Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ Every VEX statement's impact string records which patch-application mode persist

**Identifier overrides.** `--product` / `--vex-product` and `--doc-id` / `--vex-doc-id` are emitted with surrounding whitespace trimmed (a blank value means unset).

**Statement products.** The first product of every statement is the project (`--product` or the detected one), with the statement's packages as its subcomponents; readers that walk `products[0].subcomponents` see every package. Each package then follows as a product of its own with no subcomponents, which is how Trivy and Grype look a finding up, under its PURL and, for a gem with a `platform` qualifier, under the forms those scanners report it by: `pkg:gem/<name>@<version>` (Trivy) and, unless the platform is `ruby`, `pkg:gem/<name>@<version>-<platform>` (Grype, Syft), with the platform percent-decoded. Other qualifiers name a different artifact (a Maven classifier, a PyPI file), so they get no extra form. A form, the package's own PURL included, is left out of every statement of a vulnerability when it would stand for packages of that vulnerability, under its ID or any alias, with different statuses: an `affected` package, or one whose patch record the document leaves out, against a `not_affected` one. It is also left out when it equals the project's identifier. A scanner matches a package product wherever it finds that package, so the document is only for the project it was made for.

**No product to detect.** The product is read from the git `origin` remote, then from the name and version in `package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `composer.json`, `pom.xml`, the root's single `.csproj` or its single `.gemspec`. An application with none of these (a Bundler or pip project in a directory that has no git remote) has no product, and the run stops with `product_undetected` (`vex`: exit 2; embedded `--vex`: the host command's exit 1). No product is assumed: a directory name is not an identity (one checkout is `app` in a container and `workspace` in CI, and unrelated projects share those names), so a document issued under it could be read as a statement about another project. The message says what detection read, names any of those files that exists without a usable name and version, and ends with the run's own flag and a value built from the directory name, ready to paste: `… Pass a name that identifies this project, for example: --product pkg:generic/my-app` (`--vex-product …` on an embedded run). A run started in the project directory says `the current directory` instead of `.`.

**Patch hosts (manifest-less VEX).** A hosted lockfile reference counts only when it points at Socket's patch server or the operator's `--patch-server-url` / `SOCKET_PATCH_SERVER_URL` origin or under the `--patch-mirror-url` / `SOCKET_PATCH_MIRROR_URL` base. A hosted URL on any OTHER host — a staging patch server used without `--patch-server-url`, or a look-alike host — is not a hosted pin at all (v5.0: there is no redirect ledger to vouch for it), so `vex` does not attest it, and `list`, `rollback`, `remove`, `vendor` and `repair` do not see it either. Pass `--patch-server-url` for a non-production patch server. A pre-v5 redirect ledger still on disk does not change this: a record whose lockfile or recorded wiring resolves the package from a hosted-shaped URL on an origin this run was not given (or one carrying userinfo) is never attested from the ledger, whatever is installed and even under `--no-verify` / `--vex-no-verify`: `vex` reports it as `redirect_unwired`, with a `vex_claim_unwired` note naming the cause. (A patch that `apply`'s manifest also records is still verified as an agent-mode patch, on that record.) `scan` does not treat such wiring as gone: its takeover and hosted-wiring advisories still see it.
Expand Down
10 changes: 8 additions & 2 deletions crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,14 @@ impl Cell {
let named = named.unwrap_or_default();
let purl = normalize_purl(claim.purl);
assert_eq!(normalize_purl(named), purl, "{test}: {text}");
let products = json!([{ "@id": PRODUCT, "subcomponents": [{ "@id": named }] }]);
assert_eq!(statement["products"], products, "{test}: {text}");
let project = json!({ "@id": PRODUCT, "subcomponents": [{ "@id": named }] });
assert_eq!(statement["products"][0], project, "{test}: {text}");
let products = statement["products"].as_array().map(Vec::as_slice);
let packages = products.unwrap_or_default().get(1..).unwrap_or_default();
assert!(
packages.iter().any(|p| p["@id"] == named),
"{test}: the package is a product of its own: {text}"
);
let (uuid, how) = (claim.uuid, claim.how.words());
if claim.affected() {
assert_eq!(statement["status"], "affected", "{test}: {text}");
Expand Down
5 changes: 3 additions & 2 deletions crates/socket-patch-cli/tests/e2e_bazel_build/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,11 +1725,12 @@ fn vex_says(cell: &Cell, standin: &StandIn, name: &str) -> (Value, Vec<Value>, [
}

/// The statement of a document of the fixture's product about the package
/// `id` and the advisory of the fixture's patches, without its status.
/// `id` and the advisory of the fixture's patches, without its status. The
/// package follows the product as a product of its own.
fn about(id: &Value) -> Value {
json!({
"vulnerability": { "name": "GHSA-test-aaaa-bbbb", "aliases": ["CVE-2024-0001"] },
"products": [{ "@id": PRODUCT, "subcomponents": [{ "@id": id }] }],
"products": [{ "@id": PRODUCT, "subcomponents": [{ "@id": id }] }, { "@id": id }],
})
}

Expand Down
7 changes: 6 additions & 1 deletion crates/socket-patch-cli/tests/e2e_embedded_vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ fn assert_not_affected_statement(
);

let products = stmt["products"].as_array().expect("statement.products");
assert_eq!(products.len(), 1, "exactly one product per statement");
assert_eq!(
products.len(),
2,
"the project, then the patched package as a product of its own"
);
assert_eq!(products[1]["@id"], expect_subcomponent);
assert_eq!(
products[0]["@id"], expect_product,
"product comes from --vex-product"
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/e2e_redirect_cargo_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ async fn run_shape(shape: Shape) -> Option<()> {
.unwrap()
.iter()
.flat_map(|st| st["products"].as_array().unwrap().clone())
.flat_map(|p| p["subcomponents"].as_array().unwrap().clone())
.flat_map(|p| p["subcomponents"].as_array().cloned().unwrap_or_default())
.map(|c| c["@id"].as_str().unwrap().to_string())
.collect();
attested.sort();
Expand Down
4 changes: 3 additions & 1 deletion crates/socket-patch-cli/tests/e2e_vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ fn no_verify_emits_valid_openvex() {
assert_eq!(s0["justification"], "inline_mitigations_already_exist");

let products = s0["products"].as_array().unwrap();
assert_eq!(products.len(), 1);
assert_eq!(products.len(), 2);
assert_eq!(products[0]["@id"], "pkg:npm/test-app@1.0.0");
let subs = products[0]["subcomponents"].as_array().unwrap();
assert_eq!(subs.len(), 1);
assert_eq!(subs[0]["@id"], "pkg:npm/lodash@4.17.20");
assert_eq!(products[1]["@id"], "pkg:npm/lodash@4.17.20");
assert!(products[1].get("subcomponents").is_none());

maybe_validate_with_vexctl(&stdout);
}
Expand Down
Loading
Loading