socket.yml and the selection filter refuse a scoped npm purl that scan --package accepts
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
[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
- 主要語言
- Rust
- 星號
- 9
- 分支
- 2
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 313
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SocketDev/socket-patch 的其他 Issue
-
agent:triaged arch-audit bug priority:p2
難度 2/5 1-3 小時 新手友好度 84/100
SocketDev/socket-patch#2306 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p3
難度 2/5 1-3 小時 新手友好度 88/100
SocketDev/socket-patch#2296 ·
維護者通常 1 天內回覆
-
agent:needs-human agent:triaged ci-janitor priority:p1
難度 2/5 1-3 小時 新手友好度 72/100
SocketDev/socket-patch#2270 · 3 則留言 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p1
難度 2/5 1-3 小時 新手友好度 82/100
SocketDev/socket-patch#2259 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit priority:p3 refactor
難度 2/5 1-3 小時 新手友好度 83/100
SocketDev/socket-patch#1860 ·
維護者通常 1 天內回覆
查看 SocketDev/socket-patch 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
storytold/craft-launcher#1671 ·
維護者通常 1 天內回覆
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)未關閉
難度 2/5 1-3 小時 新手友好度 63/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 76/100