Skip to content

Attempt to automatically generate unaffected_versions: #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 9, 2023
Merged
33 changes: 31 additions & 2 deletions lib/github_advisory_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ def update(package)
package.filename
end

def vulnerable_version_ranges_for(package)
vulnerabilities.select { |v|
v['package']['name'] == package.name
}.map { |v|
v['vulnerableVersionRange'].split(', ',2).map do |version_range|
version_range.split(' ',2)
end
}.sort_by { |((lower_op,lower_version),(upper_op,upper_version))|
lower_version
}
end

def unaffected_versions_for(package)
if (version_range = vulnerable_version_ranges_for(package).first)
lower_version_range = version_range[0]
operator, version = lower_version_range

case operator
when '>'
["<= #{version}"]
when '>=', '='
["< #{version}"]
end
end
end

def first_patched_versions_for(package)
first_patched_versions = []

Expand Down Expand Up @@ -371,10 +397,13 @@ def create(package)

new_data = package.merge_data(
"cvss_v3" => ("<FILL IN IF AVAILABLE>" unless cvss),
"cvss_v4" => "<FILL IN IF AVAILABLE>",
"unaffected_versions" => ["<OPTIONAL: FILL IN SEE BELOW>"]
"cvss_v4" => "<FILL IN IF AVAILABLE>"
)

if (unaffected_versions = unaffected_versions_for(package))
new_data['unaffected_versions'] = unaffected_versions
end

patched_versions = patched_versions_for(package)

if !patched_versions.empty?
Expand Down