Skip to content

Commit 03aed58

Browse files
committed
Merge release/v5-prerelease (lockfile models)
Brings in WS3 (#281, one lockfile model per ecosystem). It merges cleanly with the rollout; scan, rollout, policy and memory suites pass unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2 parents 47d218f + 73c0c4f commit 03aed58

63 files changed

Lines changed: 4532 additions & 3386 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎crates/socket-patch-cli/src/commands/get.rs‎

Lines changed: 8 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use socket_patch_core::api::types::{
1111
};
1212
use socket_patch_core::crawlers::fuzzy_match::fuzzy_match_packages;
1313
use socket_patch_core::crawlers::{CrawlerOptions, Ecosystem};
14+
use socket_patch_core::formats::pnpm::PnpmLock;
1415
use socket_patch_core::manifest::operations::{read_manifest, write_manifest};
1516
use socket_patch_core::manifest::schema::{
1617
PatchFileInfo, PatchManifest, PatchRecord, VulnerabilityInfo,
@@ -1498,47 +1499,6 @@ fn purl_has_version(purl: &str) -> bool {
14981499
})
14991500
}
15001501

1501-
/// Does the raw pnpm-lock text RESOLVE `name@version`? Boundary-anchored
1502-
/// probes over the three lock grammars — a plain `contains` collides on
1503-
/// version prefixes (`left-pad@1.3.0` matches inside
1504-
/// `left-pad@1.3.0-beta.1`), name suffixes (`pad@1.3.0` inside
1505-
/// `left-pad@1.3.0`), and unscoped-inside-scoped names (`name@1.0.0` inside
1506-
/// `@scope/name@1.0.0`). The needles cover v6/v9's `name@version` and v5's
1507-
/// `/name/version` key spellings; a match counts only when the preceding
1508-
/// char cannot extend the name (start/whitespace/quote, or a `/` delimiter
1509-
/// itself preceded by such a boundary) and the following char cannot extend
1510-
/// the version (so `:`, `'`, `(`, and v5's `_peer` suffix all accept).
1511-
/// Heuristic by design: a false negative degrades to a calm skip, a false
1512-
/// positive costs one grant request the rewriter's per-dep confirmation
1513-
/// then ignores.
1514-
fn pnpm_lock_resolves(text: &str, name: &str, version: &str) -> bool {
1515-
let version_boundary = |c: char| !(c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | '+'));
1516-
let name_boundary = |c: char| matches!(c, ' ' | '\t' | '\n' | '\r' | '\'' | '"');
1517-
for needle in [format!("{name}@{version}"), format!("/{name}/{version}")] {
1518-
for (pos, _) in text.match_indices(needle.as_str()) {
1519-
let before_ok = match text[..pos].chars().next_back() {
1520-
None => true,
1521-
// v5/v6's leading key delimiter — legitimate only when the
1522-
// char before it is itself a boundary (otherwise this is a
1523-
// scoped `@scope/<name>` tail: a DIFFERENT package).
1524-
Some('/') => text[..pos - 1]
1525-
.chars()
1526-
.next_back()
1527-
.is_none_or(name_boundary),
1528-
Some(c) => name_boundary(c),
1529-
};
1530-
let after_ok = text[pos + needle.len()..]
1531-
.chars()
1532-
.next()
1533-
.is_none_or(version_boundary);
1534-
if before_ok && after_ok {
1535-
return true;
1536-
}
1537-
}
1538-
}
1539-
false
1540-
}
1541-
15421502
/// Outcome of the coarse installed-VERSION narrowing over a CVE/GHSA/PURL
15431503
/// search fan-out (see [`filter_to_installed_purls`]).
15441504
struct InstalledNarrowing {
@@ -1576,7 +1536,7 @@ struct InstalledNarrowing {
15761536
/// `yarn_pnp_unsupported`, not a false "not installed"). pnpm PnP skips
15771537
/// carry `pnpm_pnp_unsupported` in agent/vendored modes; hosted mode — the
15781538
/// refusal's own remedy — keeps the versions the raw pnpm-lock.yaml text
1579-
/// resolves ([`pnpm_lock_resolves`]), labels a judged miss
1539+
/// resolves ([`PnpmLock::resolves`]), labels a judged miss
15801540
/// `package_not_installed` like any other mode, and reserves the layout
15811541
/// code for an unreadable lock (no judgment possible).
15821542
///
@@ -1645,6 +1605,7 @@ async fn filter_to_installed_purls(
16451605
let pnpm_pnp_lock_text: Option<String> = (pnp_pnpm && mode == super::scan::ScanMode::Hosted)
16461606
.then(|| std::fs::read_to_string(common.cwd.join("pnpm-lock.yaml")).ok())
16471607
.flatten();
1608+
let pnpm_pnp_lock = pnpm_pnp_lock_text.as_deref().map(PnpmLock::parse);
16481609

16491610
let mut out = InstalledNarrowing {
16501611
kept: Vec::new(),
@@ -1674,8 +1635,8 @@ async fn filter_to_installed_purls(
16741635
// The pnpm PnP refusal's own remedy is the hosted lockfile
16751636
// rewrite — but only for versions the lock ACTUALLY resolves:
16761637
// keeping the whole fan-out would request grants for every
1677-
// version ever patched. Anchored probe over the raw lock text
1678-
// (see `pnpm_lock_resolves`); a hit is kept (the rewriter's
1638+
// version ever patched. The lock model's key probe
1639+
// (`PnpmLock::resolves`); a hit is kept (the rewriter's
16791640
// per-dep confirmation still decides). A judged MISS is a
16801641
// genuine "version not resolved" verdict — the layout blocked
16811642
// nothing — so it carries the same `package_not_installed` code
@@ -1684,9 +1645,9 @@ async fn filter_to_installed_purls(
16841645
let decoded = canon(&result.purl);
16851646
let coord = decoded.strip_prefix("pkg:npm/").unwrap_or(&decoded);
16861647
if mode == super::scan::ScanMode::Hosted {
1687-
match (pnpm_pnp_lock_text.as_deref(), coord.rsplit_once('@')) {
1688-
(Some(text), Some((name, version))) => {
1689-
if pnpm_lock_resolves(text, name, version) {
1648+
match (&pnpm_pnp_lock, coord.rsplit_once('@')) {
1649+
(Some(lock), Some((name, version))) => {
1650+
if lock.resolves(name, version) {
16901651
out.kept.push(result.clone());
16911652
continue;
16921653
}
@@ -3987,77 +3948,6 @@ pub(crate) fn base64_decode(input: &str) -> Result<Vec<u8>, String> {
39873948
mod tests {
39883949
use super::*;
39893950

3990-
/// The pnpm-PnP hosted lock probe must be boundary-anchored: plain
3991-
/// substring matching collides on version prefixes, name suffixes, and
3992-
/// unscoped-inside-scoped names.
3993-
#[test]
3994-
fn pnpm_lock_resolves_is_boundary_anchored() {
3995-
// v9/v6/v5 key spellings all resolve.
3996-
assert!(pnpm_lock_resolves(
3997-
"lockfileVersion: '9.0'\n\nsnapshots:\n\n left-pad@1.3.0:\n",
3998-
"left-pad",
3999-
"1.3.0"
4000-
));
4001-
assert!(pnpm_lock_resolves(
4002-
" /left-pad@1.3.0:\n resolution: {}\n",
4003-
"left-pad",
4004-
"1.3.0"
4005-
));
4006-
assert!(pnpm_lock_resolves(
4007-
" /left-pad/1.3.0:\n resolution: {}\n",
4008-
"left-pad",
4009-
"1.3.0"
4010-
));
4011-
// Peer-qualified keys still resolve: v9 `(peer)` and v5 `_peer`.
4012-
assert!(pnpm_lock_resolves(
4013-
" 'left-pad@1.3.0(react@18.0.0)':\n",
4014-
"left-pad",
4015-
"1.3.0"
4016-
));
4017-
assert!(pnpm_lock_resolves(
4018-
" /left-pad/1.3.0_react@18.0.0:\n",
4019-
"left-pad",
4020-
"1.3.0"
4021-
));
4022-
// Scoped names resolve in both quoted-v9 and v6 spellings.
4023-
assert!(pnpm_lock_resolves(
4024-
" '@scope/name@1.0.0':\n",
4025-
"@scope/name",
4026-
"1.0.0"
4027-
));
4028-
assert!(pnpm_lock_resolves(
4029-
" /@scope/name@1.0.0:\n",
4030-
"@scope/name",
4031-
"1.0.0"
4032-
));
4033-
4034-
// Version-prefix collision: 1.3.0 must NOT match 1.3.0-beta.1.
4035-
assert!(!pnpm_lock_resolves(
4036-
" left-pad@1.3.0-beta.1:\n",
4037-
"left-pad",
4038-
"1.3.0"
4039-
));
4040-
// Name-suffix collision: `pad` must NOT match inside `left-pad`.
4041-
assert!(!pnpm_lock_resolves(" left-pad@1.3.0:\n", "pad", "1.3.0"));
4042-
assert!(!pnpm_lock_resolves(" /left-pad/1.3.0:\n", "pad", "1.3.0"));
4043-
// Unscoped-inside-scoped: `name` must NOT match `@scope/name`.
4044-
assert!(!pnpm_lock_resolves(
4045-
" '@scope/name@1.0.0':\n",
4046-
"name",
4047-
"1.0.0"
4048-
));
4049-
assert!(!pnpm_lock_resolves(
4050-
" /@scope/name@1.0.0:\n",
4051-
"name",
4052-
"1.0.0"
4053-
));
4054-
// Absent version: never resolves.
4055-
assert!(!pnpm_lock_resolves(
4056-
" left-pad@1.3.0:\n",
4057-
"left-pad",
4058-
"2.0.0"
4059-
));
4060-
}
40613951
use socket_patch_core::api::types::{PatchFileResponse, VulnerabilityResponse};
40623952
use std::collections::HashMap;
40633953

@@ -5036,36 +4926,6 @@ mod tests {
50364926
);
50374927
}
50384928

5039-
// --- pnpm_lock_resolves: needle at byte 0 ------------------------------
5040-
// The boundary probe reads the char BEFORE the match; a match at the very
5041-
// start of the text has none (`None => true`). A regression that indexes
5042-
// `text[..pos - 1]` unconditionally would underflow/panic here.
5043-
5044-
#[test]
5045-
fn pnpm_lock_resolves_needle_at_start_of_text() {
5046-
// pos == 0, plain v9 spelling: no preceding char is a valid boundary.
5047-
assert!(pnpm_lock_resolves("left-pad@1.3.0:\n", "left-pad", "1.3.0"));
5048-
// pos == 0, v5/v6 `/name/version` and `/name@version` spellings: the
5049-
// leading `/` delimiter itself has nothing before it.
5050-
assert!(pnpm_lock_resolves(
5051-
"/left-pad/1.3.0:\n",
5052-
"left-pad",
5053-
"1.3.0"
5054-
));
5055-
assert!(pnpm_lock_resolves(
5056-
"/left-pad@1.3.0:\n",
5057-
"left-pad",
5058-
"1.3.0"
5059-
));
5060-
// Still boundary-checked at the start of text: a scoped tail whose
5061-
// name begins mid-token must NOT match.
5062-
assert!(!pnpm_lock_resolves(
5063-
"@scope/left-pad@1.3.0:\n",
5064-
"left-pad",
5065-
"1.3.0"
5066-
));
5067-
}
5068-
50694929
// --- write_all_patch_blobs ---------------------------------------------
50704930
// The per-patch fan-out over write_blob_entry: the FIRST bad entry must
50714931
// fail the whole patch (Err(())) and leave nothing outside the blobs

0 commit comments

Comments
 (0)