socket.yml and the selection filter refuse a scoped npm purl that scan --package accepts
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 76/100
Rechercherichtung
Start with package_spec_error in crates/socket-patch-core/src/policy/socket_yml.rs and compare its purl parsing with package_spec_matches in crates/socket-patch-core/src/policy/mod.rs; then read spec_error in policy/filter.rs. Update the shared parsing behavior and the named package_specs, schema parity, and e2e_socket_yml_policy.rs tests. Done means both unencoded scoped purls are accepted consistently while empty scoped names remain rejected.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
[agent] Found by the architecture refactor routine on main at cfc870f. Kind: two implementations of the --package grammar that disagree.
Problem
socket.yml (patches.packages, patches.ignorePackages) and the selection filter (skip.packages, reachability[].package) refuse the purl of a scoped npm package written the way socket-patch prints it: pkg:npm/@babel/core or pkg:npm/@babel/[email protected]. The whole scan fails, in every mode and on a dry run, with socket_yml_invalid (exit 1) or filter_invalid (exit 2). The message is "purl spec needs a type and a name", for a spec that has both. scan --package takes the same spec and selects the package.
CLI_CONTRACT.md says the three share one grammar:
- socket.yml patch policy: "Package specs are exactly
--package's: a name … or a purl with or without a version". - Selection filter: "
skip.packagesand a finding'spackageuse the--packagegrammar". - Target grammar: "the same matcher as
scan --packageandsocket.yml".
The unencoded spelling is the one every command prints (the scan table, packages[].purl, policy.filtered[].purl, the manifest keys). It is also the one the ambiguous_target message tells the user to type: "core" is ambiguous: it names pkg:npm/@angular/core, pkg:npm/@babel/core; use the full name or a purl.
Who it hurts. Anyone who allows or ignores a scoped npm package by purl, which the contract recommends over a bare name ("so prefer purls"). The run fails closed, so nothing is patched against the policy. The cost is a failed scan (a red CI job) and an error that points at the wrong thing. pkg:npm/%40babel/core and the bare name @babel/core work today.
Evidence on main
A project with node_modules/@babel/core at 7.0.0 and four other packages, and a local stand-in for the patch API that offers one patch for each. The binary is built from cfc870f.
The flag takes the spec:
$ socket-patch scan --mode agent --dry-run --package pkg:npm/@babel/[email protected]
…
[dry-run] Would download and apply 1 patch. No changes made.
MODERATE @babel/[email protected] CVE-2026-0005
…
(exit 0)
socket.yml refuses it:
$ cat socket.yml
version: 2
patches:
ignorePackages:
- pkg:npm/@babel/[email protected]
$ socket-patch scan --mode agent --dry-run
Error (socket_yml_invalid): socket.yml: patches.ignorePackages[0]: purl spec needs a type and a name (`pkg:npm/lodash`): `pkg:npm/@babel/[email protected]` (fix the file, or pass --no-socket-yml to ignore it)
(exit 1)
So does the selection filter:
$ cat filter.json
{"version": 1, "skip": {"packages": ["pkg:npm/@babel/[email protected]"]}}
$ socket-patch scan --mode agent --dry-run --selection-filter filter.json
Error: selection filter filter.json: skip.packages[0]: purl spec needs a type and a name (`pkg:npm/lodash`): `pkg:npm/@babel/[email protected]`
(exit 2)
The same spec in each place, with and without a version:
| Spec | scan --package |
patches.ignorePackages / patches.packages |
skip.packages / reachability[].package |
|---|---|---|---|
pkg:npm/@babel/[email protected] |
selects the package | socket_yml_invalid, exit 1 |
filter_invalid, exit 2 |
pkg:npm/@babel/core |
selects the package | socket_yml_invalid, exit 1 |
filter_invalid, exit 2 |
pkg:npm/%40babel/[email protected] |
selects the package | honored | honored |
@babel/core |
selects the package | honored | honored |
Hosted mode gives the same result: on a hosted npm project with 24 patches, four of them for scoped packages, ignorePackages: ["pkg:npm/@aninhe925/[email protected]"] fails the scan with socket_yml_invalid and changes no file, and --package with that spec pins that one package.
The selection filter's JSON Schema (docs/selection-filter.schema.json, packageSpec) accepts both unencoded spellings, so the schema and the parser disagree too.
A unit test that feeds one spec to both functions fails on main:
// crates/socket-patch-core/src/policy/socket_yml.rs, mod tests
#[test]
fn probe_scoped_npm_purl_matcher_vs_validator() {
for spec in ["pkg:npm/@babel/core", "pkg:npm/@babel/[email protected]"] {
assert!(
crate::policy::package_spec_matches(spec, "pkg:npm/@babel/[email protected]"),
"the matcher takes {spec}"
);
assert_eq!(package_spec_error(spec), None, "the validator refuses {spec}");
}
}
$ cargo test -p socket-patch-core --lib probe_scoped_npm_purl
assertion `left == right` failed: the validator refuses pkg:npm/@babel/core
left: Some("purl spec needs a type and a name (`pkg:npm/lodash`)")
right: None
test result: FAILED. 0 passed; 1 failed
Cause
package_spec_error in crates/socket-patch-core/src/policy/socket_yml.rs (line 484) accepts a purl spec only when, at line 495:
!ty.is_empty() && !name.trim_matches('/').is_empty() && !name.starts_with('@')
starts_with('@') is there to refuse pkg:npm/@1.0.0, an empty name with a version (the package_specs test pins that, line 1285). It refuses every npm scope with it.
The matcher, package_spec_matches in crates/socket-patch-core/src/policy/mod.rs (line 841), finds the version at the last @ after the first character, so it reads pkg:npm/@babel/[email protected] as the name @babel/core at 7.0.0. --package goes to the matcher with no validator in front of it. The selection filter's spec_error (policy/filter.rs, line 318) calls package_spec_error. The test that keeps the schema and the parser in step has no unencoded scoped purl in its table.
Planned fix
- Give the validator the matcher's reading of a purl spec: one function that splits a spec into type, name and version, used by
package_spec_matchesandpackage_spec_error, so a spec is valid exactly when the matcher can match it. - Keep refusing what can never match:
pkg:npm/@1.0.0(no name), and a scope with no name after it (pkg:npm/@babel). - Add both scoped spellings to the
package_specstest, to the schema parity table inpolicy/filter.rs, and one case toe2e_socket_yml_policy.rs.
No JSON shape, flag, default or exit code changes. Two inputs that are errors today become what the contract says they are.
Not run: the in-memory engine, which reads socket.yml through the same parser. get reads the file only for its policy_bypassed warning, so with such a file it drops the warning and still succeeds.
Generated by Claude Code
- Vorherrschende Sprache
- Rust
- Sterne
- 9
- Forks
- 2
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 313
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
SocketDev/socket-patch#2306 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit bug priority:p3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
SocketDev/socket-patch#2296 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:needs-human agent:triaged ci-janitor priority:p1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
SocketDev/socket-patch#2270 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit bug priority:p1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
SocketDev/socket-patch#2259 ·
Maintainer antworten meist innerhalb von 1 Tag
-
agent:triaged arch-audit priority:p3 refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
SocketDev/socket-patch#1860 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in SocketDev/socket-patch
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
storytold/craft-launcher#1671 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 63/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100