Skip to content

Fix License Violations On Unchanged Root Components During PR Diff Scans - #909

Merged
orto17 merged 11 commits into
jfrog:devfrom
orto17:fix/license-violations-on-unchanged-roots
Oct 19, 2026
Merged

orto17 merged 11 commits into
jfrog:devfrom
orto17:fix/license-violations-on-unchanged-roots

Conversation

@orto17

@orto17 orto17 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....
  • All static analysis checks passed.
  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • Updated the Contributing page / ReadMe page / CI Workflow files if needed.
  • All changes are detailed at the description. if not already covered at JFrog Documentation, new documentation have been added.

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 via cdxutils.Exclude(sourceBom, targetBom.Components...), and this reduced SBOM is what gets uploaded and evaluated for violations.

Exclude deliberately 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 Licenses field 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 a dependsOn child 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:

Case Behavior
Root unchanged, at least one new/changed child survives Root is kept as-is (untouched, including its license) to anchor the real diff
Root unchanged, nothing real left underneath it Root is excluded entirely - from components and from every dependsOn list that references it, including the wrapper's

This 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-request run on a README-only PR (no dependency changes):

Before fix After fix
Violations Found 1 violations: [1 License] No violations found
Uploaded diffed SBOM Root present, carrying a license Empty (nothing left to diff)

orto17 and others added 2 commits October 4, 2026 16:37
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>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 4b0598ee-e72a-42df-8dda-3261b3ced8b9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@orto17 orto17 added bug Something isn't working safe to test Approve running integration tests on a pull request labels Oct 6, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 6, 2026

@attiasas attiasas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 7, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 7, 2026
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 8, 2026
@orto17
orto17 requested a review from attiasas October 8, 2026 08:15
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 8, 2026
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 8, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 8, 2026

@attiasas attiasas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 8, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 8, 2026
@orto17

orto17 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@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.
Added tests for a root whose purl changed, and an unchanged root depending on a changed child root (both pass untouched, as expected).

@orto17
orto17 requested a review from attiasas October 8, 2026 11:33
Comment thread sca/bom/bomgenerator_test.go Resolved
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>
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 14, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 14, 2026
@orto17 orto17 added the safe to test Approve running integration tests on a pull request label Oct 18, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Oct 18, 2026
@orto17
orto17 merged commit a682835 into jfrog:dev Oct 19, 2026
229 of 234 checks passed

This branch had an error being deployed

1 failed deployment
frogbot — 1c1ef280 Deployed Oct 18, 2026 by orto17 via scan-pull-request #4704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants