Repository navigation
Add an internal scan --selection-filter for reachability-aware patching - #2062
Conversation
`scan --selection-filter <FILE>` (or `SOCKET_SELECTION_FILTER`) reads a JSON sidecar that says what one scan need not patch: project roots, packages and advisories to skip, and reachability findings. It is the interface for Socket's remediation tooling (`socket fix` pull requests): hidden from `--help`, and versioned (`"version": 1`) rather than covered by semver. What a scan does with it: - `skip.paths` and `skip.packages` leave roots and packages alone, like socket.yml's `patches.ignorePaths` and `patches.ignorePackages`. - Each advisory a patch fixes is judged: skipped ids and `unreachable` findings need no fix, `reachable` and `unknown` ones do. The most specific finding decides (advisory and package, then advisory, then package), and `unlistedAdvisories: "skip"` turns the findings into an allowlist. - A patch is withheld only when no advisory it fixes needs a fix. A patch that fixes one that does is applied whole, so a merged patch brings its unreachable fixes along, and a package goes unpatched only when every advisory its patches fix is unreachable or skipped. - The filter never changes how patches rank; the severity floor judges the whole patch. One preference comes first: when exactly one advisory of a package needs a fix and a patch fixes it alone, that single-advisory patch is taken instead of a merged one. - It narrows beside the socket.yml policy and never removes a patch. A recorded patch the filter withholds gives way to a wanted one; a package already on a wanted merged patch follows the usual ranking. `policy.filtered[]` gains the reasons `filter_path_skipped`, `filter_package_skipped` and `filter_not_needed`, and a run given a filter echoes it as `policy.selectionFilter`. A file that cannot be read or honored fails before any request or write: exit 2, `filter_invalid`. The format reference is docs/selection-filter.md, with a JSON Schema in docs/selection-filter.schema.json that a unit test keeps in step with the parser. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit 9601238. Configure here. |
Adds
scan --selection-filter <FILE>(envSOCKET_SELECTION_FILTER): a JSON sidecar that says what one scan need not patch, so the scan applies only the patches that fix a reachable (or unknown) vulnerability. It is the interface for thesocket fixremediation pull requests. The flag is hidden from--help, and the file is versioned ("version": 1) instead of being covered by the CLI's semver policy.{ "version": 1, "skip": { "paths": ["services/legacy/"], "packages": ["pkg:npm/left-pad"], "advisories": ["GHSA-jf85-cpcp-j695", "CVE-2021-23337"] }, "reachability": [ { "advisory": "GHSA-35jh-r3h4-6jhm", "package": "pkg:npm/lodash@4.17.20", "state": "reachable" }, { "advisory": "GHSA-p6mc-m468-83gw", "state": "unreachable" }, { "package": "pkg:npm/minimist@1.2.5", "state": "unreachable" } ], "unlistedAdvisories": "patch" }The format reference is
docs/selection-filter.md: fields, value grammars, the rules with a worked table, how to read the result, errors, limits and integration recipes. Its JSON Schema isdocs/selection-filter.schema.json.Behavior
skip.pathsandskip.packagesleave project roots and packages alone, with the grammar of socket.yml'spatches.ignorePathsand of--package.unreachableneeds no fix;reachableandunknownneed one. An advisory no finding covers followsunlistedAdvisories:patch(default) orskip, which makes the findings an allowlist.--no-socket-ymldrops only the file.policy.filtered[]gainsfilter_path_skipped,filter_package_skippedandfilter_not_needed; a run given a filter echoes its digest and entry counts aspolicy.selectionFilter. Without a filter no output changes.error.code: filter_invalid.Only
scanreads the filter, in every mode. The in-memory engine behind the Node addon does not take one yet.Where the code is
crates/socket-patch-core/src/policy/filter.rs(new): the parser, validation and per-package judgement.policy/mod.rs:SelectionPolicy::with_filter, the path and package skips inadmits_root/admits_purl,judge_offers, andOffers.withheld.rollout/stage.rs:classifylets a recorded patch the filter withholds give way to the selection.scan/policy.rs:ScanPolicy::selectapplies the judgement beside the severity floor.scan/socket_yml_args.rsholds the hidden flag.Testing
e2e_socket_yml_policy.rsrun the real binary against a mock patch API: hosted, agent and vendored modes, merged patches, the single-advisory preference, the allowlist, path skips, fail-closed errors, and recorded-patch retention.-D warningsand rustfmt. The Docker and per-ecosystem build suites were not run locally.commands::apply::tests::cargo_patches_refuse_under_a_cargo_config_above_the_repositoryfailed once in a full local unit run and passed on every re-run. This PR does not touch it.Review
/code-review highran on the diff; the confirmed findings are fixed. Three were left as they are:select, not in core'sfloor_filter. The per-package judgement is in core (SelectionPolicy::judge_offers). The choice against a recorded patch stays inScanPolicy::select, where the severity floor's lives too. The in-memory engine cannot be handed a filter today, so nothing reaches the path that would ignore it. Wiring it in belongs with the change that gives the Node addon a filter.skip.pathscompile-and-report block resemblessocket_yml::check_patterns. That helper compiles a list and discards the matcher; the filter keeps it.🤖 Generated with Claude Code