@@ -282,15 +282,16 @@ def get_artifact_hash(self, purl: PackageURL, hash_algorithm: Any) -> str | None
282
282
if not file_name :
283
283
return None
284
284
285
- # Maven supports but does not require a sha256 hash of uploaded artifacts. Check that first.
285
+ # Maven supports but does not require a sha256 hash of uploaded artifacts.
286
286
artifact_url = self .registry_url + "/" + artifact_path + "/" + file_name
287
287
sha256_url = artifact_url + ".sha256"
288
288
logger .debug ("Search for artifact hash using URL: %s" , [sha256_url , artifact_url ])
289
289
290
290
response = send_get_http_raw (sha256_url , {})
291
- if response and response .text :
292
- logger .debug ("Found hash of artifact: %s" , response .text )
293
- return response .text
291
+ sha256_hash = None
292
+ if response and (sha256_hash := response .text ):
293
+ # As Maven hashes are user provided and not verified they serve as a reference only.
294
+ logger .debug ("Found hash of artifact: %s" , sha256_hash )
294
295
295
296
try :
296
297
response = requests .get (artifact_url , stream = True , timeout = 40 )
@@ -313,5 +314,9 @@ def get_artifact_hash(self, purl: PackageURL, hash_algorithm: Any) -> str | None
313
314
return None
314
315
315
316
artifact_hash : str = hash_algorithm .hexdigest ()
317
+ if sha256_hash and artifact_hash != sha256_hash :
318
+ logger .debug ("Artifact hash and discovered hash do not match: %s != %s" , artifact_hash , sha256_hash )
319
+ return None
320
+
316
321
logger .debug ("Computed hash of artifact: %s" , artifact_hash )
317
322
return artifact_hash
0 commit comments