You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cfc870f
Browse filesBrowse the repository at this point in the historyBrowse files
Add vex --grype-config to list the VEX document in Grype's config (#2252)
* Add `vex --grype-config` to list the VEX document in Grype's config
`socket-patch vex --output socket.vex.json --grype-config [path]` keeps
the Grype config's `vex-documents` list naming the document, so a plain
`grype dir:.` reads it without `--vex`. `.grype.yaml` is the default.
- A missing config is created; an existing one gains one list item and
keeps every other byte (CRLF and a missing final newline included).
- Grype fails a whole scan when a listed document is missing, so a run
that leaves no document at `--output` takes the entry out again.
- Grype refuses a key named twice, and a config the editor cannot read
with certainty (a flow list, another spelling of the key, nested
content, several documents) is left as it is, with a
`grype_config_not_updated` warning naming the line to add. The VEX
document and the exit status stay the run's own.
- The entry is relative to the config's directory, which is where
Grype resolves it when run there.
- `--json` reports `grypeConfig: { path, entry, change }`; `--dry-run`
writes nothing and says what it would do.
Checked with Grype 0.122.1 on an npm project with hosted patches: the
config line alone hides the same 13 patched findings as `--vex`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Harden the Grype config editor after review
- Read a file mixing CRLF and LF line by line, so a key on an LF line
is found instead of appended a second time (Grype refuses a key named
twice). Each line keeps its own ending, and a missing final newline
stays missing.
- Treat `./socket.vex.json`, `out/../socket.vex.json` and `\`
separators as the same entry when adding and when removing.
- Refuse a config or document path with `..`, which a symlinked
directory could send elsewhere.
- Check the document shape (one block mapping) before every edit, not
only when the key is missing.
- Honour a quote only where it opens an item, as YAML does.
- After a failed run, warn when the config cannot be read or checked,
without claiming it lists the entry, and report the change in the
error envelope's `grypeConfig`.
- Read `SOCKET_VEX_GRYPE_CONFIG=1/true/yes` as `.grype.yaml` and
`0/false/no` as off, like the other SOCKET_VEX_* switches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Keep a leading `..` in the Grype entry match; preview would_remove in a dry run
- `same_path` popped on every `..`, so `../socket.vex.json` folded to
`socket.vex.json`: add reported the parent's entry as `listed` and
remove could drop it. A `..` with nothing to climb out of now stays.
- A dry run leaves a stale OpenVEX document in place, so the config
step saw it and never previewed `would_remove`, although the real run
removes both. It now asks whether the real run would remove the
document (`is_openvex_doc`, split out of `remove_stale_vex_doc`).
Assisted-by: Claude Code:claude-opus-5-5
* Break the vex <-> vex_grype import cycle
6281359 made vex_grype call vex::is_openvex_doc, a cycle that
command_module_layering refuses. vex.rs now asks is_openvex_doc itself
and passes the answer to unlist_missing_document as `stale_doc_kept`,
which skips the "a file is still at --output" early return. Behavior
is unchanged: a dry run still previews would_remove for a stale
OpenVEX document the real run would delete.
Assisted-by: Claude Code:claude-opus-5-5
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: crates/socket-patch-cli/CLI_CONTRACT.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -311,7 +311,7 @@ Beyond the globals above, each subcommand defines a small set of local arguments
311
311
| `get` | positional `identifier`; `--id` / `--cve` / `--ghsa` / `--package` (`-p`); `--save-only`; `--mode <hosted\|vendored\|agent>` | `SOCKET_SAVE_ONLY` | Patch lookup + consumption mode (v3.6). `--mode` reuses scan's value enum (same hidden value aliases `host`/`redirect`/`vendor`; deliberately no env binding, matching scan). Default (v5.0): the mode the project's patch state records, like scan (see **Mode resolution**), so `hosted` for a project with no state; `agent` (save + apply in place) when `--save-only` or `--global`/`--global-prefix` is given. An explicit `--mode hosted\|vendored` with `--global`/`--global-prefix` is a usage error (exit 2, scan's wording: global installs have no project lockfile). An explicit `--save-only` conflicts with `--mode hosted\|vendored` — rejected with **exit 1** via get's established self-enforced-conflict style (unlike scan's exit-2 mode conflicts; see the exit-code table) |
312
312
| `remove` | positional `identifier` (target grammar: UUID, PURL with or without version, or exact package name); `--skip-rollback`; `--preserve-state` (v5.0) | `SOCKET_SKIP_ROLLBACK`, `SOCKET_PRESERVE_STATE` | Manifest entry removal. The identifier matches like a `rollback` target (a PyPI name compares by its PEP 503 canonical form). `--preserve-state` is the single-patch twin of `rollback --preserve-state`: restore the tree and unwind the identifier's vendored/hosted wiring, but keep the manifest entry, the vendored artifact + ledger entry, and skip all GC. Combining it with `--skip-rollback` is a self-enforced usage error (exit 2): one flag keeps the tree and drops the state, the other restores the tree and keeps the state — together they select the do-nothing quadrant ("the combination would be a no-op: nothing would change"). The conflict fires whether either flag is spelled on the command line or sourced from its env var |
313
313
| `rollback` | optional variadic positional `targets` (PURL \| UUID \| package name \| path glob); `--preserve-state` (v5.0) | `SOCKET_PRESERVE_STATE` | Rollback scope. Multiple targets union. A token becomes a path glob ONLY when it is path-SHAPED — contains a separator (`/` or `\`) or a glob metacharacter (`*?[`), or starts with `./`, or is absolute (an npm `@scope/name` is a name, not a path; a relative slash name without glob metacharacters or `.`/`..` segments — composer `vendor/pkg`, a go module path — is a name when it selects a recorded or hosted patch); a `pkg:` prefix is a PURL and every other token keeps the target grammar (UUID, PURL or exact package name), so a mistyped identifier or truncated UUID stays a safe exit-1 "No patch found matching identifier: X" (with a hint suggesting `./X` or `X/**` for directory targeting) instead of silently becoming a path scope. An unparseable glob is a usage error (exit 2) |
| `vex` | `--output` / `-O`, `--product`, `--no-verify`, `--no-bazel`, `--doc-id`, `--compact`, `--grype-config [<path>]` | `SOCKET_VEX_OUTPUT`, `SOCKET_VEX_PRODUCT`, `SOCKET_VEX_NO_VERIFY`, `SOCKET_VEX_NO_BAZEL`, `SOCKET_VEX_DOC_ID`, `SOCKET_VEX_COMPACT`, `SOCKET_VEX_GRYPE_CONFIG` | OpenVEX 0.2.0 document generation; see "vex output channels" below. `--grype-config` lists the document in a Grype config (see "Grype config" below). `--no-bazel` is **Experimental** (Bazel workspaces) |
315
315
| `repair` | `--download-only` | `SOCKET_DOWNLOAD_ONLY` | Repair-specific cleanup mode (mutually exclusive with `--offline`; combining them is a usage error, exit 2) |
316
316
317
317
**pnpm hosted-mode contract**: `scan --mode hosted` handles block and flow resolutions in legacy `shrinkwrap.yaml` and lockfileVersion 5.x, 6.0, and 9.0. The [pinned compatibility matrix](../../docs/testing/pnpm-compatibility.md) samples pnpm majors 1–12. Early shrinkwrapVersion 3 without a positive minor version is refused with `redirect_pnpm_legacy_lockfile_unsupported`: pnpm 1.0.0 discards hosted URLs even on frozen installs. Upgrade to a tested release (1.43.1 or newer) and regenerate the lock, or use agent mode.
@@ -2789,6 +2789,7 @@ outcome for a selected record, rather than inferring a write from exit 0.
2789
2789
| `invalid_env` | scan | Usage error (exit 2): a malformed `SOCKET_MIN_SEVERITY` or `SOCKET_MAX_NEW_PATCHES`. |
2790
2790
| `filter_invalid` | scan | Usage error (exit 2): the `--selection-filter` file cannot be read or honored (internal interface, see "Selection filter"). |
| `grype_config_requires_output` | vex | Usage error (exit 2): `--grype-config` without `--output` (Grype reads the document from a file). |
2792
2793
| `no_patches` | vex | The manifest file exists but is empty AND no vendor-ledger record or lockfile reference names a patch (exit 1). |
2793
2794
| `vendor_ledger_corrupt` | vex (every form) | `.socket/vendor/state.json` exists but is malformed or unreadable. The vendor ledger is an attestation input (records and liveness), so attesting from a partial view is refused (exit 2 standalone; the host command fails). A missing ledger is simply empty. |
2794
2795
| `redirect_ledger_corrupt` | vex, list (`warnings[]`) | v5.0: a WARNING, no longer an error — a pre-v5 `.socket/vendor/redirect-state.json` exists but is malformed or unreadable. v5 hosted mode keeps no ledger (hosted references come from the lockfiles, their records from the API), so the file is only an optional migration record source: its records are not consulted and the run continues. Delete the file or restore it from version control. |
@@ -3209,6 +3210,16 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope
3209
3210
3210
3211
When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting <purl> from VEX: <reason> (<tag>)`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/<name>-<version>.gemspec\` and \`cache/<name>-<version>.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one) and run \`bundle install\`. Other projects may load a gem home outside the project, so for one run \`bundle config set --local path vendor/bundle && bundle install\` instead, then run \`socket-patch vex\` again.` A gem the manifest records under the same patch as the hosted pin keeps the general remedy, since `apply` patches it in place; a record of another patch, which the pin superseded, does not. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other.
3211
3212
3213
+
### Grype config (`vex --grype-config`)
3214
+
3215
+
`--grype-config [<path>]` (`SOCKET_VEX_GRYPE_CONFIG`; `.grype.yaml` when the flag has no value, or when the value is a switch value — `1`, `true`, `yes` — while `0`, `false`, `no` turn it off; resolved like `--output` against the current directory) keeps the config's top-level `vex-documents` list naming the `--output` document, so `grype` run in the config's directory reads it without `--vex`. It needs `--output` (`grype_config_requires_output`, exit 2, otherwise).
3216
+
3217
+
* **Entry.** The document's path relative to the config's directory, `/`-separated, quoted only when YAML would read it differently. Grype resolves a listed path against the directory it runs in. A document outside the config's directory, or a config or document path that contains `..`, is not listed. An item that names the same path in another spelling (`./socket.vex.json`, `out/../socket.vex.json`, `\` separators) counts as the entry, when adding and when removing.
3218
+
* **Edit.** A missing config is created as `vex-documents:` with the one item. An existing one gains the item: under its `vex-documents` block list, with the indentation of the last item, or as a new key appended to the document when it has none, or in place of an inline `[]`. Every other byte stays: each line keeps its own ending (a file mixing CRLF and LF is read line by line), new lines take the file's most common ending, and a missing final newline stays missing. A listed entry leaves the file unchanged.
3219
+
* **Refused shapes.** A config the editor cannot read with certainty is left unchanged: `vex-documents` with any other inline value (a flow list, a scalar), spelled in another case or named twice (Grype refuses both), items other than plain paths, uneven or tab indentation, nested content, a flow-style root, an indented root, or more than one YAML document. So is a config that is not a regular file or cannot be read or written. The run then warns `grype_config_not_updated` with the line to add, and the document and exit status stay the run's own.
3220
+
* **Removal.** Grype fails the whole scan when a listed document is missing. A failed run that leaves no document at `--output` (it removed the previous one, `vex_stale_doc_removed`, or there was none) takes every spelling of the entry out of the list, leaving the key. A config it cannot read or check with certainty is warned about (`grype_config_not_updated`, saying to remove the entry if it is there).
3221
+
* **Output.** The human summary adds one line when the config changes (`Created .grype.yaml, listing socket.vex.json in vex-documents`, `Listed … in vex-documents of …`, `Removed … from vex-documents of …, since the document is gone`). The success envelope carries `grypeConfig: { path, entry, change }`, with `change` one of `created`, `added`, `listed`, `not_updated`, or under `--dry-run` (which writes nothing) `would_create` / `would_add`. The error envelope of a failed run that touched the config carries it too, with `change` `removed`, `not_updated` or, under `--dry-run`, `would_remove`.
3222
+
3212
3223
## Semver policy
3213
3224
3214
3225
Versioning lives in **`Cargo.toml`** at the workspace root (`version = "..."`) and is propagated to the Cargo and npm packages by **`scripts/version-sync.sh <new-version>`** (the full list of stamped files is below).
0 commit comments