Class: Homebrew::Vulns::Vulnerability Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- vulns/vulnerability.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Wraps a single OSV vulnerability record. See https://ossf.github.io/osv-schema/ for the field definitions.
Defined Under Namespace
Classes: Interval, RangeStatus, Uncomparable
Instance Attribute Summary collapse
- #affected ⇒ Array<Hash{String => T.untyped}> readonly private
- #aliases ⇒ Array<String> readonly private
- #details ⇒ String? readonly private
- #id ⇒ String readonly private
- #references ⇒ Array<Hash{String => T.untyped}> readonly private
- #related ⇒ Array<String> readonly private
- #severity ⇒ Symbol? readonly private
- #severity_entries ⇒ Array<Hash{String => T.untyped}> readonly private
- #summary ⇒ String? readonly private
- #upstream ⇒ Array<String> readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #advisory_url ⇒ String? private
- #affected_entries_for(ecosystem, name) ⇒ Array<Hash{String => T.untyped}> private
- #affected_entry_relevant?(aff, repo_url) ⇒ Boolean private
-
#affects_version?(version) ⇒ Boolean
private
OSV has already matched this record against the queried version.
- #comparator_for(range_type) ⇒ T.proc.params(a: String, b: String).returns(Integer) private
- #cve_ids ⇒ Array<String> private
- #extract_severity(data) ⇒ Symbol? private
- #fix_available?(version, repo_url = nil) ⇒ Boolean private
- #fix_available_of_type?(version, repo_url, fix_type) ⇒ Boolean private
- #fix_urls ⇒ Array<String> private
- #fixed_versions ⇒ Array<String> private
-
#identifiers ⇒ Array<String>
private
Only
idandaliasesname this vulnerability. - #in_interval?(target, lower, upper, upper_inclusive, cmp) ⇒ Boolean private
- #in_interval_permissive?(target, interval) ⇒ Boolean private
- #in_interval_strict?(target, interval) ⇒ Boolean? private
- #in_semver_range?(target, events) ⇒ Boolean private
- #initialize(data) ⇒ void constructor private
- #intervals(events) ⇒ Array<Interval> private
- #non_semver_fix_available_of_type?(target, range, fix_type) ⇒ Boolean private
- #normalize_severity(value) ⇒ Symbol? private
- #normalize_version(version) ⇒ String private
- #patch_fix_available?(version, repo_url = nil) ⇒ Boolean private
-
#prerelease_boundary?(ecosystem, name, version) ⇒ Boolean
private
Some packages use prerelease syntax for rebuilds.
-
#range_status(ecosystem, name, version) ⇒ RangeStatus?
private
Evaluates
versionagainst everyaffected[]entry whosepackagematches{ecosystem, name}(an advisory can carry several disjoint entries for the same package, e.g. GHSA-jfh8-c2jp-5v3q's three log4j-core ranges), honouring rangetype:. - #range_status_for_entries(entries, version) ⇒ RangeStatus? private
- #released_fix_available?(version, repo_url = nil) ⇒ Boolean private
- #same_boundary?(left, right, cmp) ⇒ Boolean private
- #semver_compare!(left, right) ⇒ Integer private
- #severity_display ⇒ String private
- #severity_level ⇒ Integer private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(data) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'vulns/vulnerability.rb', line 54 def initialize(data) @id = T.let(data.fetch("id"), String) @summary = T.let(data["summary"], T.nilable(String)) @details = T.let(data["details"], T.nilable(String)) @aliases = T.let(Array(data["aliases"]), T::Array[String]) @upstream = T.let(Array(data["upstream"]), T::Array[String]) @related = T.let(Array(data["related"]), T::Array[String]) @references = T.let(Array(data["references"]), T::Array[T::Hash[String, T.untyped]]) @affected = T.let(Array(data["affected"]), T::Array[T::Hash[String, T.untyped]]) @severity_entries = T.let(Array(data["severity"]), T::Array[T::Hash[String, T.untyped]]) @severity = T.let(extract_severity(data), T.nilable(Symbol)) end |
Instance Attribute Details
#affected ⇒ Array<Hash{String => T.untyped}> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
51 52 53 |
# File 'vulns/vulnerability.rb', line 51 def affected @affected end |
#aliases ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
48 49 50 |
# File 'vulns/vulnerability.rb', line 48 def aliases @aliases end |
#details ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
42 43 44 |
# File 'vulns/vulnerability.rb', line 42 def details @details end |
#id ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
39 40 41 |
# File 'vulns/vulnerability.rb', line 39 def id @id end |
#references ⇒ Array<Hash{String => T.untyped}> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
51 52 53 |
# File 'vulns/vulnerability.rb', line 51 def references @references end |
#related ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
48 49 50 |
# File 'vulns/vulnerability.rb', line 48 def @related end |
#severity ⇒ Symbol? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
45 46 47 |
# File 'vulns/vulnerability.rb', line 45 def severity @severity end |
#severity_entries ⇒ Array<Hash{String => T.untyped}> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
51 52 53 |
# File 'vulns/vulnerability.rb', line 51 def severity_entries @severity_entries end |
#summary ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
42 43 44 |
# File 'vulns/vulnerability.rb', line 42 def summary @summary end |
#upstream ⇒ Array<String> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
48 49 50 |
# File 'vulns/vulnerability.rb', line 48 def upstream @upstream end |
Class Method Details
.from_osv_list(list) ⇒ Array<Vulnerability>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
68 69 70 |
# File 'vulns/vulnerability.rb', line 68 def self.from_osv_list(list) list.map { |data| new(data) } end |
Instance Method Details
#advisory_url ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
101 102 103 |
# File 'vulns/vulnerability.rb', line 101 def advisory_url references.find { |r| r["type"] == "ADVISORY" }&.dig("url") end |
#affected_entries_for(ecosystem, name) ⇒ Array<Hash{String => T.untyped}>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
241 242 243 244 245 246 |
# File 'vulns/vulnerability.rb', line 241 def affected_entries_for(ecosystem, name) affected.select do |aff| pkg = aff["package"] pkg.is_a?(Hash) && pkg["ecosystem"] == ecosystem && pkg["name"] == name end end |
#affected_entry_relevant?(aff, repo_url) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'vulns/vulnerability.rb', line 451 def affected_entry_relevant?(aff, repo_url) return true if repo_url.nil? git_ranges = Array(aff["ranges"]).select { |r| r["type"] == "GIT" } if git_ranges.any? normalized_repo = repo_url.downcase.chomp("/").delete_suffix(".git").chomp("/") return git_ranges.any? do |r| range_repo = r["repo"].to_s.downcase.chomp("/").delete_suffix(".git").chomp("/") range_repo.empty? || range_repo == normalized_repo end end # For entries without GIT ranges (e.g. SEMVER ranges or version lists), # check that the package ecosystem is GIT or unspecified. ecosystem = aff.dig("package", "ecosystem") ecosystem.blank? || ecosystem == "GIT" end |
#affects_version?(version) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
OSV has already matched this record against the queried version. This
method only overrides that with false when every affected entry can
be evaluated locally (explicit versions list or SEMVER range) and
none of them contains the target. Any uncheckable range or comparison
failure keeps the match.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'vulns/vulnerability.rb', line 280 def affects_version?(version) return true if affected.empty? target = normalize_version(version) checkable = T.let(false, T::Boolean) affected.each do |aff| versions = Array(aff["versions"]) if versions.any? checkable = true return true if versions.any? { |v| normalize_version(v.to_s) == target } end Array(aff["ranges"]).each do |range| return true if range["type"] != "SEMVER" checkable = true return true if in_semver_range?(target, Array(range["events"])) end end !checkable end |
#comparator_for(range_type) ⇒ T.proc.params(a: String, b: String).returns(Integer)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
249 250 251 252 253 254 255 |
# File 'vulns/vulnerability.rb', line 249 def comparator_for(range_type) if range_type == "SEMVER" ->(a, b) { Semver.compare(a, b) || raise(Uncomparable) } else ->(a, b) { Version.new(a) <=> Version.new(b) || raise(Uncomparable) } end end |
#cve_ids ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
96 97 98 |
# File 'vulns/vulnerability.rb', line 96 def cve_ids identifiers.select { |i| i.start_with?("CVE-") } end |
#extract_severity(data) ⇒ Symbol?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'vulns/vulnerability.rb', line 305 def extract_severity(data) Array(data["severity"]) .select { |s| CVSS_TYPE_PRIORITY.key?(s["type"]) } .sort_by { |s| -CVSS_TYPE_PRIORITY.fetch(s["type"]) } .each do |s| sev = CVSS.severity(s["score"].to_s) return sev if sev end top = normalize_severity(data.dig("database_specific", "severity")) return top if top affected.each do |aff| eco = normalize_severity(aff.dig("ecosystem_specific", "severity")) return eco if eco db = normalize_severity(aff.dig("database_specific", "severity")) return db if db end nil end |
#fix_available?(version, repo_url = nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
470 471 472 |
# File 'vulns/vulnerability.rb', line 470 def fix_available?(version, repo_url = nil) fix_available_of_type?(version, repo_url, :any) end |
#fix_available_of_type?(version, repo_url, fix_type) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'vulns/vulnerability.rb', line 485 def fix_available_of_type?(version, repo_url, fix_type) return false if affected.empty? target = normalize_version(version) affected.each do |aff| next unless affected_entry_relevant?(aff, repo_url) version_matched = false ranges = Array(aff["ranges"]) semver_ranges, non_semver_ranges = ranges.partition { |r| r["type"] == "SEMVER" } versions = Array(aff["versions"]) version_matched = true if versions.any? { |v| normalize_version(v.to_s) == target } version_matched = true if non_semver_ranges.any? matched_semver_range = T.let(false, T::Boolean) fix_found = T.let(false, T::Boolean) semver_ranges.each do |range| intervals(Array(range["events"])).each do |interval| result = in_interval_strict?(target, interval) next if result.nil? next unless result matched_semver_range = true fix = interval.fix next if fix.blank? fix_found = true if fix_type != :patch end end version_matched ||= matched_semver_range next unless version_matched return true if fix_found non_semver_ranges.each do |range| return true if non_semver_fix_available_of_type?(target, range, fix_type) end end false end |
#fix_urls ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
106 107 108 |
# File 'vulns/vulnerability.rb', line 106 def fix_urls references.select { |r| r["type"] == "FIX" }.filter_map { |r| r["url"] } end |
#fixed_versions ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
111 112 113 114 115 116 117 |
# File 'vulns/vulnerability.rb', line 111 def fixed_versions affected.flat_map do |aff| Array(aff["ranges"]).flat_map do |range| Array(range["events"]).filter_map { |e| e["fixed"] } end end.uniq end |
#identifiers ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Only id and aliases name this vulnerability. upstream is a
directed reference (a distro advisory pointing at one-or-more source
CVEs) and related links to different vulnerabilities; neither is safe
to treat as an identity of this record. Match follows upstream
explicitly and re-attributes the hit to each CVE it names.
91 92 93 |
# File 'vulns/vulnerability.rb', line 91 def identifiers [id, *aliases].uniq end |
#in_interval?(target, lower, upper, upper_inclusive, cmp) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
262 263 264 265 266 267 268 269 270 271 272 |
# File 'vulns/vulnerability.rb', line 262 def in_interval?(target, lower, upper, upper_inclusive, cmp) above = lower.nil? || cmp.call(target, lower) >= 0 below = if upper.nil? true elsif upper_inclusive cmp.call(target, upper) <= 0 else cmp.call(target, upper).negative? end above && below end |
#in_interval_permissive?(target, interval) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
371 372 373 374 375 376 |
# File 'vulns/vulnerability.rb', line 371 def in_interval_permissive?(target, interval) in_interval_strict?(target, interval) != false rescue => e odebug "Failed to check #{target} against interval #{interval.inspect} for #{id}: #{e}" true end |
#in_interval_strict?(target, interval) ⇒ Boolean?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'vulns/vulnerability.rb', line 354 def in_interval_strict?(target, interval) lower = interval.lower upper = interval.upper above = lower.nil? || semver_compare!(target, lower) >= 0 below = if upper.nil? true elsif interval.upper_inclusive semver_compare!(target, upper) <= 0 else semver_compare!(target, upper).negative? end above && below rescue Uncomparable nil end |
#in_semver_range?(target, events) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
347 348 349 350 351 |
# File 'vulns/vulnerability.rb', line 347 def in_semver_range?(target, events) return false if events.empty? intervals(events).any? { |interval| in_interval_permissive?(target, interval) } end |
#intervals(events) ⇒ Array<Interval>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'vulns/vulnerability.rb', line 387 def intervals(events) result = [] lower = T.let(nil, T.nilable(String)) events.each do |event| if (intro = event["introduced"]) result << Interval.new(lower: lower, upper: nil, upper_inclusive: false, fix: nil) if lower intro = normalize_version(intro.to_s) lower = (intro == "0") ? nil : intro elsif (fixed = event["fixed"]) fixed_norm = normalize_version(fixed.to_s) result << Interval.new(lower: lower, upper: fixed_norm, upper_inclusive: false, fix: fixed_norm) lower = nil elsif (last = event["last_affected"]) last_norm = normalize_version(last.to_s) result << Interval.new(lower: lower, upper: last_norm, upper_inclusive: true, fix: nil) lower = nil elsif (limit = event["limit"]) limit = limit.to_s upper = (limit == "*") ? nil : normalize_version(limit) result << Interval.new(lower: lower, upper: upper, upper_inclusive: false, fix: nil) lower = nil end end result << Interval.new(lower: lower, upper: nil, upper_inclusive: false, fix: nil) if lower || result.empty? result end |
#non_semver_fix_available_of_type?(target, range, fix_type) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'vulns/vulnerability.rb', line 416 def non_semver_fix_available_of_type?(target, range, fix_type) events = Array(range["events"]) return false if events.empty? is_git = range["type"] == "GIT" range_intervals = intervals(events) uncomparable_seen = T.let(false, T::Boolean) range_intervals.each do |interval| result = in_interval_strict?(target, interval) if result.nil? uncomparable_seen = true next end next unless result fix = interval.fix return false if fix.blank? return (fix_type == :patch && is_git) || (fix_type == :released && !is_git) || fix_type == :any end return false unless uncomparable_seen last_event = events.last return false if last_event.nil? return false unless last_event.key?("fixed") fix = last_event["fixed"].to_s return false if fix.blank? (fix_type == :patch && is_git) || (fix_type == :released && !is_git) || fix_type == :any end |
#normalize_severity(value) ⇒ Symbol?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
329 330 331 332 333 334 335 336 |
# File 'vulns/vulnerability.rb', line 329 def normalize_severity(value) case value&.downcase when "critical" then :critical when "high" then :high when "medium", "moderate" then :medium when "low" then :low end end |
#normalize_version(version) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
339 340 341 |
# File 'vulns/vulnerability.rb', line 339 def normalize_version(version) version.sub(/\Av(?!v)/i, "") end |
#patch_fix_available?(version, repo_url = nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
480 481 482 |
# File 'vulns/vulnerability.rb', line 480 def patch_fix_available?(version, repo_url = nil) fix_available_of_type?(version, repo_url, :patch) end |
#prerelease_boundary?(ecosystem, name, version) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Some packages use prerelease syntax for rebuilds. Reconciliation must hold a boundary whose state depends on that ambiguous interpretation.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'vulns/vulnerability.rb', line 156 def prerelease_boundary?(ecosystem, name, version) release = Semver.release_version(version) return false unless release entries = affected_entries_for(ecosystem, name).map do |entry| entry.merge("ranges" => Array(entry["ranges"]).select { |range| range["type"] == "SEMVER" }) end return false if entries.none? { |entry| entry.fetch("ranges").any? } range_status_for_entries(entries, version)&.state != range_status_for_entries(entries, release)&.state end |
#range_status(ecosystem, name, version) ⇒ RangeStatus?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Evaluates version against every affected[] entry whose package
matches {ecosystem, name} (an advisory can carry several disjoint
entries for the same package, e.g. GHSA-jfh8-c2jp-5v3q's three
log4j-core ranges), honouring range type:
SEMVERranges compare with Semver.ECOSYSTEMranges compare with Version (best-effort; the record's own ecosystem defines the ordering, but callers only invoke this for ecosystems whose versions are broadlyVersion-comparable).GITranges are commit hashes and are skipped as uncomparable.
Returns nil when no entry matches the package or no comparable range
exists in the matching entries, so callers can distinguish
:not_applicable/:fixed from "could not check".
149 150 151 |
# File 'vulns/vulnerability.rb', line 149 def range_status(ecosystem, name, version) range_status_for_entries(affected_entries_for(ecosystem, name), version) end |
#range_status_for_entries(entries, version) ⇒ RangeStatus?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'vulns/vulnerability.rb', line 171 def range_status_for_entries(entries, version) return if entries.empty? target = normalize_version(version) checked = T.let(false, T::Boolean) past_terminals = T.let([], T::Array[[String, T.nilable(String), Comparator]]) entries.each do |entry| Array(entry["ranges"]).each do |range| type = range["type"] next if type == "GIT" cmp = comparator_for(type) intervals(Array(range["events"])).each do |interval| inside = in_interval?(target, interval.lower, interval.upper, interval.upper_inclusive, cmp) checked = true if inside return RangeStatus.new(state: :affected, fixed_in: interval.fix).freeze end upper = interval.upper next unless upper rel = cmp.call(target, upper) past = interval.upper_inclusive ? rel.positive? : rel >= 0 past_terminals << [upper, interval.fix, cmp] if past rescue Uncomparable next end end versions = Array(entry["versions"]) next if versions.empty? checked = true if versions.any? { |v| normalize_version(v.to_s) == target } return RangeStatus.new(state: :affected, fixed_in: nil).freeze end end return unless checked # Conflicting entries can end at the same version with `fixed` and # `last_affected`/`limit`. Prefer the non-fix terminal on a tie so # upstream entry ordering cannot turn an inclusive affected boundary # into a reported fix version. `Version` ranks terminals across ranges # of differing types, but each range's own comparator also settles # ties: SemVer ignores build metadata, so `1.0.0+1` and `1.0.0+2` are # one boundary there and `Version` alone would miss the tie. latest_terminal = past_terminals.max_by do |upper, fix, _| [Version.new(upper), fix.nil? ? 1 : 0] end return RangeStatus.new(state: :not_applicable, fixed_in: nil).freeze unless latest_terminal boundary, fixed_in, cmp = latest_terminal shadowed = past_terminals.any? do |other, other_fix, other_cmp| other_fix.nil? && (same_boundary?(boundary, other, cmp) || same_boundary?(boundary, other, other_cmp)) end RangeStatus.new(state: :fixed, fixed_in: (fixed_in unless shadowed)).freeze end |
#released_fix_available?(version, repo_url = nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
475 476 477 |
# File 'vulns/vulnerability.rb', line 475 def released_fix_available?(version, repo_url = nil) fix_available_of_type?(version, repo_url, :released) end |
#same_boundary?(left, right, cmp) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
234 235 236 237 238 |
# File 'vulns/vulnerability.rb', line 234 def same_boundary?(left, right, cmp) cmp.call(left, right).zero? rescue Uncomparable false end |
#semver_compare!(left, right) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
379 380 381 |
# File 'vulns/vulnerability.rb', line 379 def semver_compare!(left, right) Semver.compare(left, right) || raise(Uncomparable, "cannot compare #{left.inspect} with #{right.inspect}") end |
#severity_display ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
73 74 75 |
# File 'vulns/vulnerability.rb', line 73 def severity_display severity&.to_s&.upcase || "UNKNOWN" end |
#severity_level ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
78 79 80 81 82 83 |
# File 'vulns/vulnerability.rb', line 78 def severity_level sev = severity return 0 if sev.nil? SEVERITY_LEVEL.fetch(sev, 0) end |