fix(diff): detect upgrades by stripping version from purl key#47
Open
dmchaledev wants to merge 1 commit into
Open
fix(diff): detect upgrades by stripping version from purl key#47dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
The component map was keyed on the raw purl, which embeds the version
(e.g. "pkg:npm/lodash@4.17.21"). Since virtually every real-world SBOM
component carries a purl, the tool's headline "upgraded dependencies"
detection never fired: an upgrade was misreported as an unrelated
remove + add.
Key components on a version-independent identity by stripping the
version segment from the purl. Namespace scopes ("@angular", encoded as
%40) and qualifiers/subpath are preserved. Falls back to the name when
no purl is present.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VKLSy7zqzDs5ztAf6jtKqw
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.
Problem
The headline "upgraded dependencies" feature is broken for essentially every real-world SBOM.
buildComponentMapinsrc/diff.tskeyed each component on its raw purl:But a purl embeds the version —
pkg:npm/lodash@4.17.21. Since tools likesyft,trivy,cdxgen, etc. emit a purl for virtually every component, an upgrade oflodash 4.17.20 → 4.17.21gets two different keys and is misreported as one removal + one addition, never as an upgrade. Upgrade detection only worked for the rare components with no purl.The previous test even enshrined the broken behavior as "correct":
Fix
Key components on a version-independent identity by stripping the version segment from the purl. The version follows the first literal
@; a namespace scope like@angularis percent-encoded as%40, so the scope is untouched. Qualifiers (?...) and subpath (#...) are preserved so components differing only by those stay distinct. Falls back to the component name when no purl is present.Verification
Before this change, an SBOM pair with purl-bearing components reported
Upgraded: 0(all changes shown as add/remove). After:%40-encoded) purl with a major bump, guarding the version-stripping edge case.typecheck, andlintall pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01VKLSy7zqzDs5ztAf6jtKqw
Generated by Claude Code