fix(bundler-audit): reset advisory fields so warnings cannot inherit stale values - #15716
Open
mhuzaifa3 wants to merge 1 commit into
Open
fix(bundler-audit): reset advisory fields so warnings cannot inherit stale values#15716mhuzaifa3 wants to merge 1 commit into
mhuzaifa3 wants to merge 1 commit into
Conversation
…stale values
get_findings resets advisory_id at the top of each warning block but leaves gem_name,
gem_version, advisory_title, advisory_url, advisory_solution and sev bound from the
previous iteration. Only Name is guaranteed in bundler-audit output, so a warning that
omits any other field is rendered against whatever the preceding warning happened to set.
Three consequences, all observable:
warning with no Advisory/CVE/GHSA line
TypeError: can only concatenate str (not "NoneType") to str
incomplete warning with nothing before it
UnboundLocalError: cannot access local variable 'advisory_title'
incomplete warning after a complete one
Gem sprockets: Directory traversal in Rack::Directory [CVE-2018-3760]
The third is the damaging one. A sprockets advisory that omits Criticality, Title and
Solution takes rack's title, rack's High severity and rack's remediation text, so the
finding tells the user to apply rack's fix to sprockets.
Resetting every field per warning, and building the title, description and fingerprint
from the fields actually present, makes a warning a function of its own text. A missing
Criticality line maps to Medium, matching the existing handling of bundler-audit's
"Unknown" criticality.
Identity is not affected: both existing fixtures parse to byte-identical findings, dedupe
fingerprint included, so no recorded sample changes and existing findings do not churn on
upgrade.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BundlerAuditParser.get_findingsresetsadvisory_idat the top of each warning block, but leavesgem_name,gem_version,advisory_title,advisory_url,advisory_solutionandsevbound from the previous iteration. OnlyNameis guaranteed in bundler-audit output, so a warning that omits any other field is rendered against whatever the preceding warning happened to set.Three failure modes, none caught by the existing fixtures because every warning in them carries a complete field set:
Advisory/CVE/GHSAlineTypeError: can only concatenate str (not "NoneType") to strUnboundLocalError: cannot access local variable 'advisory_title'The third is the damaging one. A
sprocketsadvisory that omitsCriticality,TitleandSolutiontakesrack's title,rack'sHighseverity andrack's remediation text, so the finding tells the user to apply rack's fix to sprockets:Fix
Reset every field per warning, and build the title, description and dedupe fingerprint from the fields actually present, so a warning is a function of its own text.
A missing
Criticalityline maps toMedium, matching the existing handling of bundler-audit'sUnknowncriticality. Happy to make thatInfoinstead if you would rather unrated advisories not inflate severity.Test results
Three fixtures and three tests added, one per failure mode:
unittests/scans/bundler_audit/no_advisory_id.txtunittests/scans/bundler_audit/incomplete_first.txtunittests/scans/bundler_audit/partial_fields.txtWith the fix applied:
With the fix reverted and the new tests kept:
Output for well-formed reports is byte-identical, dedupe fingerprint included, so no recorded sample changes and existing findings do not churn on upgrade. Both pre-existing tests pass unmodified. Ruff clean per
ruff.toml.Documentation
No documentation change needed. Behaviour for well-formed reports is unchanged.