Class: Brew::Vulns::Vulnerability

Inherits:
Object
  • Object
show all
Defined in:
lib/brew/vulns/vulnerability.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Vulnerability

Returns a new instance of Vulnerability.



8
9
10
11
12
13
14
15
16
# File 'lib/brew/vulns/vulnerability.rb', line 8

def initialize(data)
  @id = data["id"]
  @summary = data["summary"]
  @details = data["details"]
  @aliases = data["aliases"] || []
  @references = data["references"] || []
  @affected = data["affected"] || []
  @severity = extract_severity(data)
end

Instance Attribute Details

#affectedObject (readonly)

Returns the value of attribute affected.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def affected
  @affected
end

#aliasesObject (readonly)

Returns the value of attribute aliases.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def aliases
  @aliases
end

#detailsObject (readonly)

Returns the value of attribute details.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def details
  @details
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def id
  @id
end

#referencesObject (readonly)

Returns the value of attribute references.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def references
  @references
end

#severityObject (readonly)

Returns the value of attribute severity.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def severity
  @severity
end

#summaryObject (readonly)

Returns the value of attribute summary.



6
7
8
# File 'lib/brew/vulns/vulnerability.rb', line 6

def summary
  @summary
end

Class Method Details

.from_osv_list(vulns_data) ⇒ Object



57
58
59
# File 'lib/brew/vulns/vulnerability.rb', line 57

def self.from_osv_list(vulns_data)
  vulns_data.map { |data| new(data) }
end

Instance Method Details

#advisory_urlObject



36
37
38
39
# File 'lib/brew/vulns/vulnerability.rb', line 36

def advisory_url
  ref = references.find { |r| r["type"] == "ADVISORY" }
  ref&.dig("url")
end

#cve_idsObject



32
33
34
# File 'lib/brew/vulns/vulnerability.rb', line 32

def cve_ids
  ([id] + aliases).select { |a| a.start_with?("CVE-") }
end

#fix_urlsObject



41
42
43
# File 'lib/brew/vulns/vulnerability.rb', line 41

def fix_urls
  references.select { |r| r["type"] == "FIX" }.map { |r| r["url"] }
end

#fixed_versionsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/brew/vulns/vulnerability.rb', line 45

def fixed_versions
  versions = []
  affected.each do |aff|
    (aff["ranges"] || []).each do |range|
      (range["events"] || []).each do |event|
        versions << event["fixed"] if event["fixed"]
      end
    end
  end
  versions.uniq
end

#severity_displayObject



18
19
20
# File 'lib/brew/vulns/vulnerability.rb', line 18

def severity_display
  severity&.upcase || "UNKNOWN"
end

#severity_levelObject



22
23
24
25
26
27
28
29
30
# File 'lib/brew/vulns/vulnerability.rb', line 22

def severity_level
  case severity&.downcase
  when "critical" then 4
  when "high" then 3
  when "medium" then 2
  when "low" then 1
  else 0
  end
end