socket.yml and the selection filter refuse a scoped npm purl that scan --package accepts

オープン
#2,294 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend, cli

調査の方向性

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:triaged arch-audit bug priority:p1

[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.packages and a finding's package use the --package grammar".
  • Target grammar: "the same matcher as scan --package and socket.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_matches and package_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_specs test, to the schema parity table in policy/filter.rs, and one case to e2e_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時間
マージ済み PR(30日)
313

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SocketDev/socket-patch のほかの issue

SocketDev/socket-patch の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。