Skip to content

Stop verifying and attesting a vendored NuGet package whose lock pins other bytes - #2453

Open
Mikola Lysenko (mikolalysenko) wants to merge 9 commits into
mainfrom
arch-refactor/2381-nuget-lock-pin
Open

Mikola Lysenko (mikolalysenko) wants to merge 9 commits into
mainfrom
arch-refactor/2381-nuget-lock-pin

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2381.

Problem

A vendored NuGet package keeps its id and version, so NuGet's global packages folder (~/.nuget/packages) can already hold the upstream package, and NuGet restores from that folder before it asks any source. The only thing that ties a restore to the vendored nupkg is the contentHash in packages.lock.json, which vendor pins.

On a machine with the upstream copy in that folder, the next dotnet restore fails NU1403. NuGet's own remedy is dotnet restore --force-evaluate. It succeeds: NuGet takes the upstream copy, never opens the vendored feed, and writes the upstream contentHash back into the lock. From then on every restore passes, --locked-mode included, the build loads the upstream assembly, and:

  • socket-patch vendor --check exits 0, "committed artifact and wiring verified";
  • socket-patch vex attests not_affected;
  • socket-patch vendor --dry-run says "already vendored; nothing to do".

nuget.config still maps the id to the vendored feed and the nupkg is intact, so one hash line is all that changed. The machine that ran vendor is such a machine (it restored the project before), and so is a CI runner that restores a cached global packages folder.

The writer has the rule: a wet vendor treats a lock that pins other bytes as out of sync and pins it again. The two commands whose job is to check never read the pin. The same hole was closed for Bun's lock, and for Bun's lock only.

Evidence on main

The real .NET SDK 8 (mcr.microsoft.com/dotnet/sdk:8.0, no network), a library packed with dotnet pack into a folder feed, an app with RestorePackagesWithLockFile, and a patch that replaces the library's assembly. The binary is the one built from main at 6eb4eb9:

$ dotnet restore && dotnet run
app loads Fx.Alpha: UPSTREAM (vulnerable)
$ socket-patch vendor                              # exit 0, pins the lock, warns of the global copy
$ dotnet restore
app/app.csproj : error NU1403: Package content hash validation failed for Fx.Alpha.1.0.0. The package is different than the last restore.
$ dotnet restore --force-evaluate
  Restored app/app.csproj (in 165 ms).             # the lock holds the upstream contentHash again
$ dotnet restore --locked-mode && dotnet run
  Restored app/app.csproj (in 235 ms).
app loads Fx.Alpha: UPSTREAM (vulnerable)

$ socket-patch vendor --check                      # main
pkg:nuget/Fx.Alpha@1.0.0: committed artifact and wiring verified
[exit 0]
$ socket-patch vex --product pkg:nuget/app@1.0.0   # main
Warning: pkg:nuget/Fx.Alpha@1.0.0: the installed tree does not match its vendored artifact; […] re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement            # "status": "not_affected"
[exit 0]
$ socket-patch vendor --dry-run                    # main
1 package is already vendored; nothing to do.

A CLI test, red on main and green here. It vendors the NuGet fixture, puts the upstream pins back as --force-evaluate does, and runs vendor --check and vex:

test vendor_nuget_lock_pin::nuget_lock_pinned_to_other_bytes_is_not_verified ... FAILED
(vendor --check exit code, not_affected statements)
  left: (0, 2)
 right: (1, 0)

The fix

One rule, the writer's: a vendored NuGet package is wired only while every lock a project under the root restores into, and that locks the id at the patched version, pins the vendored nupkg's contentHash.

  • vendor::nuget_feed::lock_pin_mismatch reads the pin the way the writer's in-sync check does: the same locks (governed_locks_on_disk), the same entries (locked_at: id without regard to case, version normalized), the same tolerance (an entry with no hash, or no entry at that version, pins nothing).
  • vex (core vex/verify.rs) omits the patch with vendor_lock_pin_mismatch, the code Bun's lock already has.
  • vendor --check fails the package, names the lock and the artifact, and says what to do. The pin is judged after the liveness rule, on a package that is wired.
  • vendor --dry-run counts the package as one it would vendor. Its tell for "in sync" was the ledger recording the patch. NuGet's backend reports an in-sync package as already_vendored on a dry run too, so a verified preview of a NuGet package is always one the wet run writes, and the tally says so.
  • The wet vendor that pins the lock again now says so ("a lock pinned … to other bytes than the committed vendored nupkg's"), where it said the nupkg "was missing or stale". It also names the copy in the global packages folder (vendor_nuget_stale_global_package). The first vendor and an in-sync re-run raised that warning; the run that follows a --force-evaluate did not, so the lock was pinned again and the next restore failed NU1403 once more.
  • vex's sentence for vendor_lock_pin_mismatch says "artifact" where it said "tarball".

The same tree, the binary built from this branch (at 01383ce; the remedy sentence is the head's):

$ socket-patch vendor --check
pkg:nuget/Fx.Alpha@1.0.0: packages.lock.json pins Fx.Alpha 1.0.0 to a contentHash that is not the sha512 of .socket/vendor/nuget/11111111-…/fx.alpha.1.0.0.nupkg, so `dotnet restore` does not restore the vendored package (it takes a copy with the pinned hash from NuGet's global packages folder, or fails NU1403); re-run `socket-patch scan --mode vendored` (or `socket-patch vendor`, where the project has a .socket/manifest.json) to pin the lock again, then delete the directory in the global packages folder that the run's warning names
[exit 1]
$ socket-patch vex --product pkg:nuget/app@1.0.0
Warning: omitting pkg:nuget/Fx.Alpha@1.0.0 from VEX: the lockfile pins the vendored artifact to a sha512 that is not that file's, so an install does not deliver it; re-run socket-patch scan --mode vendored (vendor_lock_pin_mismatch)
Error: No applied patches with vulnerability metadata to attest.
[exit 1]
$ socket-patch vendor --dry-run
Would vendor 1 package.

$ socket-patch vendor                              # the remedy
Warning: a lock pinned Fx.Alpha@1.0.0 to other bytes than the committed vendored nupkg's; rebuilt at .socket/vendor/nuget/11111111-…/fx.alpha.1.0.0.nupkg and pinned again (nuget.config untouched)
Warning: Fx.Alpha 1.0.0 is now served by the vendored feed, but NuGet's global packages folder already holds the UNPATCHED copy at nuget-packages/fx.alpha/1.0.0 […] Delete that directory […]
Vendored 1 package.
$ rm -r nuget-packages/fx.alpha/1.0.0 && dotnet restore --locked-mode && dotnet run
  Restored app/app.csproj (in 200 ms).
app loads Fx.Alpha: PATCHED
$ socket-patch vendor --check
pkg:nuget/Fx.Alpha@1.0.0: committed artifact and wiring verified
[exit 0]
$ socket-patch vex --product pkg:nuget/app@1.0.0
Wrote OpenVEX document with 1 statement            # "status": "not_affected"
$ socket-patch vendor --dry-run
1 package is already vendored; nothing to do.

Tests

  • tests/vendor/vendor_nuget_lock_pin.rs, four CLI tests over the vendored NuGet fixture:
    • the control: the lock vendor wrote is verified and attested, and a dry run has nothing to do;
    • every pin put back: both packages fail the check, none is attested, the dry run would vendor two, the wet run pins the lock again and names the global copy, after which both commands pass;
    • one pin put back: only that package fails and loses its statement;
    • the config put back, then the lock too: the check says "wiring missing" and vex says vendor_unwired, never the pin's text, and the dry run would vendor two.
  • Six unit tests beside the writer's: the rule row by row (no lock, pinned, the upstream pin, one framework of two, another letter case and version spelling); the states the writer tolerates; a second project's lock; an artifact path that leaves the root (it fails with the guard removed); the shared predicate; and the re-run over a stale pin.

What the review found

An independent review by a subagent given the diff and the issue: /code-review high, then its own probes in a separate worktree. Each finding was run unless marked read.

Finding Outcome
The remedy named socket-patch vendor first. In a project with no manifest (what scan --mode vendored leaves) that command does nothing: exit 0, "No manifest to vendor from", the lock unchanged. Fixed: the text leads with socket-patch scan --mode vendored, whose wet run goes through the same backend.
vendor --check ran the pin check before the liveness rule. With the config and the lock both put back it printed the pin's text where vex said vendor_unwired. Fixed: the pin is judged after liveness. A CLI test holds the two commands to one answer.
The dry-run tally asked the pin check for every NuGet package, and still said "already vendored" with the config put back and the lock pinned. Fixed with the smaller rule the reviewer proposed (above), which reads nothing.
pin_stale was wider than the check: an entry with no hash beside one pinned at the nupkg made the wet run say "a lock pinned … to other bytes". Fixed: the prelude and the check share pins_other_bytes.
lock_pin_mismatch hashed whatever entry.artifact.path named, ../../etc/passwd included. Its callers validate the path first. Guarded in the function as well. A dead ./ trim is gone.
tests/vendor/main.rs loads prebuilt_common twice. Marked #[allow(clippy::duplicate_mod)], as the other suites do.
vex --no-verify still attests over a stale pin, for NuGet as for Bun on main. I ran it again on the real-SDK tree. Not fixed here. The contract calls a pin mismatch a wiring failure and says the wiring gates apply under --no-verify, so it is a defect; the fix moves the pin into the wiring gates for both ecosystems. Filed as #2455.
The run that pins the lock again asks the patch service for the nupkg, though the committed one is intact: SOCKET_OFFLINE=1 socket-patch vendor exits 1 and the lock stays stale. Run again on the real-SDK tree. Not fixed here: it is how that path worked before, and pinning from the committed nupkg needs a word on the warning code. In #2455.
scan --mode vendored --dry-run and get --mode vendored --dry-run preview from the ledger's uuid alone (read). Not fixed here. In #2455, as not run.
One lock whose frameworks pin different hashes: the re-run fails on "conflicting contentHash values". dotnet does not write such a lock. Not fixed. With the new order vendor --check reports that lock through the liveness rule, as on main. In #2455.
The contract still says "vendor_lock_pin_mismatch (bun)" (read). Not fixed here: see below.

A second, shorter pass on the fixes (read only) found the production change sound and three assertions that could not fail for their reason: the row for a path that leaves the root, the dry-run state of the unwired test, and nothing on the shared predicate. All three are fixed; the first was checked by removing the guard.

Deleted

Two inline copies of the stale-global-package warning; the three paths that raise it share stale_global_package.

Behavior change

For a vendored NuGet package whose lock pins a contentHash that is not the committed nupkg's:

  • vendor --check exits 1 for it (was 0, "verified").
  • vex omits it with vendor_lock_pin_mismatch (was not_affected). The contract names that code for Bun; it now covers NuGet's lock too.
  • vendor --dry-run says "Would vendor N packages" (was "already vendored; nothing to do"). Its JSON events are unchanged.
  • The wet vendor words its vendor_artifact_rebuilt warning differently and adds vendor_nuget_stale_global_package when the global folder holds other bytes.

For Bun, the sentence vex prints for vendor_lock_pin_mismatch says "artifact" where it said "tarball". No JSON shape, flag, code or exit-code meaning is new.

Risk

A project whose lock legitimately pins other bytes than the vendored nupkg would now fail vendor --check. I know of no such state: the writer already calls it out of sync and rewrites the pin on every wet run, and under it NuGet either restores another copy or fails NU1403. The check reads the project tree for its project files once per vendored NuGet package, as the writer does.

Not in this PR

Verification

Local, on ca76141 (this branch with main at 2440352 merged in):

  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • Core: 8,997 unit tests passed, 0 failed. CLI: 1,105 unit tests passed.
  • Seventeen CLI suites, 1,175 passed: vendor, e2e_vex_vendor, vex, e2e_nuget, vendor_revert_tamper_e2e, vendor_ledger_schema_e2e, vendor_group_commit_e2e, in_process_vendor, cli, vendor_eject, scan_vendor_e2e, vendor_crash_safety_e2e, vendor_partial_staging_e2e, e2e_vex, e2e_vex_lockfile, in_process_rollback_vendored and repair. Two tests of repair failed: repair_cleanup_failure_is_reported_in_json_and_silent_modes and repair_exits_zero_and_stays_quiet_when_lock_file_unremovable. Both make a file unwritable with chmod, which does not stop root, the user this sandbox runs as; they pass in CI.

On the head (2e5af57, tests only since): the 136 unit tests of vendor::nuget_feed and the 162 tests of the vendor suite.

The real .NET SDK 8 for the transcripts above. SDK 10, Windows, macOS and the Docker suites were not run here. No cfg(windows) or cfg(unix) code changed.

CI on 2e5af57 at 16:41Z: 54 checks pass, 71 are skipped (45 of them by a run that the push started while the PR was a draft, the rest by path), none failed.

Cursor Bugbot reviewed 2e5af57 and raised one finding (medium): the pin check takes an unreadable lock for "no mismatch". Not changed: run, the state does not pass. A symlinked lock is read through the link, and a lock that is not UTF-8 or not a regular file fails the liveness rule first (vendor --check exits 1 with "wiring missing", vex omits with vendor_unwired), because discovery calls every governed lock it cannot read unusable and the pin is judged only on a package that rule calls wired. The three runs are on its thread, which is resolved.

git diff --stat: 6 files, +645 −53. Production +171 −53 (vendor/nuget_feed.rs, vex/verify.rs, CLI commands/vendor.rs, commands/vex.rs). Tests +474 −0.


Generated by Claude Code

Refs #2381.

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Dec 2, 2026
A vendored NuGet package keeps its id and version, so the
`contentHash` in `packages.lock.json` is all that tells it from the
upstream package in NuGet's global packages folder, which NuGet
restores from before it asks any source. `vendor` pins that hash to
the vendored nupkg. `dotnet restore --force-evaluate` over a folder
that holds the upstream package, NuGet's remedy for the NU1403 the
pin raises there, writes the upstream hash back. Every later restore
then takes the upstream package, `--locked-mode` included.

`vex` attested such a package `not_affected`: it read the pin for
Bun's lock only. `nuget_feed::lock_pin_mismatch` reads it the way the
writer's in-sync check does, over every lock a project under the root
restores into, and `vex` omits the patch with
`vendor_lock_pin_mismatch` when an entry of the patched version pins
a hash that is not the committed nupkg's.

Refs #2381.

Assisted-by: Claude Code
`vendor --check` reported "committed artifact and wiring verified"
for a vendored NuGet package whose lock pins the upstream
`contentHash` again: the config still maps the id to the vendored
feed, and nothing compared the pin. It now fails that package, names
the lock, and says how to pin it again.

The CLI tests vendor the NuGet fixture, put the upstream pins back as
`dotnet restore --force-evaluate` does, and run `vendor --check` and
`vex`: both packages fail and none is attested, one stale entry fails
its own package only, and a wet `vendor` pins the lock again, after
which both commands pass.

Refs #2381.

Assisted-by: Claude Code
Over a vendored NuGet package whose lock pins other bytes, `vendor
--dry-run` said "already vendored; nothing to do" where the wet run
pins the lock again, and the wet run explained itself with "the
committed vendored nupkg was missing or stale", which it was not.

The dry run counts such a package as one it would vendor: the ledger
recording the patch is its tell for "in sync", and the lock pin is
the one thing the ledger does not tell. The wet run's
`vendor_artifact_rebuilt` warning says a lock pinned other bytes and
was pinned again.

Refs #2381.

Assisted-by: Claude Code
The warning that NuGet's global packages folder holds the upstream
copy of a vendored package (`vendor_nuget_stale_global_package`) was
raised by the first vendor and by an in-sync re-run, and not by the
run that rebuilds a wired package. That is the run which follows a
`dotnet restore --force-evaluate`: it pinned the lock again and left
the copy that made NuGet rewrite it unnamed, so the next restore
failed NU1403 once more.

The three paths raise the warning through one helper,
`stale_global_package`.

Refs #2381.

Assisted-by: Claude Code
Brings in #2445, which changed `commands/vex.rs`, so that the
omission phrase of a lock pin can be edited on its current text.

Assisted-by: Claude Code
`vex` explains `vendor_lock_pin_mismatch` with one sentence, written
when Bun's lock was the only one with a pin: "the lockfile pins the
vendored tarball to a sha512". A NuGet lock now gets the same code,
and its artifact is a nupkg. The sentence says "artifact".

Refs #2381.

Assisted-by: Claude Code
- The remedy named `socket-patch vendor` first, which does nothing in
  a project with no manifest (what `scan --mode vendored` leaves). It
  now leads with `socket-patch scan --mode vendored`, which pins the
  lock again in both.
- `vendor --check` ran the pin check before the liveness rule, so a
  package whose config and lock were both put back was reported with
  the pin's text where `vex` says `vendor_unwired`. The pin is judged
  after liveness, on a package that is wired.
- The dry run's tally asked the pin check for every NuGet package.
  NuGet's backend reports an in-sync package as `already_vendored` on
  a dry run too, so a `verified` preview of one is never in sync, and
  the tally says so without reading the tree. That also covers a
  package whose config was put back.
- `pin_stale` was "the nupkg is in sync and the lock is not", wider
  than a lock that pins other bytes. The prelude and the check now
  share one predicate, `pins_other_bytes`.
- The check does not read an artifact path that leaves the root, and
  the dead `./` trim is gone.

Refs #2381.

Assisted-by: Claude Code
A second review pass found the production change sound and three
assertions that could not fail for the reason they named.

- The row for an artifact path that leaves the root named a path with
  nothing at it, so it passed with or without the guard. It is a test
  of its own now, with a nupkg the lock does not pin at that path;
  with the guard removed it fails.
- The unwired test put the config and the lock back together, a state
  the first dry-run rule already got right. It now checks the config
  put back alone, with the lock still pinned, and then both.
- Nothing held the predicate the prelude's `pin_stale` goes by;
  `pins_other_bytes` has its rows.

Refs #2381.

Assisted-by: Claude Code
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes verification and VEX attestation for NuGet vendoring using lock-file reads; behavior shifts from pass to fail when pins drift, but logic aligns with the existing writer and Bun parity.

Overview
NuGet lock pins are now part of verification, mirroring the existing Bun lock behavior. If packages.lock.json contentHash does not match the committed vendored .nupkg (e.g. after dotnet restore --force-evaluate rewrote upstream hashes), vendor --check fails, vex drops the patch with vendor_lock_pin_mismatch, and vendor --dry-run treats the package as work to do instead of “already vendored.”

Core adds lock_pin_mismatch and shared pins_other_bytes logic in nuget_feed, runs the check after wiring liveness in the CLI, and wires vex/verify to call it for nuget entries. The wet vendor path distinguishes stale lock pins vs missing/stale nupkg in vendor_artifact_rebuilt messaging and centralizes vendor_nuget_stale_global_package warnings.

New CLI and unit tests cover correct pins, upstream pins, per-package judgment, and unwired packages. The VEX user-facing text says “artifact” instead of “tarball” for this error.

Reviewed by Cursor Bugbot for commit 2e5af57. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2e5af57. Configure here.

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. vendor --check, vex and the vendor dry run now compare a vendored NuGet package's lock pin, as the writer already did. Each packages.lock.json that pins the patched id and version to a contentHash other than the committed nupkg's sha512 now fails vendor --check and gets no vex statement (vendor_lock_pin_mismatch). The dry run also stops counting that package as in sync. A re-run of vendor that rebuilds because of a stale pin now names the pin as the reason (#2381).

Risk. Low. Every read failure in the new check, such as an unreadable or non-JSON lock, a missing nupkg, a hash-less entry or a path outside the root, returns no finding, so a malformed lock can't newly fail check or vex. The only new failure is the intended one.

Look here.

Verified.

  • cargo test -p socket-patch-core --lib nuget_feed: 136 passed.
  • The vendor NuGet tests: 4/4 passed.
  • With vendor.rs and verify.rs reverted to main, three of the new CLI tests fail, so the tests depend on the fix.
  • CHANGELOG.md is untouched, the only review thread is resolved, and ci-ok and clippy are green on 2e5af57.

Changes I made. None.

Open questions (not blocking, and both predate this PR):

  • A lock with the id pinned at our hash in one framework, and the same id and version without a contentHash in another, makes the writer rebuild on every re-run with the "missing or stale" warning. check and vex call it fine. The cause is lock_pinned, which requires every entry to carry the hash.
  • lock_pin_mismatch walks the governed locks once per NuGet entry, uncached. That could be slow in a large .NET monorepo.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

2 participants