Skip to content

Name each patched package as a VEX product so Trivy and Grype match it - #2243

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
fix/vex-package-products
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
fix/vex-package-products

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

socket-patch vex names only the project as each statement's product, with the patched packages as subcomponents. Trivy and Grype look a finding up by the package's own PURL, so the document suppresses nothing in either scanner.

Change

  • Project product unchanged. The project stays the first product, so readers of products[0].subcomponents see every package as before.
  • Package products. Each package then follows as a product of its own, with no subcomponents, under its PURL.
  • Platform gems. A gem with a platform qualifier is also named the way each scanner reports it:
    • pkg:gem/<name>@<version> (Trivy);
    • pkg:gem/<name>@<version>-<platform> (Grype, Syft), unless the platform is ruby. The platform is percent-decoded first.
  • Other qualifiers get no extra form. A Maven classifier or a PyPI file names a different artifact.
  • Forms left out when statuses disagree. A form is left out when, for one vulnerability (by its ID or any alias), it would stand for packages with different statuses. "Different" means one package is not_affected and another is affected, or has a patch record the document leaves out, such as a failed check. This applies to a package's own PURL too. A form equal to the --product override is not repeated.
  • Docs. Updated CLI_CONTRACT.md (Statement products), docs/usage.md (adds trivy / grype commands) and the Bazel example in docs/ecosystems.md.

Review findings not fixed as suggested

  • "Packages as top-level products reach every copy a scanner sees": kept. Trivy and Grype only match a VEX statement by the package's PURL; a directory scan has no PURL for the project. The contract and usage docs now say the document is only for the project it was made for.
  • "Never drop a statement's own PURL": kept the drop. When a patched pkg:gem/x@1.0 and an affected pkg:gem/x@1.0?platform=x86_64-linux share a form, Trivy reports both as pkg:gem/x@1.0. Naming that form not_affected would hide the unpatched build's CVE. Leaving it out keeps the finding visible, which is the safe direction. The contract text says so.

Testing

  • Unit tests for:

    • native gems, platform=ruby and a percent-encoded platform;
    • a Maven classifier, which gets no extra form;
    • a shared form with mixed statuses, with a build left out of the document, with one CVE under two GHSAs, and with every build patched;
    • the --product override.
  • Updated tests: the conformance tests, e2e_vex, e2e_embedded_vex, the Bazel harness, which compared the whole products array, and the Cargo redirect shapes test, which read subcomponents from every product.

  • Suites run: socket-patch-core lib (8556 passed) and every CLI test binary that reads VEX products (apply, vex, e2e_vex*, e2e_embedded_vex, e2e_hosted_production, e2e_gem_native_ext_build, e2e_redirect_cargo_shapes, the vlt suites, mode_migration_*). All pass.

  • Lint: cargo clippy --locked --workspace --all-features -- -D warnings is clean.

  • Real scanners: ran the release binary on an npm project with 10 hosted patches and on the same project vendored, then scanned with Trivy 0.76.2 (fs --vex) and Grype 0.122.1 (dir: --vex):

    Mode Before After
    Hosted 0 hidden in either scanner 13 hidden in both
    Vendored 0 hidden in either scanner 12 hidden in both

    A native-gem statement with both gem forms hides its finding in both scanners.

  • /code-review high: run on the first version of this PR. Its findings are fixed or answered above.

🤖 Generated with Claude Code

`socket-patch vex` named only the project as each statement's product,
with the patched packages as subcomponents. Trivy and Grype look a
finding up by the package's own PURL, so the document suppressed
nothing in either scanner.

Each statement now keeps the project product first, unchanged, and
names every package again as a product of its own: by its PURL, without
qualifiers, and for a gem built for a platform other than `ruby` as
`name@version-platform`, which is how Grype and Syft report it. A form
that would stand for packages of one vulnerability with different
statuses (a patched and an `affected` build of one gem) is left out, so
the scanner keeps reporting the finding.

Checked with Trivy 0.76.2 and Grype 0.122.1 on an npm project with 10
patched packages: the document now hides 13 patched findings in hosted
mode and 12 in vendored mode in both scanners, where it hid none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irect shapes test

Package products carry no subcomponents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review:
- Stripping qualifiers from a Maven classifier, a PyPI file or an npm
  vcs_url PURL could cover an artifact that was never patched, so only
  a gem's platform gets extra forms.
- A patch record the document leaves out (its check failed) now counts
  as an unpatched copy when deciding whether a shared form is safe.
- The check covers the vulnerability's aliases too, since scanners
  match statements by any of them.
- The platform is percent-decoded before it goes into
  name@version-platform.

The contract and usage docs say a package's own PURL can be left out
for the same reason, and that the document is only for the project it
was made for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 25, 2026 16:37
@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes VEX document shape consumed by security scanners; incorrect form omission could hide or over-suppress CVEs, though logic and tests target the safe direction.

Overview
VEX statements now list each patched package as its own product (empty subcomponents) after the project product, because Trivy and Grype match findings on the package PURL, not only project subcomponents.

For platform gems, the builder also emits scanner-specific PURL forms (Trivy name@version, Grype/Syft name@version-platform with decoded platform; no extra suffix for ruby). Conflicting forms are omitted: when one identifier would cover both not_affected and affected/unattested builds for the same vulnerability (including CVE aliases), that product id is dropped so scanners do not over-suppress. The --product id is not duplicated as a package product.

Docs add Statement products in CLI_CONTRACT.md, Trivy/Grype usage in docs/usage.md, and an updated Bazel VEX example. Tests (unit, conformance, e2e) expect multiple products per statement.

Reviewed by Cursor Bugbot for commit 58b95ea. Configure here.

The tests from #2224 compare whole statements, which now name each
package as a product of its own after the project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged via the queue into main with commit 8c2b260 Nov 25, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/vex-package-products branch November 25, 2026 17:32
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Nov 25, 2026
Main gained "Name each patched package as a VEX product so Trivy and
Grype match it" (#2243). No file has a conflict.

That change is to the VEX document and to the test harness that reads
one, which the NuGet flows of this branch go through where they hold
`vex` to a vendored package. They pass on the merged tree:
`nuget::vendored_mode_keeps_the_block_or_declines` finds the vendored
package as a product of its own in the document, beside the project.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants