@@ -23,8 +23,12 @@ def self.sync(min_year: 2018)
2323 # decide how older they want. The script is really designed to keep data synced
2424 # over going forward
2525 gh_advisories . select! do |advisory |
26- _ , cve_year = advisory . cve_id . match ( /^CVE-(\d +)-\d +$/ ) . to_a
27- cve_year . to_i >= min_year
26+ if advisory . cve_id
27+ _ , cve_year = advisory . cve_id . match ( /^CVE-(\d +)-\d +$/ ) . to_a
28+ cve_year . to_i >= min_year
29+ else
30+ true # all advisories without a CVE are included too
31+ end
2832 end
2933
3034 files_written = [ ]
@@ -174,15 +178,31 @@ def initialize(github_advisory_graphql_object:)
174178 @github_advisory_graphql_object = github_advisory_graphql_object
175179 end
176180
181+ def identifier_list
182+ github_advisory_graphql_object [ "identifiers" ]
183+ end
184+
177185 # extract the CVE identifier from the GitHub Advisory identifier list
178186 def cve_id
179- identifier_list = github_advisory_graphql_object [ "identifiers" ]
180187 cve_id_obj = identifier_list . find { |id | id [ "type" ] == "CVE" }
181188 return nil unless cve_id_obj
182189
183190 cve_id_obj [ "value" ]
184191 end
185192
193+ def ghsa_id
194+ id_obj = identifier_list . find { |id | id [ "type" ] == "GHSA" }
195+ id_obj [ "value" ]
196+ end
197+
198+ # advisories should be identified by CVE ID if there is one
199+ # but for maintainer submitted advisories there may not be one,
200+ # so a GitHub Security Advisory ID (ghsa_id) is used instead
201+ def primary_id
202+ return cve_id if cve_id
203+ ghsa_id
204+ end
205+
186206 # return a date as a string like 2019-03-21.
187207 def published_day
188208 return nil unless github_advisory_graphql_object [ "publishedAt" ]
@@ -225,17 +245,15 @@ def some_rubysec_files_do_not_exist?
225245 end
226246
227247 def write_files
228- return [ ] unless cve_id
229248 return [ ] unless some_rubysec_files_do_not_exist?
230249
231250 files_written = [ ]
232251 vulnerabilities . each do |vulnerability |
233- filename_to_write = File . join ( "gems" , vulnerability [ "package" ] [ "name" ] , "#{ cve_id } .yml" )
252+ filename_to_write = File . join ( "gems" , vulnerability [ "package" ] [ "name" ] , "#{ primary_id } .yml" )
234253 next if File . exist? ( filename_to_write )
235254
236255 data = {
237256 "gem" => vulnerability [ "package" ] [ "name" ] ,
238- "cve" => cve_id [ 4 ..20 ] ,
239257 "date" => published_day ,
240258 "url" => external_reference ,
241259 "title" => github_advisory_graphql_object [ "summary" ] ,
@@ -244,6 +262,7 @@ def write_files
244262 "patched_versions" => [ "<FILL IN SEE BELOW>" ] ,
245263 "unaffected_versions" => [ "<OPTIONAL: FILL IN SEE BELOW>" ]
246264 }
265+ data [ "cve" ] = cve_id [ 4 ..20 ] if cve_id
247266
248267 dir_to_write = File . dirname ( filename_to_write )
249268 Dir . mkdir dir_to_write unless Dir . exist? ( dir_to_write )
0 commit comments