still_active 1.6.0 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +88 -0
- data/README.md +131 -17
- data/lib/helpers/activity_helper.rb +41 -8
- data/lib/helpers/bundler_helper.rb +87 -26
- data/lib/helpers/catalog_index.rb +4 -1
- data/lib/helpers/constraint_helper.rb +208 -0
- data/lib/helpers/cvss_helper.rb +63 -0
- data/lib/helpers/cyclonedx_helper.rb +44 -12
- data/lib/helpers/diff_markdown_helper.rb +36 -17
- data/lib/helpers/endoflife_helper.rb +114 -0
- data/lib/helpers/http_helper.rb +117 -15
- data/lib/helpers/lockfile_dependency_parser.rb +99 -0
- data/lib/helpers/lockfile_indexer.rb +3 -0
- data/lib/helpers/markdown_escape.rb +58 -0
- data/lib/helpers/markdown_helper.rb +145 -6
- data/lib/helpers/pep440_helper.rb +100 -0
- data/lib/helpers/python_helper.rb +19 -0
- data/lib/helpers/ruby_advisory_db.rb +23 -0
- data/lib/helpers/ruby_helper.rb +18 -28
- data/lib/helpers/runtime_ceiling_helper.rb +121 -0
- data/lib/helpers/sarif_helper.rb +157 -28
- data/lib/helpers/semver_satisfaction.rb +68 -0
- data/lib/helpers/status_helper.rb +68 -0
- data/lib/helpers/summary_helper.rb +52 -0
- data/lib/helpers/terminal_helper.rb +167 -19
- data/lib/helpers/version_helper.rb +16 -1
- data/lib/helpers/vulnerability_helper.rb +73 -7
- data/lib/still_active/artifactory_client.rb +166 -0
- data/lib/still_active/ceiling_reconciler.rb +43 -0
- data/lib/still_active/cli.rb +292 -20
- data/lib/still_active/config.rb +59 -2
- data/lib/still_active/config_file.rb +207 -0
- data/lib/still_active/deps_dev_client.rb +140 -9
- data/lib/still_active/diff.rb +81 -2
- data/lib/still_active/ecosystem_lens.rb +284 -0
- data/lib/still_active/ecosystems_client.rb +123 -0
- data/lib/still_active/forgejo_client.rb +50 -0
- data/lib/still_active/github_client.rb +126 -0
- data/lib/still_active/gitlab_client.rb +15 -20
- data/lib/still_active/options.rb +58 -6
- data/lib/still_active/osv_client.rb +147 -0
- data/lib/still_active/poison_security_correlator.rb +232 -0
- data/lib/still_active/pypi_client.rb +56 -0
- data/lib/still_active/repository.rb +12 -4
- data/lib/still_active/sarif/rules.rb +35 -11
- data/lib/still_active/sbom_reader.rb +191 -0
- data/lib/still_active/sbom_workflow.rb +96 -0
- data/lib/still_active/suppressions.rb +143 -0
- data/lib/still_active/version.rb +1 -1
- data/lib/still_active/workflow.rb +312 -61
- data/lib/still_active.rb +3 -0
- data/still_active.gemspec +34 -9
- metadata +72 -11
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "activity_helper"
|
|
4
|
+
require_relative "status_helper"
|
|
5
|
+
|
|
6
|
+
module StillActive
|
|
7
|
+
# Builds the JSON output's summary{} digest: the headline posture of the audit
|
|
8
|
+
# in one object, so a machine/LLM consumer reads the totals directly instead
|
|
9
|
+
# of iterating every gem. Counts are derived from the canonical per-gem fields
|
|
10
|
+
# (activity_level, archived, up_to_date, vulnerability_count) so they never
|
|
11
|
+
# drift from a separately-thresholded SARIF rule.
|
|
12
|
+
module SummaryHelper
|
|
13
|
+
ACTIVITY_LEVELS = [:ok, :stale, :critical, :archived, :unknown].freeze
|
|
14
|
+
|
|
15
|
+
extend self
|
|
16
|
+
|
|
17
|
+
def summarize(result, ruby_info: nil)
|
|
18
|
+
activity = ACTIVITY_LEVELS.to_h { |level| [level, 0] }
|
|
19
|
+
archived = up_to_date = outdated = vulnerable_gems = vulnerabilities = direct = 0
|
|
20
|
+
|
|
21
|
+
result.each_value do |data|
|
|
22
|
+
activity[ActivityHelper.activity_level(data)] += 1
|
|
23
|
+
direct += 1 if data[:direct]
|
|
24
|
+
archived += 1 if data[:archived]
|
|
25
|
+
up_to_date += 1 if data[:up_to_date] == true
|
|
26
|
+
outdated += 1 if data[:up_to_date] == false
|
|
27
|
+
count = data[:vulnerability_count].to_i
|
|
28
|
+
next unless count.positive?
|
|
29
|
+
|
|
30
|
+
vulnerable_gems += 1
|
|
31
|
+
vulnerabilities += count
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
summary = {
|
|
35
|
+
total_gems: result.size,
|
|
36
|
+
direct: direct,
|
|
37
|
+
transitive: result.size - direct,
|
|
38
|
+
activity: activity,
|
|
39
|
+
archived: archived,
|
|
40
|
+
up_to_date: up_to_date,
|
|
41
|
+
outdated: outdated,
|
|
42
|
+
vulnerable_gems: vulnerable_gems,
|
|
43
|
+
vulnerabilities: vulnerabilities,
|
|
44
|
+
# The single worst per-gem verdict (plus EOL Ruby), so a consumer reads
|
|
45
|
+
# one project-level posture without scanning every gem's status.
|
|
46
|
+
status: StatusHelper.project_status(result, ruby_info: ruby_info),
|
|
47
|
+
}
|
|
48
|
+
summary[:ruby_eol] = ruby_info[:eol] == true if ruby_info
|
|
49
|
+
summary
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "activity_helper"
|
|
4
4
|
require_relative "ansi_helper"
|
|
5
|
+
require_relative "constraint_helper"
|
|
6
|
+
require_relative "summary_helper"
|
|
5
7
|
require_relative "libyear_helper"
|
|
6
8
|
require_relative "version_helper"
|
|
7
9
|
require_relative "vulnerability_helper"
|
|
@@ -22,8 +24,7 @@ module StillActive
|
|
|
22
24
|
lines << separator_line(widths)
|
|
23
25
|
names.each_with_index do |name, i|
|
|
24
26
|
lines << row_line(rows[i], widths)
|
|
25
|
-
|
|
26
|
-
lines << extra if extra
|
|
27
|
+
lines.concat(sub_lines(result[name]))
|
|
27
28
|
end
|
|
28
29
|
lines << ""
|
|
29
30
|
lines << summary_line(result)
|
|
@@ -101,7 +102,8 @@ module StillActive
|
|
|
101
102
|
return AnsiHelper.green("0") if count.zero?
|
|
102
103
|
|
|
103
104
|
severity = VulnerabilityHelper.highest_severity(data[:vulnerabilities])
|
|
104
|
-
|
|
105
|
+
notes = [severity, ("no fix" if VulnerabilityHelper.no_fix_available?(data[:vulnerabilities]))].compact
|
|
106
|
+
label = notes.empty? ? count.to_s : "#{count} (#{notes.join(", ")})"
|
|
105
107
|
AnsiHelper.red(label)
|
|
106
108
|
end
|
|
107
109
|
|
|
@@ -130,6 +132,138 @@ module StillActive
|
|
|
130
132
|
.join
|
|
131
133
|
end
|
|
132
134
|
|
|
135
|
+
# The ↳ sub-lines under a gem row. A poison gem gets the poison receipt (which
|
|
136
|
+
# names the direct parent itself when transitive, so the generic transitive
|
|
137
|
+
# line is redundant and dropped); a direct poison gem may still get its
|
|
138
|
+
# alternatives line. A non-poison gem keeps the prior behaviour: transitive
|
|
139
|
+
# gems point at the parent (#60), direct ones offer alternatives.
|
|
140
|
+
def sub_lines(data)
|
|
141
|
+
lines = if data[:poison]
|
|
142
|
+
[poison_line(data), (data[:direct] == false ? nil : alternatives_line(data))]
|
|
143
|
+
else
|
|
144
|
+
[data[:direct] == false ? dependency_path_line(data) : alternatives_line(data)]
|
|
145
|
+
end
|
|
146
|
+
# A language-runtime ceiling is orthogonal to poison/alternatives (a gem can
|
|
147
|
+
# be maintained yet still cap your Ruby), so it always gets its own line.
|
|
148
|
+
lines << language_ceiling_line(data)
|
|
149
|
+
lines.compact
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# " ↳ ruby ceiling: <receipt>" (or "python ceiling"), coloured by tier (red =
|
|
153
|
+
# strands you on an EOL runtime, dim = an FYI cap below the latest stable).
|
|
154
|
+
# Reuses poison_colour; the runtime name comes off the finding, not hardcoded.
|
|
155
|
+
def language_ceiling_line(data)
|
|
156
|
+
ceiling = data[:language_ceiling]
|
|
157
|
+
return if ceiling.nil?
|
|
158
|
+
|
|
159
|
+
AnsiHelper.public_send(poison_colour(ceiling[:severity]), " ↳ #{ceiling[:runtime].downcase} ceiling: #{language_ceiling_receipt(ceiling, data)}")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def language_ceiling_receipt(ceiling, data)
|
|
163
|
+
runtime = ceiling[:runtime]
|
|
164
|
+
base =
|
|
165
|
+
if ceiling[:eol_forced]
|
|
166
|
+
"requires #{runtime} #{ceiling[:requirement]}, stranding you on end-of-life #{runtime} #{ceiling[:ceiling_version]}#{eol_suffix(ceiling[:ceiling_eol_date])}"
|
|
167
|
+
else
|
|
168
|
+
"requires #{runtime} #{ceiling[:requirement]}, no #{runtime} #{ceiling[:latest_stable]} support yet"
|
|
169
|
+
end
|
|
170
|
+
"#{base}#{language_ceiling_fix_hint(ceiling, data)}"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def eol_suffix(eol_date)
|
|
174
|
+
eol_date ? " (EOL #{eol_date.strftime("%Y-%m-%d")})" : ""
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Name the actionable fix when a newer release of the gem lifts the cap; the
|
|
178
|
+
# gem's own name sits on the row directly above, so "upgrade to <latest>" reads
|
|
179
|
+
# unambiguously without repeating it.
|
|
180
|
+
def language_ceiling_fix_hint(ceiling, data)
|
|
181
|
+
return "" unless ceiling[:fixed_by_upgrade] && data[:latest_version]
|
|
182
|
+
|
|
183
|
+
"; upgrade to #{data[:latest_version]} to lift it"
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# " ↳ poison: caps <receipt>", coloured by severity tier (see poison_colour).
|
|
187
|
+
# The row is already red (poison requires a dormant gem); the sub-line tier
|
|
188
|
+
# says how urgent the cap is. Transitive gems name the direct parent that pulls
|
|
189
|
+
# the pill in, the actionable target.
|
|
190
|
+
def poison_line(data)
|
|
191
|
+
constraints = data[:constraints]
|
|
192
|
+
return if constraints.nil? || constraints.empty?
|
|
193
|
+
|
|
194
|
+
path = data[:dependency_path]
|
|
195
|
+
via = data[:direct] == false && path && path.length >= 2 ? " (via #{path.first})" : ""
|
|
196
|
+
# Colour carries the tier: red = act-now (3+ majors behind), yellow = plan,
|
|
197
|
+
# dim = a minor/FYI cap (1 behind). A security-relevant cap (it pins a
|
|
198
|
+
# vulnerable dependency below the fix) is always red -- that's the finding to
|
|
199
|
+
# act on regardless of how many majors behind it happens to be.
|
|
200
|
+
colour = data[:poison_security_relevant] ? :red : poison_colour(data[:poison_severity])
|
|
201
|
+
AnsiHelper.public_send(colour, " ↳ poison#{via}: #{poison_receipt(constraints)}#{poison_security_suffix(data)}")
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Names the vulnerable dependency a security-relevant poison cap pins you to. When
|
|
205
|
+
# the cap holds you BELOW THE FIX (every patched version is a major it forbids) we
|
|
206
|
+
# lead with that stronger, enforced claim and name the CVE and its nearest fix --
|
|
207
|
+
# "you cannot patch this without replacing the dormant capper". Otherwise the
|
|
208
|
+
# weaker "pins vulnerable X" (the dep is vulnerable, but patchable in place).
|
|
209
|
+
def poison_security_suffix(data)
|
|
210
|
+
return "" unless data[:poison_security_relevant]
|
|
211
|
+
|
|
212
|
+
below = Array(data[:constraints]).select { |c| c[:capped_below_fix] }
|
|
213
|
+
if below.any?
|
|
214
|
+
receipts = below.map { |c| "#{c[:dependency]} below the fix (#{c[:below_fix_advisory]} fixed in #{c[:below_fix_fixed_in]})" }.uniq
|
|
215
|
+
" ⚠ pins #{receipts.join("; ")}"
|
|
216
|
+
else
|
|
217
|
+
pinned = Array(data[:constraints]).select { |c| c[:capped_dep_vulnerable] }.map { |c| c[:dependency] }.uniq
|
|
218
|
+
" ⚠ pins vulnerable #{pinned.join(", ")}"
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def poison_colour(severity)
|
|
223
|
+
{ critical: :red, warning: :yellow, note: :dim }.fetch(severity, :yellow)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# A worst-first "N label (X critical, Y note)" summary fragment, coloured by
|
|
227
|
+
# the worst tier present, or nil when there are none. Shared by the poison and
|
|
228
|
+
# Ruby-ceiling counts (both roll a set of tiered findings up the same way).
|
|
229
|
+
def tier_summary_part(severities, label)
|
|
230
|
+
return if severities.empty?
|
|
231
|
+
|
|
232
|
+
by_tier = severities.group_by { |severity| severity || :note }
|
|
233
|
+
present = ConstraintHelper::SEVERITY.reverse.select { |tier| by_tier[tier] } # worst-first
|
|
234
|
+
breakdown = present.map { |tier| "#{by_tier[tier].size} #{tier}" }.join(", ")
|
|
235
|
+
AnsiHelper.public_send(poison_colour(present.first), "#{label} (#{breakdown})")
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Single cap: the full receipt (requirement + latest major), since there's
|
|
239
|
+
# room. Many caps: the worst 3 by majors-behind + "+N more", a glanceable
|
|
240
|
+
# summary; the complete list stays in the JSON output.
|
|
241
|
+
def poison_receipt(constraints)
|
|
242
|
+
top = ConstraintHelper.top_findings(constraints, limit: 3)
|
|
243
|
+
return single_cap_receipt(top[:shown].first) if top[:total] == 1
|
|
244
|
+
|
|
245
|
+
parts = top[:shown].each_with_index.map do |finding, i|
|
|
246
|
+
count = finding[:majors_behind]
|
|
247
|
+
i.zero? ? "#{finding[:dependency]} (#{count} behind)" : "#{finding[:dependency]} (#{count})"
|
|
248
|
+
end
|
|
249
|
+
remaining = top[:total] - top[:shown].length
|
|
250
|
+
receipt = "caps #{parts.join(", ")}"
|
|
251
|
+
remaining.positive? ? "#{receipt} +#{remaining} more" : receipt
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def single_cap_receipt(finding)
|
|
255
|
+
behind = finding[:majors_behind]
|
|
256
|
+
"caps #{finding[:dependency]} #{finding[:requirement]} " \
|
|
257
|
+
"(#{behind} major#{"s" unless behind == 1} behind, latest #{major_x(finding[:dep_latest])})"
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# "8.0.1" -> "8.x": the cap is a major-level gap, so the major is the honest
|
|
261
|
+
# granularity to name as the current latest.
|
|
262
|
+
def major_x(version)
|
|
263
|
+
major = version.to_s[/\d+/]
|
|
264
|
+
major ? "#{major}.x" : version
|
|
265
|
+
end
|
|
266
|
+
|
|
133
267
|
def alternatives_line(data)
|
|
134
268
|
level = ActivityHelper.activity_level(data)
|
|
135
269
|
return unless [:archived, :critical].include?(level)
|
|
@@ -142,6 +276,18 @@ module StillActive
|
|
|
142
276
|
end
|
|
143
277
|
end
|
|
144
278
|
|
|
279
|
+
# For a flagged transitive gem, name the direct dependency that pulls it in,
|
|
280
|
+
# the gem the user can actually act on (#60).
|
|
281
|
+
def dependency_path_line(data)
|
|
282
|
+
path = data[:dependency_path]
|
|
283
|
+
return unless path && path.length >= 2
|
|
284
|
+
|
|
285
|
+
level = ActivityHelper.activity_level(data)
|
|
286
|
+
return unless [:archived, :critical].include?(level) || data[:vulnerability_count].to_i.positive?
|
|
287
|
+
|
|
288
|
+
AnsiHelper.dim(" ↳ transitive, pulled in by #{path.first}")
|
|
289
|
+
end
|
|
290
|
+
|
|
145
291
|
def ruby_summary_line(ruby_info)
|
|
146
292
|
version = ruby_info[:version]
|
|
147
293
|
latest = ruby_info[:latest_version]
|
|
@@ -161,29 +307,31 @@ module StillActive
|
|
|
161
307
|
end
|
|
162
308
|
end
|
|
163
309
|
|
|
310
|
+
# Reuse the same digest the JSON output emits so the human summary line can
|
|
311
|
+
# never drift from the machine one (the #63 "computed two ways" trap). The
|
|
312
|
+
# terminal keeps a coarser grouping (critical folds into stale) and adds its
|
|
313
|
+
# own yanked / total-libyear extras that the JSON digest doesn't carry.
|
|
164
314
|
def summary_line(result)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
.tally
|
|
170
|
-
|
|
171
|
-
up_to_date = version_counts.fetch(true, 0)
|
|
172
|
-
outdated = version_counts.fetch(false, 0)
|
|
315
|
+
summary = SummaryHelper.summarize(result)
|
|
316
|
+
active = summary[:activity][:ok]
|
|
317
|
+
stale = summary[:activity][:stale] + summary[:activity][:critical]
|
|
318
|
+
archived = summary[:activity][:archived]
|
|
173
319
|
yanked = result.each_value.count { |d| d[:version_yanked] }
|
|
174
|
-
active = level_counts.fetch(:ok, 0)
|
|
175
|
-
archived = level_counts.fetch(:archived, 0)
|
|
176
|
-
stale = level_counts.fetch(:stale, 0) + level_counts.fetch(:critical, 0)
|
|
177
|
-
vulns = result.each_value.sum { |d| d[:vulnerability_count] || 0 }
|
|
178
320
|
|
|
179
|
-
parts = [
|
|
180
|
-
"#{total} gems: #{up_to_date} up to date, #{outdated} outdated",
|
|
181
|
-
]
|
|
321
|
+
parts = ["#{summary[:total_gems]} gems: #{summary[:up_to_date]} up to date, #{summary[:outdated]} outdated"]
|
|
182
322
|
parts.last << ", #{yanked} yanked" if yanked > 0
|
|
183
323
|
activity = "#{active} active, #{stale} stale"
|
|
184
324
|
activity << ", #{archived} archived" if archived > 0
|
|
185
325
|
parts << activity
|
|
186
|
-
parts << "#{
|
|
326
|
+
parts << "#{summary[:vulnerabilities]} vulnerabilities"
|
|
327
|
+
poison_tiers = result.each_value.select { |data| data[:poison] }.map { |data| data[:poison_severity] }
|
|
328
|
+
poison_part = tier_summary_part(poison_tiers, "#{poison_tiers.size} poison-#{poison_tiers.size == 1 ? "pill" : "pills"}")
|
|
329
|
+
parts << poison_part if poison_part
|
|
330
|
+
ceilings = result.each_value.filter_map { |data| data[:language_ceiling] }
|
|
331
|
+
runtimes = ceilings.map { |ceiling| ceiling[:runtime] }.uniq
|
|
332
|
+
runtime_label = runtimes.size == 1 ? runtimes.first : "language"
|
|
333
|
+
ceiling_part = tier_summary_part(ceilings.map { |ceiling| ceiling[:severity] }, "#{ceilings.size} #{runtime_label} ceiling#{"s" unless ceilings.size == 1}")
|
|
334
|
+
parts << ceiling_part if ceiling_part
|
|
187
335
|
total_libyear = LibyearHelper.total_libyear(result)
|
|
188
336
|
parts << "#{total_libyear.round(1)} libyears behind" if total_libyear > 0
|
|
189
337
|
parts.join(" · ")
|
|
@@ -12,7 +12,13 @@ module StillActive
|
|
|
12
12
|
elsif !version_string.nil?
|
|
13
13
|
versions&.find { |v| v["number"] == version_string }
|
|
14
14
|
else
|
|
15
|
-
|
|
15
|
+
# The "latest" of a kind: pick the highest by version rather than trust
|
|
16
|
+
# the source's ordering. RubyGems happens to return newest-first, but
|
|
17
|
+
# GitHub Packages and other sources don't, and a wrong "latest" cascades
|
|
18
|
+
# into up_to_date and libyear.
|
|
19
|
+
versions
|
|
20
|
+
&.select { |v| v["prerelease"] == pre_release }
|
|
21
|
+
&.max_by { |v| to_gem_version(v["number"]) || Gem::Version.new("0") }
|
|
16
22
|
end
|
|
17
23
|
end
|
|
18
24
|
|
|
@@ -38,6 +44,15 @@ module StillActive
|
|
|
38
44
|
Time.parse(release_date) unless release_date.nil?
|
|
39
45
|
end
|
|
40
46
|
|
|
47
|
+
# The version's declared Ruby requirement (the `ruby_version` field in the
|
|
48
|
+
# RubyGems versions payload, e.g. ">= 3.2", "< 3.2"), or nil when absent. This
|
|
49
|
+
# is the language-runtime ceiling's raw input; note it is `ruby_version`, not
|
|
50
|
+
# the gemspec's `required_ruby_version`.
|
|
51
|
+
def ruby_requirement(version_hash:)
|
|
52
|
+
requirement = version_hash&.dig("ruby_version")
|
|
53
|
+
requirement unless requirement.nil? || requirement.empty?
|
|
54
|
+
end
|
|
55
|
+
|
|
41
56
|
# SPDX license identifier(s) from the RubyGems versions payload.
|
|
42
57
|
# Comma-joined when a gem declares more than one. nil when unknown.
|
|
43
58
|
def license(version_hash:)
|
|
@@ -6,20 +6,77 @@ module StillActive
|
|
|
6
6
|
|
|
7
7
|
SEVERITY_ORDER = ["low", "medium", "high", "critical"].freeze
|
|
8
8
|
|
|
9
|
+
# OSV's GHSA severity labels, mapped to our order. deps.dev stores only CVSS 3.x, so
|
|
10
|
+
# a CVSS-4-only advisory returns cvss3Score 0 (unscored); OSV's
|
|
11
|
+
# `database_specific.severity` reads correctly for it and rescues a real HIGH from
|
|
12
|
+
# fail-closed noise. GitHub uses MODERATE where we use medium.
|
|
13
|
+
OSV_LABELS = { "critical" => "critical", "high" => "high", "moderate" => "medium", "medium" => "medium", "low" => "low" }.freeze
|
|
14
|
+
|
|
9
15
|
def highest_severity(vulnerabilities)
|
|
10
16
|
return if vulnerabilities.nil? || vulnerabilities.empty?
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
vulnerabilities
|
|
19
|
+
.filter_map { |v| advisory_severity(v) }
|
|
20
|
+
.max_by { |label| SEVERITY_ORDER.index(label) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# One advisory's severity label ("low".."critical"), or nil when genuinely unscored.
|
|
24
|
+
# The authoritative GHSA/OSV label is a FLOOR: a real CVSS number sharpens precision
|
|
25
|
+
# and can RAISE the band, but never lowers it below the label. This matters because
|
|
26
|
+
# the OSV-derived score is cvss-suite's overall_score, which folds in any
|
|
27
|
+
# threat/environmental metrics a vector carries (and can diverge from GHSA at a band
|
|
28
|
+
# edge) -- on a fail-closed, no-false-positive tool a computed number must not
|
|
29
|
+
# silently demote a GHSA-HIGH finding out of a severity gate. With only one of the
|
|
30
|
+
# two present, that one stands.
|
|
31
|
+
def advisory_severity(vulnerability)
|
|
32
|
+
from_score = (score = effective_score(vulnerability)) ? severity_label(score) : nil
|
|
33
|
+
from_label = OSV_LABELS[vulnerability[:osv_severity].to_s.downcase]
|
|
34
|
+
return from_score || from_label if from_score.nil? || from_label.nil?
|
|
35
|
+
|
|
36
|
+
[from_score, from_label].max_by { |label| SEVERITY_ORDER.index(label) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Unknown = no CVSS score AND no OSV label. A freshly disclosed CVE often has
|
|
40
|
+
# neither yet, and the cross-ecosystem lens emits a minimal advisory when
|
|
41
|
+
# detail-fetch fails. The CVSS-4-only case (deps.dev returns cvss3Score 0, its
|
|
42
|
+
# "no 3.x score" sentinel, for two HIGH protobuf GHSAs scored CVSS 4.0) is no
|
|
43
|
+
# longer unknown once OSV enrichment attaches the GHSA severity label -- that's
|
|
44
|
+
# the whole point of the enrichment: a real HIGH stops failing closed as unscored.
|
|
45
|
+
# A truly unknown advisory still fails closed on a gate.
|
|
46
|
+
def unknown_severity?(vulnerability)
|
|
47
|
+
advisory_severity(vulnerability).nil?
|
|
48
|
+
end
|
|
14
49
|
|
|
15
|
-
|
|
50
|
+
# True when at least one advisory has no fixed version available -- the gem
|
|
51
|
+
# can't be upgraded out of the vulnerability. Only ruby-advisory-db sets this
|
|
52
|
+
# today; a deps.dev-only advisory leaves it nil (unknown), which reads false.
|
|
53
|
+
def no_fix_available?(vulnerabilities)
|
|
54
|
+
Array(vulnerabilities).any? { |vulnerability| vulnerability[:no_fix_available] }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# The best real CVSS score for an advisory, or nil when none is usable. Prefers
|
|
58
|
+
# deps.dev's v3/v2, then the score OSV enrichment computed from a v4 (or v3)
|
|
59
|
+
# vector. A score of 0 is treated as absent: deps.dev only stores CVSS 3.x, so a
|
|
60
|
+
# CVSS-4-only advisory (e.g. two HIGH protobuf GHSAs) comes back with cvss3Score
|
|
61
|
+
# 0 -- its "no 3.x score" sentinel, not a genuine severity of zero (which
|
|
62
|
+
# published advisories never carry) -- and the OSV v4 score fills that gap. Every
|
|
63
|
+
# consumer of a numeric score (severity labels, SARIF level, CycloneDX rating)
|
|
64
|
+
# routes through here so a 0 can't masquerade as "low" and silently clear a gate.
|
|
65
|
+
def effective_score(vulnerability)
|
|
66
|
+
[vulnerability[:cvss3_score], vulnerability[:cvss2_score], vulnerability[:osv_cvss_score]].find { |score| score&.positive? }
|
|
16
67
|
end
|
|
17
68
|
|
|
18
69
|
def severity_at_or_above?(vulnerabilities, threshold)
|
|
19
|
-
|
|
20
|
-
|
|
70
|
+
return false if vulnerabilities.nil? || vulnerabilities.empty?
|
|
71
|
+
|
|
72
|
+
# Fail closed on an unscored advisory: a confirmed advisory we can't score
|
|
73
|
+
# could be anything up to critical (and fresh CVEs commonly lack a score),
|
|
74
|
+
# so passing it as "below threshold" would silently clear a severity gate on
|
|
75
|
+
# a real finding. The user accepts a specific advisory via a suppression if
|
|
76
|
+
# they've reviewed it. Only when every advisory is scored do we compare.
|
|
77
|
+
return true if vulnerabilities.any? { |vulnerability| unknown_severity?(vulnerability) }
|
|
21
78
|
|
|
22
|
-
SEVERITY_ORDER.index(
|
|
79
|
+
SEVERITY_ORDER.index(highest_severity(vulnerabilities)) >= SEVERITY_ORDER.index(threshold)
|
|
23
80
|
end
|
|
24
81
|
|
|
25
82
|
# Combines advisories from deps.dev and ruby-advisory-db (via bundler-audit),
|
|
@@ -44,7 +101,11 @@ module StillActive
|
|
|
44
101
|
private
|
|
45
102
|
|
|
46
103
|
def identifiers(advisory)
|
|
47
|
-
|
|
104
|
+
# Coerce to strings: advisory ids/aliases are strings, but deps.dev's ALPHA API
|
|
105
|
+
# could drift and hand back a non-string alias, and a mixed array makes the
|
|
106
|
+
# union's `.sort` (in combine!) raise -- which escapes to the per-gem rescue that
|
|
107
|
+
# strips ALL the gem's signals, reading a known-vulnerable gem as clean.
|
|
108
|
+
[advisory[:id], *advisory[:aliases]].compact.map(&:to_s)
|
|
48
109
|
end
|
|
49
110
|
|
|
50
111
|
# Folds a ruby-advisory-db advisory into a matching deps.dev advisory in place:
|
|
@@ -56,6 +117,11 @@ module StillActive
|
|
|
56
117
|
into[:title] ||= from[:title]
|
|
57
118
|
into[:url] ||= from[:url]
|
|
58
119
|
into[:aliases] = (identifiers(into) | identifiers(from)).reject { |id| id == into[:id] }.sort
|
|
120
|
+
# ruby-advisory-db is the sole authority for fix availability; its
|
|
121
|
+
# determination wins whenever it has one (deps.dev leaves the key absent
|
|
122
|
+
# today, but this fails safe if that ever changes: a radb "no fix" can't be
|
|
123
|
+
# overridden by a stale/absent deps.dev value on a security-adjacent field).
|
|
124
|
+
into[:no_fix_available] = from[:no_fix_available] unless from[:no_fix_available].nil?
|
|
59
125
|
into[:source] = "merged"
|
|
60
126
|
end
|
|
61
127
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler"
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "json"
|
|
6
|
+
require "uri"
|
|
7
|
+
require_relative "../helpers/http_helper"
|
|
8
|
+
|
|
9
|
+
module StillActive
|
|
10
|
+
module ArtifactoryClient
|
|
11
|
+
extend self
|
|
12
|
+
|
|
13
|
+
def artifactory_uri?(uri)
|
|
14
|
+
# Hostnames are case-insensitive, so downcase before the suffix check; an
|
|
15
|
+
# uppercase jfrog host would otherwise be misread as an unqueryable source.
|
|
16
|
+
uri.is_a?(String) && URI(uri).host&.downcase&.end_with?(".jfrog.io")
|
|
17
|
+
rescue URI::InvalidURIError
|
|
18
|
+
false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def versions(gem_name:, source_uri:)
|
|
22
|
+
headers = auth_headers(gem_name: gem_name, source_uri: source_uri)
|
|
23
|
+
vs = RubygemsClient.versions(gem_name: gem_name, source_uri: source_uri, headers: headers)
|
|
24
|
+
return vs unless vs.empty?
|
|
25
|
+
|
|
26
|
+
AqlClient.versions(gem_name: gem_name, source_uri: source_uri, headers: headers)
|
|
27
|
+
rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout, SocketError
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def credentials(gem_name:, source_uri:)
|
|
34
|
+
host = URI(source_uri).host
|
|
35
|
+
bundler = Bundler.settings[source_uri] || Bundler.settings[host]
|
|
36
|
+
return bundler if bundler && !bundler.empty?
|
|
37
|
+
|
|
38
|
+
global = StillActive.config.artifactory_token
|
|
39
|
+
return unless global
|
|
40
|
+
|
|
41
|
+
configured_host = StillActive.config.artifactory_host
|
|
42
|
+
unless configured_host && host&.casecmp?(configured_host)
|
|
43
|
+
warn_unauthorized_host(gem_name: gem_name, host: host)
|
|
44
|
+
return
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
global
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def warn_unauthorized_host(gem_name:, host:)
|
|
51
|
+
$stderr.puts(
|
|
52
|
+
"warning: an Artifactory token is set but #{host} (source for #{gem_name}) is not an authorized host, " \
|
|
53
|
+
"so the token will not be sent. " \
|
|
54
|
+
"To allow it, set --artifactory-host=#{host} or STILL_ACTIVE_ARTIFACTORY_HOST=#{host}",
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def auth_headers(gem_name:, source_uri:)
|
|
59
|
+
creds = credentials(gem_name: gem_name, source_uri: source_uri)
|
|
60
|
+
return {} unless creds
|
|
61
|
+
|
|
62
|
+
if creds.include?(":")
|
|
63
|
+
user, pass = creds.split(":", 2).map { |part| CGI.unescape(part) }
|
|
64
|
+
{ "Authorization" => "Basic #{["#{user}:#{pass}"].pack("m0")}" }
|
|
65
|
+
else
|
|
66
|
+
{ "Authorization" => "Bearer #{creds}" }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Artifactory's Rubygems-compatible API
|
|
71
|
+
module RubygemsClient
|
|
72
|
+
extend self
|
|
73
|
+
|
|
74
|
+
def versions(gem_name:, source_uri:, headers: {})
|
|
75
|
+
base = URI(source_uri.chomp("/"))
|
|
76
|
+
path = "#{base.path}/api/v1/versions/#{encode(gem_name)}.json"
|
|
77
|
+
HttpHelper.get_json(base, path, headers: headers) || []
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def encode(value)
|
|
83
|
+
CGI.escape(value)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# AQL stands for Artifactory Query Language
|
|
88
|
+
# https://docs.jfrog.com/artifactory/docs/artifactory-query-language
|
|
89
|
+
module AqlClient
|
|
90
|
+
extend self
|
|
91
|
+
|
|
92
|
+
SOURCE_URL_PATTERN = %r{\A(https?://[^/]+\.jfrog\.io/[^/]+)/api/gems/([^/]+)/?\z}
|
|
93
|
+
AQL_PATH = "/api/search/aql"
|
|
94
|
+
|
|
95
|
+
def versions(gem_name:, source_uri:, headers: {})
|
|
96
|
+
artifactory_base, repo_key = parse_source_url(source_uri)
|
|
97
|
+
return [] if artifactory_base.nil?
|
|
98
|
+
|
|
99
|
+
base = URI(artifactory_base)
|
|
100
|
+
path = "#{base.path}#{AQL_PATH}"
|
|
101
|
+
query = {
|
|
102
|
+
"name" => { "$match" => "#{gem_name}-*.gem" },
|
|
103
|
+
"repo" => repo_key,
|
|
104
|
+
}
|
|
105
|
+
body = %(items.find(#{JSON.generate(query)}).include("repo", "path", "name", "created"))
|
|
106
|
+
response = HttpHelper.post_json(base, path, body: body, headers: headers.merge("Content-Type" => "text/plain"))
|
|
107
|
+
return [] if response.nil?
|
|
108
|
+
|
|
109
|
+
results = response["results"] || []
|
|
110
|
+
build_version_hashes(results: results, gem_name: gem_name)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def parse_source_url(source_uri)
|
|
116
|
+
match = source_uri.match(SOURCE_URL_PATTERN)
|
|
117
|
+
unless match
|
|
118
|
+
$stderr.puts("warning: unrecognized Artifactory source URL for AQL fallback: #{source_uri}")
|
|
119
|
+
return [nil, nil]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
[match[1], match[2]]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def build_version_hashes(results:, gem_name:)
|
|
126
|
+
results
|
|
127
|
+
.filter_map do |item|
|
|
128
|
+
version = extract_version(item["name"], gem_name)
|
|
129
|
+
next if version.nil?
|
|
130
|
+
|
|
131
|
+
{
|
|
132
|
+
"number" => version,
|
|
133
|
+
"created_at" => item["created"],
|
|
134
|
+
"prerelease" => Gem::Version.new(version).prerelease?,
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
.uniq { |h| h["number"] }
|
|
138
|
+
.sort_by { |h| Gem::Version.new(h["number"]) }
|
|
139
|
+
.reverse
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def extract_version(filename, gem_name)
|
|
143
|
+
prefix = "#{gem_name}-"
|
|
144
|
+
return unless filename&.end_with?(".gem") && filename.start_with?(prefix)
|
|
145
|
+
|
|
146
|
+
version_part = filename[prefix.length..-5]
|
|
147
|
+
return if version_part.nil? || version_part.empty?
|
|
148
|
+
|
|
149
|
+
parse_version_from_filename_tail(version_part)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Given the portion of a `.gem` filename after `name-`, returns the
|
|
153
|
+
# leading semver (e.g. `7.0.0` from `7.0.0-x86_64-linux`). Ignores
|
|
154
|
+
# unrelated artifacts that share a prefix (e.g. `datadog-ruby_core_source`
|
|
155
|
+
# when the gem name is `datadog`).
|
|
156
|
+
def parse_version_from_filename_tail(version_part)
|
|
157
|
+
segments = version_part.split("-")
|
|
158
|
+
segments.length.times do |i|
|
|
159
|
+
candidate = segments[0, i + 1].join("-")
|
|
160
|
+
return candidate if Gem::Version.correct?(candidate)
|
|
161
|
+
end
|
|
162
|
+
nil
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StillActive
|
|
4
|
+
# Whole-tree correlation between the two capping signals, run once after the
|
|
5
|
+
# fan-out (native or SBOM) has assembled every package's findings. A language
|
|
6
|
+
# ceiling that says "upgrade <package> to lift it" is wrong if the same tree
|
|
7
|
+
# poisons <package> below that upgrade (a dormant dependency caps it): the
|
|
8
|
+
# report must never advise an upgrade its own poison finding says is impossible.
|
|
9
|
+
# All data is already in the assembled result, so this is one pass, no fetches.
|
|
10
|
+
# "The correlation layer must correlate."
|
|
11
|
+
module CeilingReconciler
|
|
12
|
+
extend self
|
|
13
|
+
|
|
14
|
+
def reconcile_ceiling_with_poison(result_object)
|
|
15
|
+
# Qualify each capped dependency by the ecosystem that declares the cap. A
|
|
16
|
+
# capped dep resolves in its parent's ecosystem, so a poison finding on a
|
|
17
|
+
# `pypi` package caps a `pypi` dependency. A mixed SBOM has two flat-
|
|
18
|
+
# resolution ecosystems (rubygems + pypi), so a bare-name match alone would
|
|
19
|
+
# let a rubygems poison-cap on "foo" wrongly block a pypi "foo"'s ceiling.
|
|
20
|
+
# Native results carry no :ecosystem (all rubygems) -> nil on both sides,
|
|
21
|
+
# still consistent.
|
|
22
|
+
capped = result_object.each_value
|
|
23
|
+
.flat_map do |data|
|
|
24
|
+
Array(data[:constraints])
|
|
25
|
+
.select { |constraint| constraint[:majors_behind].to_i.positive? }
|
|
26
|
+
.map { |constraint| "#{data[:ecosystem]}/#{constraint[:dependency]}" }
|
|
27
|
+
end
|
|
28
|
+
.uniq
|
|
29
|
+
result_object.each do |key, data|
|
|
30
|
+
ceiling = data[:language_ceiling]
|
|
31
|
+
next unless ceiling && ceiling[:fixed_by_upgrade]
|
|
32
|
+
|
|
33
|
+
# Native results are keyed by the bare gem name; SBOM results are keyed by
|
|
34
|
+
# "ecosystem/name@version" and carry the bare name in :name.
|
|
35
|
+
package_name = data[:name] || key
|
|
36
|
+
next unless capped.include?("#{data[:ecosystem]}/#{package_name}")
|
|
37
|
+
|
|
38
|
+
ceiling[:fixed_by_upgrade] = false
|
|
39
|
+
ceiling[:upgrade_blocked] = true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|