This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvulnerability_package.rb
More file actions
59 lines (48 loc) · 1.94 KB
/
vulnerability_package.rb
File metadata and controls
59 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require "vers"
module Git
module Pkgs
module Models
class VulnerabilityPackage < Sequel::Model
many_to_one :vulnerability, key: :vulnerability_id
dataset_module do
def for_package(ecosystem, name)
where(ecosystem: ecosystem, package_name: name)
end
end
def affects_version?(version)
return false if affected_versions.nil? || affected_versions.empty?
return false if version.nil? || version.empty?
# Convert OSV ecosystem to purl type for Vers
bib_ecosystem = Ecosystems.from_osv(ecosystem) || ecosystem.downcase
purl_type = Ecosystems.to_purl(bib_ecosystem) || bib_ecosystem
# Handle || separator (OR conditions between different ranges)
# Each part separated by || is an independent range (OR)
# Within each part, space-separated constraints are AND conditions
affected_versions.split(" || ").any? do |range_part|
range_matches?(version, range_part, purl_type)
end
rescue ArgumentError, Vers::Error
# If we can't parse the version or range, be conservative and assume affected
true
end
def range_matches?(version, range_part, purl_type)
# Extract individual constraints (e.g., ">=7.1.0 <7.1.3.1" -> [">=7.1.0", "<7.1.3.1"])
constraints = range_part.scan(/[<>=!~^]+[^\s]+/)
return false if constraints.empty?
# All constraints must be satisfied (AND logic)
constraints.all? do |constraint|
Vers.satisfies?(version, constraint, purl_type)
end
end
def fixed_versions_list
return [] if fixed_versions.nil? || fixed_versions.empty?
fixed_versions.split(",").map(&:strip)
end
def purl
Models::Package.generate_purl(ecosystem, package_name)
end
end
end
end
end