Skip to content

Add vex --grype-config to list the VEX document in Grype's config - #2252

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
feat/vex-grype-config
Nov 25, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
feat/vex-grype-config

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

What

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. The default path is .grype.yaml.

This is a stopgap on the CLI side. Longer term, the scanner integrations should be driven by Socket's backend.

Behaviour

  • Create or merge. A missing config is created as vex-documents: with one item. An existing config gains one list item and keeps every other byte:

    • each line keeps its own ending, and a file mixing CRLF and LF is read line by line;
    • a missing final newline stays missing.
  • Already listed. An entry listed in any spelling (./socket.vex.json, out/../socket.vex.json, \ separators) leaves the file unchanged.

  • Removal. Grype fails a whole scan when a listed document is missing. A failed run that leaves no document at --output therefore takes every spelling of the entry out again.

  • Refused shapes. Grype refuses a key named twice. A config the editor cannot read with certainty 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. Refused shapes are:

    • a flow list or scalar;
    • the key in another case, or named twice;
    • nested content, or uneven or tab indentation;
    • a flow-style or indented root, or several YAML documents.

    A config or document path containing .. is not listed either, because a symlinked directory could send it elsewhere.

  • Entry. The entry is relative to the config's directory, which is where Grype resolves it when run there.

  • Output. --json reports grypeConfig: { path, entry, change }, and so does the error envelope when a failed run touched the config. --dry-run writes nothing and says what it would do. A human run prints one line when the config changes.

  • Usage error. --grype-config without --output is a usage error (grype_config_requires_output, exit 2).

  • Env var. SOCKET_VEX_GRYPE_CONFIG takes a path. Like the other SOCKET_VEX_* switches, 1, true and yes mean .grype.yaml, and 0, false and no mean off.

  • Docs. Documented under "Grype config" in CLI_CONTRACT.md and in docs/usage.md.

Grype behaviour this rests on

Checked with Grype 0.122.1:

Case Grype
vex-documents: [socket.vex.json], no --vex Hides the same 13 patched findings as --vex
Listed document missing The scan fails: VEX document "socket.vex.json" not found, exit 1
.grype.yaml next to an existing .grype/config.yaml Both are loaded, and the user's settings still apply
-c from another directory The listed path resolves against the working directory
vex-documents named twice The config fails to load: mapping key "vex-documents" already defined
vex-documents: with no items Loads fine

End to end, the release binary on an npm project with hosted patches added the entry to a team config holding fail-on-severity: critical. Plain grype dir:. then hid 13 findings and exited 0, because the only critical finding was a patched one.

Testing

  • YAML editor: 13 unit tests, covering shapes, the round trip, mixed line endings, a missing final newline, path spellings and quoting.
  • End to end: 7 tests in e2e_vex_grype_config:
    • create, then re-run;
    • merge into an existing config;
    • removal after a run that leaves no document;
    • a refused shape;
    • --dry-run;
    • --grype-config without --output;
    • a switch value in the env var.
  • Parse tests: the bare flag, an explicit path and the env var.
  • Env scrub: SOCKET_VEX_GRYPE_CONFIG is added to both lists of variables cleared from child processes.
  • Suites run:
    • core lib: 8573 passed;
    • CLI lib: 1068 passed;
    • VEX, Bazel and installer test binaries: all pass;
    • the full CLI suite passes except e2e_vendor_cargo_build's two old-toolchain tests. Those fail on this machine with "Bad CPU type in executable", unrelated to this change; CI runs them.
  • Lint: cargo clippy --locked --workspace --all-features -- -D warnings is clean.
  • Rendering: checked on a pty at 80, 100 and 120 columns.
  • /code-review high: 3 important and 7 minor findings, all fixed in the second commit.

For the owner

  • The flag name, --grype-config [<path>], and its env var SOCKET_VEX_GRYPE_CONFIG.
  • Exit 0 with a warning when the VEX document is written but the config can't be edited.
  • Only the standalone vex command has the flag for now. scan, apply and vendor (--vex-grype-config) can follow.

🤖 Generated with Claude Code


Generated by Claude Code

`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>
- 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>
@cursor

cursor Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Optional VEX workflow helper that only edits Grype config files when requested; core patch/scan behavior is unchanged.

Overview
Adds socket-patch vex --grype-config [<path>] (and SOCKET_VEX_GRYPE_CONFIG) so a generated OpenVEX file can be listed under vex-documents in a Grype config (default .grype.yaml), letting grype dir:. pick it up without --vex.

On a successful write, the CLI creates or surgically edits the config to add a relative path entry while preserving existing YAML shape and line endings; if the file is already listed (any spelling), it leaves it alone. On runs that end with no document at --output, it removes matching entries so Grype does not fail on a missing listed file. Uneditable configs get grype_config_not_updated with manual instructions; VEX success/failure is unchanged. --grype-config without --output is exit 2 (grype_config_requires_output). JSON envelopes gain grypeConfig: { path, entry, change }.

The YAML logic lives in socket-patch-core (vex/grype_config); orchestration is in vex_grype. Contract docs, usage guide, parse/e2e tests, and child-env scrub for the new variable are included.

Reviewed by Cursor Bugbot for commit de22dae. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit de22dae. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed the YAML line editor, the refused shapes and the removal on a failed run. One nit inline. The open Bugbot thread on same_path is real and worth fixing before or soon after merge; the compact-key thread is not a bug, since vex-documents:[] with no space is a plain scalar, not a key.

… 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
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
Merged via the queue into main with commit cfc870f Nov 25, 2026
79 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the feat/vex-grype-config branch November 25, 2026 22:32
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.

4 participants