@@ -341,10 +341,12 @@ class DrupalAdvisoryPatch(typing.TypedDict):
341341 patches : dict [str , DrupalAdvisoryPatch ] = tomllib .load (fi )
342342
343343
344- def patch_advisory (sa_id : str , sa_advisory : drupal .Advisory ) -> bool :
344+ def patch_advisory (osv_id : str , sa_advisory : drupal .Advisory ) -> bool :
345345 """
346346 Attempts to apply any patches to the advisory that are defined in patches.toml
347347 """
348+ sa_id = f'SA-{ osv_id .removeprefix ("DRUPAL-" )} '
349+
348350 if sa_id in patches :
349351 before , after = patches [sa_id ]['field_affected_versions' ]
350352
@@ -363,14 +365,14 @@ def unix_timestamp_to_rfc3339(unix: int) -> str:
363365
364366
365367def build_osv_advisory (
366- sa_id : str ,
368+ osv_id : str ,
367369 sa_advisory : drupal .Advisory ,
368370) -> osv .Vulnerability | None :
369371 """
370372 Builds a representation of the given Drupal SA advisory in OSV format
371373 """
372374
373- patched = patch_advisory (sa_id , sa_advisory )
375+ patched = patch_advisory (osv_id , sa_advisory )
374376
375377 # we expect that the downloader has excluded PSA type entries, but
376378 # we still guard against them here just in case one slips through
@@ -387,7 +389,7 @@ def build_osv_advisory(
387389
388390 osv_advisory : osv .Vulnerability = {
389391 'schema_version' : '1.7.0' ,
390- 'id' : f'D { sa_id } ' ,
392+ 'id' : osv_id ,
391393 'modified' : unix_timestamp_to_rfc3339 (int (sa_advisory ['changed' ])),
392394 'published' : unix_timestamp_to_rfc3339 (int (sa_advisory ['created' ])),
393395 'aliases' : sa_advisory ['field_sa_cve' ],
@@ -396,7 +398,7 @@ def build_osv_advisory(
396398 {
397399 # todo: figure out if we need a dedicated ecosystem i.e. Drupal, Drupal8, etc
398400 'package' : {
399- 'ecosystem' : 'Packagist ' ,
401+ 'ecosystem' : 'Drupal ' ,
400402 'name' : determine_composer_package_name (sa_advisory ),
401403 },
402404 # todo: figure out how to map field_sa_criticality to severity
@@ -426,10 +428,10 @@ def fetch_affected_packages(osv_advisory: osv.Vulnerability) -> list[str]:
426428
427429
428430def is_existing_advisory_ahead (
429- name : str , sa_id : str , proposed_modified_at : str
431+ name : str , osv_id : str , proposed_modified_at : str
430432) -> bool :
431433 try :
432- with open (f'advisories/{ name } /D { sa_id } .json' ) as f :
434+ with open (f'advisories/{ name } /{ osv_id } .json' ) as f :
433435 existing_advisory = typing .cast (osv .Vulnerability , json .load (f ))
434436 # RFC3339 dates are designed to be comparable as strings, so this is safe
435437 return existing_advisory ['modified' ] > proposed_modified_at
@@ -445,8 +447,8 @@ def generate_osv_advisories() -> None:
445447 with open (file .path ) as f :
446448 sa_advisory : drupal .Advisory = json .load (f )
447449 print (f'processing { sa_advisory ["url" ]} ' )
448- sa_id = file .name .removesuffix ('.json' )
449- osv_advisory = build_osv_advisory (sa_id , sa_advisory )
450+ osv_id = f'DRUPAL- { file .name .removeprefix ( "SA-" ). removesuffix ('.json' )} '
451+ osv_advisory = build_osv_advisory (osv_id , sa_advisory )
450452
451453 if osv_advisory is None :
452454 continue
@@ -459,13 +461,13 @@ def generate_osv_advisories() -> None:
459461 for affected_package in affected_packages :
460462 name = affected_package .removeprefix ('drupal/' )
461463 os .makedirs (f'advisories/{ name } ' , exist_ok = True )
462- if is_existing_advisory_ahead (name , sa_id , osv_advisory ['modified' ]):
464+ if is_existing_advisory_ahead (name , osv_id , osv_advisory ['modified' ]):
463465 print (
464466 ' \\ - error: current modified date is ahead of the proposed modified date (is your cache up to date?)'
465467 )
466468 exit (1 )
467469
468- with open (f'advisories/{ name } /D { sa_id } .json' , 'w' ) as f :
470+ with open (f'advisories/{ name } /{ osv_id } .json' , 'w' ) as f :
469471 json .dump (osv_advisory , f , indent = 2 )
470472 f .write ('\n ' )
471473
0 commit comments