Repository navigation
Fix License Violations On Unchanged Root Components During PR Diff Scans - #909
Conversation
cdxutils.Exclude never removes root components from the diffed SBOM, by design, so a license attached to a root (local manifest or a Catalog name/version collision) persists unchanged across every PR scan and keeps firing a bound license policy even when nothing about that root changed. Strip the license on a root when it matches the target's component by purl, keeping the component for graph structure while a genuinely new/changed root still gets enforced. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… license A license-only strip on an unchanged root doesn't survive the pipeline: the SCA scan-graph/Catalog enrich step runs after the diff and re-resolves license data fresh for every component still present, silently re-attaching whatever was cleared. A multi-root scan also always lists every root as a dependsOn child of its own wrapper entry, so a root is never "unreferenced" on its own merely by touching its declared-dependencies entry. An unchanged root with at least one surviving (new/changed) child is still kept as-is, untouched, to anchor the real diff. A root with nothing real left underneath it is now excluded entirely - from Components and from every dependsOn list that references it (including the wrapper's) - so it is never resubmitted for re-enrichment and can no longer trigger a recurring violation. Verified end-to-end against a live Xray instance: a README-only PR via a real scan-pull-request run went from "Found 1 violations: [1 License]" to "No violations found", with the uploaded diffed SBOM confirmed empty. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
attiasas
left a comment
There was a problem hiding this comment.
The single-project case matches the description: an unchanged root with a surviving child stays, license included, and an unchanged root with nothing under it is removed so enrich cannot put the license back. Exclude only feeds getDiffSbom, and a root whose purl changed is still evaluated.
Please fix the nested-root pass and replace the multi-root test before merge.
One more case sits above this diff, so it cannot be an inline comment. Exclude returns immediately when Dependencies is nil or empty (cyclonedxutils.go:352). That guard predates this change. A package with no dependencies is written as a library component and no dependency entry, and hasDependenciesToScan still scans any library component, so that root's license is uploaded on every PR. Xray-lib usually has a metadata dependsOn, which is why the README-only Frogbot run still passes. getDiffSbom is also used for build-info, so this return should not skip a library root that is present in the target.
Exclusion of unchanged roots now repeats until a full pass excludes nothing more, so a root that depends on another unchanged root (e.g. a monorepo wrapper listing app and lib, where app depends on lib) is no longer kept just because it was checked before its own child got removed in the same pass. The BOM-wide early return on a missing/empty Dependencies array no longer skips exclusion entirely - a library root with no declared dependencies of its own is excluded by a straightforward purl match instead, since getDiffSbom is also used for technologies whose dependency-free roots carry no Dependencies entry at all. Replaced the invalid multi-root test (its ad hoc "file:workspace" ref never actually classified anything as a root) with cases built on the real Metadata.Component wrapper structure, plus new cascade and no-dependency-graph cases. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
attiasas
left a comment
There was a problem hiding this comment.
The direct-child case matches the description: an unchanged root with a surviving child stays, license included, and an unchanged root with nothing under it is removed. The empty-graph path and the mixed wrapper case look right. Exclude still only feeds getDiffSbom.
Please fix the transitive case, the unchanged-root cycle, and the cascade test before merge.
Two smaller gaps: the first loop still reads bom.Dependencies while writing through filteredSbom (same slice today; the cascade loop already passes filteredSbom.Dependencies). And there is no case for a root whose purl changed, or for an unchanged root that depends on a changed child root.
Non-root matched components were still dropped wholesale via the original excludeFromDependencies call, discarding their own declared children outright regardless of whether any of them were actually new. A lockfile change that only adds a transitive dependency under an otherwise-unchanged direct dependency silently uploaded nothing. Replace the root-only deferred pass with a single rule applied to every matched (unchanged) component uniformly: exclude it, from both Components and every dependsOn list that references it, only once it cannot reach anything outside the matched set - no new or changed component, and no other matched component that itself can. This is computed once as a reachability fixed point over the whole graph (calculateEscapingRefs), which naturally handles arbitrarily deep chains and also resolves a cycle of mutually-unchanged roots that a single non-cyclic pass could never see as childless. Updated two pre-existing tests whose expectations encoded the old wholesale-deletion behavior for a matched node with unconfirmed (not independently excluded) children; added tests for the transitive leaf case, the root cycle, a root whose purl changed, and an unchanged root depending on a changed child root. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@attiasas replaced the whole root-specific deferred-pass approach with one uniform rule applied to every matched (unchanged) component: it's excluded only once it can't reach anything outside the matched set, computed as a single reachability fixed point (calculateEscapingRefs) over the full graph rather than an ordered, root-only pass. This fixes the transitive case and the cycle case in one shot (details below), and the "reads bom.Dependencies while writing through filteredSbom" aliasing issue is gone structurally — there's no longer a first-loop/second-loop split, just one analysis pass and one edit pass. |
Matching only tracked the first component SearchComponentByCleanPurl found for a given normalized purl, but removal matched by purl too - so two distinct components sharing a normalized purl (same name+version, different hash) could have one's new child dropped along with the other's wholesale deletion. Exclude and excludeFromDependencies now key everything off the matched bom-refs themselves, so only the refs actually decided for exclusion are touched. calculateEscapingRefs also treated any dependsOn ref outside the matched set as a real escape, including one that does not resolve to any component at all (a dangling or malformed entry). Such a ref now carries no signal either way, so a root whose only child is unresolvable is still correctly excluded. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
devbranch.go vet ./....go fmt ./....Frogbot V3 PR scans report license violations on root components (npm/pypi/etc. project roots) on every pull request, even when the PR changes no dependencies. A README-only PR with zero dependency changes still fails on a recurring license violation, forever, because the root never actually gets removed from the diffed SBOM.
Root Cause
getDiffSbom(sca/bom/bomgenerator.go) computes the PR diff viacdxutils.Exclude(sourceBom, targetBom.Components...), and this reduced SBOM is what gets uploaded and evaluated for violations.Excludedeliberately never removed root components - by design, since a root anchors the dependency graph. That meant whatever license a root carried (from its own manifest, or from an Xray Catalog name/version collision with an unrelated published package - confirmed live during verification) persisted unchanged in every PR's uploaded SBOM, firing a bound license policy every time regardless of what actually changed.A naive fix (stripping just the
Licensesfield on an unchanged root) does not survive the real pipeline: the SCA scan-graph/Catalog enrich step runs after the diff and re-resolves license data fresh for every component still present, silently re-attaching whatever was cleared. A multi-root scan also always lists every root as adependsOnchild of its own wrapper entry, so a root is never "unreferenced" on its own merely by touching its declared-dependencies entry.Fix
An unchanged root (same purl as in the target branch) is now handled based on whether anything real survives underneath it:
componentsand from everydependsOnlist that references it, including the wrapper'sThis stops a fully-unchanged root from ever being resubmitted for re-enrichment, so it can no longer trigger a recurring violation, while a root that genuinely changed (new version, new/changed dependency) is still correctly evaluated.
Verification
Verified end-to-end against a live Xray instance using a real
frogbot scan-pull-requestrun on a README-only PR (no dependency changes):Found 1 violations: [1 License]No violations found