Repository navigation
Description
[agent] Found by the architecture refactor routine (lead L179). main at d987721, and the released 5.1.0 (npm i @socketsecurity/socket-patch@5.1.0).
Problem
A manifest save keeps what this release does not own: "every top-level and per-record field it does not know" ([core manifest/operations.rs, write_manifest](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/manifest/operations.rs#L96-L121), [keep_unknown_fields](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/manifest/operations.rs#L147-L179)). That rule arrived with #2052 and shipped in 5.1.0. It stops at the record. A field the release does not know inside a file entry (files.<path>) or a vulnerability entry is dropped by the next command that saves the manifest.
The first field added since then went into a file entry: mode (#2433, 5.2.0; core manifest/schema.rs). So 5.1.0, which carries unknown fields at two levels, drops it. The contract states what follows for "a release that predates mode" (CLI_CONTRACT.md lines 216 to 224): the record "then reads as applied to every release, this one included". main has the same gap, so the next field a later release adds to a file entry is lost the same way by 5.2.x.
It hurts a project that two releases drive: CI pinned to one, a developer or a wrapper on another.
Evidence
1. The released 5.1.0, then main, on one project. An npm project with node_modules/left-pad/index.js at mode 0666, and a record whose one file entry fixes the permissions alone (beforeHash equal to afterHash, "mode": "0644"), beside a second record:
| Step | Output |
|---|---|
main: apply --check --offline |
"Patches are OUT OF SYNC: pkg:npm/left-pad@1.3.0: patch not applied (an installed copy is still unpatched)", exit 1 |
5.1.0: remove pkg:npm/other@1.0.0 --yes --skip-rollback --offline |
"Manifest updated", exit 0. The manifest's "mode" is gone |
main: apply --check --offline |
"Patches are in sync (1 patch checked).", exit 0 |
main: apply --offline |
"pkg:npm/left-pad@1.3.0 (already patched)", exit 0 |
main: vex -O v.json --offline |
one statement, not_affected |
stat -c %a node_modules/left-pad/index.js |
666 throughout |
2. main alone. A probe beside test_write_manifest_unknown_fields_follow_their_record (the diff is below) puts one unknown field at each of the four levels, removes the other record and saves:
assertion `left == right` failed: record-level, top-level, file-level, vulnerability-level fields kept
left: (1, 1, 0, 0)
right: (1, 1, 1, 1)
test result: FAILED. 28 passed; 1 failed
The same from the command line, for both releases: the project of step 1 with futureTop at the top of the manifest, futureField in the record and futureFileField in its file entry, then remove pkg:npm/other@1.0.0 --yes --skip-rollback --offline:
| After the save by | futureTop |
futureField |
futureFileField |
mode |
|---|---|---|---|---|
| 5.1.0 | kept | kept | dropped | dropped |
main |
kept | kept | dropped | kept |
Planned fix
Carry the unknown keys of a file entry and of a vulnerability entry through a save, by the record's own rule: the record is still the same patch (same uuid), the entry is still there under the same key, and the keys go back at the positions the file had them. test_known_keys_match_the_schema gets the two key lists, so a field added to the schema later cannot be mistaken for another writer's. About 30 production lines in core manifest/operations.rs. A manifest with no such field is written as today.
This cannot repair 5.1.0. It makes 5.2.x safe for the next per-file field.
A question that does not block the fix
A save by 5.1.0 leaves a trace: a file entry with equal hashes and no mode, which patches nothing. main reads it as applied (step 1). Should apply --check, apply and vex decline to call such an entry applied, and name the remedy the contract already gives (remove the record and download it again)? The contract documents today's answer, so that part needs a maintainer's word.
Not run
The vendored ledger (its header states its own rule for a newer writer's fields); a 5.0.x release; another writer of the manifest; Windows.
Reproduce
mkmode.py <dir>:
#!/usr/bin/env python3
"""mkmode.py <dir>: an npm project whose one agent-mode record fixes a file's
permissions alone (beforeHash == afterHash, "mode": "0644"), beside a second
record for a package that is not installed. The installed file is 0666."""
import hashlib, json, os, sys
root = sys.argv[1]
def gsha(b): return hashlib.sha256(b"blob %d\0" % len(b) + b).hexdigest()
body = b"module.exports = function leftPad(s, n) { return String(s).padStart(n); };\n"
os.makedirs(f"{root}/node_modules/left-pad", exist_ok=True)
os.makedirs(f"{root}/.socket/blobs", exist_ok=True)
open(f"{root}/package.json", "w").write(json.dumps({"name": "app", "version": "1.0.0", "dependencies": {"left-pad": "1.3.0"}}, indent=2) + "\n")
open(f"{root}/node_modules/left-pad/package.json", "w").write(json.dumps({"name": "left-pad", "version": "1.3.0", "main": "index.js"}, indent=2) + "\n")
p = f"{root}/node_modules/left-pad/index.js"
open(p, "wb").write(body); os.chmod(p, 0o666)
open(f"{root}/.socket/blobs/{gsha(body)}", "wb").write(body)
vuln = {"GHSA-aaaa-bbbb-cccc": {"cves": ["CVE-2026-0001"], "summary": "world-writable file", "severity": "high", "description": "d"}}
def rec(uuid, files): return {"uuid": uuid, "exportedAt": "2026-01-01T00:00:00Z", "files": files, "vulnerabilities": vuln, "description": "fix", "license": "MIT", "tier": "free"}
h = gsha(body)
manifest = {"patches": {
"pkg:npm/left-pad@1.3.0": rec("11111111-1111-4111-8111-111111111111", {"package/index.js": {"beforeHash": h, "afterHash": h, "mode": "0644"}}),
"pkg:npm/other@1.0.0": rec("22222222-2222-4222-8222-222222222222", {"package/x.js": {"beforeHash": h, "afterHash": gsha(body + b"x")}})}}
open(f"{root}/.socket/manifest.json", "w").write(json.dumps(manifest, indent=2) + "\n")python3 mkmode.py m && cd m
export SOCKET_TELEMETRY_DISABLED=1 SOCKET_NO_CONFIG=1 SOCKET_NO_UPDATE_CHECK=1
<main>/socket-patch apply --check --offline # exit 1, out of sync
<5.1.0>/socket-patch remove pkg:npm/other@1.0.0 --yes --skip-rollback --offline
grep -c '"mode"' .socket/manifest.json # 0
<main>/socket-patch apply --check --offline # exit 0, in sync
<main>/socket-patch vex -O v.json --offline # not_affected
stat -c %a node_modules/left-pad/index.js # 666The probe (cargo test -p socket-patch-core --lib manifest::operations::tests):
diff --git a/crates/socket-patch-core/src/manifest/operations.rs b/crates/socket-patch-core/src/manifest/operations.rs
index f76d287c..4ae61cbe 100644
--- a/crates/socket-patch-core/src/manifest/operations.rs
+++ b/crates/socket-patch-core/src/manifest/operations.rs
@@ -796,6 +796,41 @@ mod tests {
assert_eq!(written["futureTopLevel"], true);
}
+ /// Probe (not committed): a field this version does not know inside a
+ /// file entry, or inside a vulnerability entry, survives a rewrite that
+ /// keeps its record, as a record-level and a top-level one do.
+ #[tokio::test]
+ async fn zz_probe_unknown_fields_inside_a_file_entry_survive() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("manifest.json");
+ let mut doc: serde_json::Value =
+ serde_json::from_str(MANIFEST_WITH_UNKNOWN_FIELDS).unwrap();
+ let record = &mut doc["patches"]["pkg:npm/pkg-b@2.0.0"];
+ record["files"]["package/index.js"] = serde_json::json!({
+ "beforeHash": "a".repeat(64), "afterHash": "b".repeat(64),
+ "futureFileField": "another tool"
+ });
+ record["vulnerabilities"]["GHSA-aaaa-bbbb-cccc"] = serde_json::json!({
+ "cves": [], "summary": "s", "severity": "high", "description": "d",
+ "futureVulnField": "another tool"
+ });
+ let (files, vulns) = (1, 1);
+ tokio::fs::write(&path, serde_json::to_string_pretty(&doc).unwrap())
+ .await
+ .unwrap();
+
+ let mut manifest = read_manifest(&path).await.unwrap().unwrap();
+ manifest.patches.remove("pkg:npm/pkg-a@1.0.0");
+ write_manifest(&path, &manifest).await.unwrap();
+ let written = tokio::fs::read_to_string(&path).await.unwrap();
+ let kept = |key: &str| written.matches(key).count();
+ assert_eq!(
+ (kept("addedBy"), kept("futureTopLevel"), kept("futureFileField"), kept("futureVulnField")),
+ (1, 1, files, vulns),
+ "record-level, top-level, file-level, vulnerability-level fields kept"
+ );
+ }
+
/// A manifest without unknown fields is written exactly as the schema
/// serializes it (no trailing newline), whatever was on disk before.
#[tokio::test]Generated by Claude Code
Activity
refactor: L178, L179 filed as #2496, #2498 (PnP, manifest)
mikolalysenko commentedon Dec 4, 2026
[agent] The vendored ledger has the same gap, at every level, and one released pair already shows it.
mainat d987721.On
main..socket/vendor/state.jsonis saved from the typed model, and nothing carries what the model does not know. The ten projects oftests/vendor_ecosystem_fixtures, each vendored bymain, with one unknown field put at each level of the ledger, thenremove <first purl> --yes --offline(exit 0,success):artifactrecordAll ten ecosystems give the same six rows. The
versionnumber does not protect an older binary either: a ledger with"version": 99is read, edited and saved back as 99 bymainand by 5.1.0.5.1.0 and 5.2.0. 5.2.0 added
gemBuildsto a ledger entry: one record per platform gem (#2422). The project: the platform gem ofgem_vendor_platform_gems_fresh_checkout_bundle_install_and_revert(real Bundler 4.0.18, three platforms), vendored bymain, with two vendored npm packages in the same root.main:vendor --checkremove pkg:npm/alpha@1.0.0 --yes --offline(rollback <purl>does the same)success; the gem entry'sgemBuildsis gonemain:vendor --checkpkg:gem/sockplat@1.0.0?platform=ruby: committed artifact and wiring verified, andpatch has no vendored ledger entry(vendor_ledger_missing) for each of the three platform gemsmain:vexpkg:gem/sockplat@1.0.0-x86_64-linuxand so on) topkg:gem/sockplat@1.0.0?platform=ruby, a gem the lock does not hold; threevex_record_supersededwarningsmain:vendor --offlinevendor_service_offline_conflictfor each platform gemmain:vendorwith the patch servicegemBuildsback;GemfileandGemfile.lockuntouchedmain:vendor --revert,rollbackmain's own savemainruns thatremovegemBuildskept, the check passesSo this pair fails closed, and an online
vendorby 5.2.0 heals it until the next 5.1.0 save. No package loses its patch. What a team sees is a redvendor --checkwhose message names no cause, and a VEX document that names another product. 5.1.0's ownvendor --checkalready fails on such a project before any save, so the two releases do not share it quietly; itsremoveandrollback <purl>are the commands that succeed and strip the entry.For the fix. The same rule in the second store:
save_state/ledger_value(corevendor/state.rs) would carry the unknown keys of the top level, of an entry, of itsartifact, of each wiring record, of the embeddedrecordand of its file entries, for the entries that stay. One carrier for the manifest and the ledger would keep the two from drifting again. The ledger's header promises that an older binary can read a newer ledger (lines 21 to 27) and says nothing of saving one.Generated by Claude Code
refactor: L184 filed as #2501 (NuGet undo), L185 on #2498