Class: Homebrew::Vulns::Vulnerability Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



58
59
60
61
62
63
64
65
66
67
68
69
# File 'vulns/vulnerability.rb', line 58

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.

Returns:



55
56
57
# File 'vulns/vulnerability.rb', line 55

def affected
  @affected
end

#aliases ⇒ 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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



55
56
57
# File 'vulns/vulnerability.rb', line 55

def references
  @references
end

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.

Returns:



52
53
54
# File 'vulns/vulnerability.rb', line 52

def related
  @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.

Returns:



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.

Returns:



55
56
57
# File 'vulns/vulnerability.rb', line 55

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.

Returns:



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.

Returns:



52
53
54
# File 'vulns/vulnerability.rb', line 52

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.

Parameters:

Returns:



72
73
74
# File 'vulns/vulnerability.rb', line 72

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.

Returns:



114
115
116
# File 'vulns/vulnerability.rb', line 114

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.

Parameters:

Returns:



254
255
256
257
258
259
# File 'vulns/vulnerability.rb', line 254

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.

Parameters:

Returns:

  • (Boolean)


464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'vulns/vulnerability.rb', line 464

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.

Parameters:

Returns:

  • (Boolean)


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'vulns/vulnerability.rb', line 293

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.

Parameters:

Returns:



262
263
264
265
266
267
268
# File 'vulns/vulnerability.rb', line 262

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.

Returns:



109
110
111
# File 'vulns/vulnerability.rb', line 109

def cve_ids
  identifiers.select { |i| i.start_with?("CVE-") }
end

#excluding_aliases(excluded) ⇒ 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.

Keep cached upstream records intact when applying a formula's reviewed alias correction. Exclusions cannot remove the record's own identity.

Parameters:

Returns:



102
103
104
105
106
# File 'vulns/vulnerability.rb', line 102

def excluding_aliases(excluded)
  corrected = dup
  corrected.aliases = aliases - excluded
  corrected
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.

Parameters:

Returns:



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'vulns/vulnerability.rb', line 318

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.

Parameters:

  • version (String)
  • repo_url (String, nil) (defaults to: nil)

Returns:

  • (Boolean)


483
484
485
# File 'vulns/vulnerability.rb', line 483

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.

Parameters:

Returns:

  • (Boolean)


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
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'vulns/vulnerability.rb', line 498

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.

Returns:



119
120
121
# File 'vulns/vulnerability.rb', line 119

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.

Returns:



124
125
126
127
128
129
130
# File 'vulns/vulnerability.rb', line 124

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.

Returns:



95
96
97
# File 'vulns/vulnerability.rb', line 95

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.

Parameters:

Returns:

  • (Boolean)


275
276
277
278
279
280
281
282
283
284
285
# File 'vulns/vulnerability.rb', line 275

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.

Parameters:

Returns:

  • (Boolean)


384
385
386
387
388
389
# File 'vulns/vulnerability.rb', line 384

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.

Parameters:

Returns:

  • (Boolean, nil)


367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'vulns/vulnerability.rb', line 367

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.

Parameters:

Returns:

  • (Boolean)


360
361
362
363
364
# File 'vulns/vulnerability.rb', line 360

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.

Parameters:

Returns:



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'vulns/vulnerability.rb', line 400

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 = normalize_version(limit) if 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.

Parameters:

Returns:

  • (Boolean)


429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'vulns/vulnerability.rb', line 429

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.

Parameters:

Returns:



342
343
344
345
346
347
348
349
# File 'vulns/vulnerability.rb', line 342

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.

Parameters:

Returns:



352
353
354
# File 'vulns/vulnerability.rb', line 352

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.

Parameters:

  • version (String)
  • repo_url (String, nil) (defaults to: nil)

Returns:

  • (Boolean)


493
494
495
# File 'vulns/vulnerability.rb', line 493

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.

Parameters:

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
177
178
179
# File 'vulns/vulnerability.rb', line 169

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:

  • SEMVER ranges compare with Semver.
  • ECOSYSTEM ranges compare with Version (best-effort; the record's own ecosystem defines the ordering, but callers only invoke this for ecosystems whose versions are broadly Version-comparable).
  • GIT ranges 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".

Parameters:

Returns:



162
163
164
# File 'vulns/vulnerability.rb', line 162

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.

Parameters:

Returns:



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
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'vulns/vulnerability.rb', line 184

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.

Parameters:

  • version (String)
  • repo_url (String, nil) (defaults to: nil)

Returns:

  • (Boolean)


488
489
490
# File 'vulns/vulnerability.rb', line 488

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.

Parameters:

Returns:

  • (Boolean)


247
248
249
250
251
# File 'vulns/vulnerability.rb', line 247

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.

Parameters:

Returns:



392
393
394
# File 'vulns/vulnerability.rb', line 392

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.

Returns:



77
78
79
# File 'vulns/vulnerability.rb', line 77

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.

Returns:



82
83
84
85
86
87
# File 'vulns/vulnerability.rb', line 82

def severity_level
  sev = severity
  return 0 if sev.nil?

  SEVERITY_LEVEL.fetch(sev, 0)
end