Skip to content

After dotnet restore --force-evaluate over a global packages folder that holds the upstream copy, vendor --check and vex call a vendored NuGet package patched while the build loads the upstream assembly: neither reads the lock's contentHash #2381

Backlog

Description

[agent] Found by the architecture refactor routine on main at cfc870f, with the real .NET SDK 8.0.428 and 10.0.404.

The problem

Vendored NuGet keeps the package's id and version, so NuGet's global packages folder (~/.nuget/packages) can already hold the upstream copy. vendor warns about that (vendor_nuget_stale_global_package) and re-pins packages.lock.json to the vendored nupkg's contentHash, so the next dotnet restore on that machine fails with NU1403. The contract says as much: "dotnet restore would keep the upstream bytes (silently without a lock, NU1403 against the re-pinned lock with one)".

NuGet's own remedy for NU1403 is dotnet restore --force-evaluate. Run on that machine it succeeds: NuGet takes the upstream copy from the global folder, never opens the vendored feed, and writes the upstream contentHash back into the lock. From then on:

  • every dotnet restore passes, --locked-mode included, and the build loads the upstream assembly;
  • socket-patch vendor --check exits 0: "committed artifact and wiring verified";
  • socket-patch vex exits 0 and attests not_affected ("Patched via Socket patch … (vendored)");
  • socket-patch vendor --dry-run prints "1 package is already vendored; nothing to do."

nuget.config still maps the id to .socket/vendor/nuget/<uuid>, and the nupkg there is intact, so nothing in the diff but one hash line shows it. The lock's contentHash is the only thing that ties a restore to the vendored bytes while the global folder holds that id and version, and neither verifier reads it.

The machine that ran vendor is such a machine by construction (it restored the project before), and so is a teammate's, and a CI runner that restores a cached ~/.nuget/packages.

A wet socket-patch vendor does notice: it re-pins the lock and warns about the global folder again. So the rule exists in the writer (core vendor/nuget_feed.rs, lines 390 to 415: lock_ok, through lock_pinned, line 2329) and is missing from the two commands whose job is to check.

The same hole was closed for Bun in #2120 (81034b8, "Lock pin"): "vendor --check and vex now compare the sha512 a bun.lock tuple (bun.lockb record) carries for a vendored tarball with the tarball's own. When they differ the lock does not install the artifact: Bun 1.3.10+ fails the integrity check on a cold cache, and Bun 1.4, which keys its tarball cache by that digest, installs whatever cached tarball has it. Both commands used to pass." It was closed for Bun alone. In vex the pin check is behind entry.flavor.as_deref() == Some("bun") (core vex/verify.rs, line 209), and the one per-backend lock audit vendor --check runs is the npm family's (check_npm_wiring, CLI commands/vendor.rs, line 1450).

The NuGet lock pin and the verifiers read the same at the v5.0.0 and v5.1.0 tags (read there, not built).

Evidence

With the real SDK

A library Fx.Alpha 1.0.0 packed with dotnet pack into a local folder feed, an app that references it with RestorePackagesWithLockFile, and a patch record that replaces lib/net8.0/Fx.Alpha.dll with a second build of the library (the string it returns differs). The SDKs ran in their mcr.microsoft.com/dotnet/sdk images with no network; socket-patch is the binary built from main, with the vendor suite's fixture service.

$ dotnet restore && dotnet run
app loads Fx.Alpha: UPSTREAM (vulnerable)

$ socket-patch vendor                              # exit 0
Vendored 1 package.
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 …/fx.alpha/1.0.0 […]
$ grep contentHash packages.lock.json
        "contentHash": "a5SFi5jQb8xP…"             # the vendored nupkg

$ dotnet restore                                   # SDK 8.0.428
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 155 ms).
$ grep contentHash packages.lock.json
        "contentHash": "q8F1j+YdUW5s…"             # the upstream nupkg again
$ dotnet restore --locked-mode
  Restored app/app.csproj (in 183 ms).
$ dotnet run
app loads Fx.Alpha: UPSTREAM (vulnerable)

$ socket-patch vendor --check                      # exit 0
pkg:nuget/Fx.Alpha@1.0.0: committed artifact and wiring verified

$ socket-patch vex --product pkg:nuget/app@1.0.0   # exit 0
Warning: pkg:nuget/Fx.Alpha@1.0.0: the installed tree does not match its vendored artifact; the
attestation is based on the committed .socket/vendor artifact (the project's lockfile or
package-manager config wires it in), but the live tree carries different bytes — re-run your
package manager's install to resync it.
Emitted 1 VEX statement
  "status": "not_affected", "justification": "inline_mitigations_already_exist",
  "impact_statement": "Patched via Socket patch 11111111-… (vendored)"

$ socket-patch vendor --dry-run                    # exit 0
1 package is already vendored; nothing to do.

SDK 10.0.404, with the project on net10.0, gives the same at every step: NU1403, then --force-evaluate restores, the lock holds the upstream hash, the app prints UPSTREAM (vulnerable), vendor --check exits 0 and vex attests.

Three more things in that transcript are wrong on their own:

  • The remedy in the vex warning does nothing. A restore already passes and keeps the upstream bytes.
  • The dry run says "nothing to do", and its JSON holds a verified event where an in-sync package has skipped / already_vendored. The wet run then rewrites the lock.
  • That wet run explains itself with "the committed vendored nupkg for Fx.Alpha@1.0.0 was missing or stale; rebuilt". The nupkg was neither. The lock pin was.

The control: on the vendored tree, delete <global packages>/fx.alpha/1.0.0 as the vendor warning says. dotnet restore --locked-mode then restores from the vendored feed, the lock keeps the vendored hash, and the app prints PATCHED. The vendored state itself is right.

A test that fails on main

For crates/socket-patch-cli/tests/vendor_ledger_schema_e2e.rs, or any suite that loads vendor_ecosystem_fixtures:

/// What `dotnet restore --force-evaluate` leaves over a global packages
/// folder that holds the upstream package: the config still maps the id to
/// the vendored feed, and the lock pins the upstream `contentHash` again.
#[test]
fn nuget_lock_pinned_to_other_bytes_is_not_verified() {
    let f = Fixture::new("nuget");
    let upstream_lock = std::fs::read(f.root.join("packages.lock.json")).unwrap();
    let (code, stdout, stderr) = f.vendor(&[], &[]);
    assert_eq!(code, 0, "{stdout}\n{stderr}");
    assert_ne!(std::fs::read(f.root.join("packages.lock.json")).unwrap(), upstream_lock);
    std::fs::write(f.root.join("packages.lock.json"), &upstream_lock).unwrap();

    let (code, ..) = f.run(&["vendor", "--check"], &[]);
    let (_, vex, _) = f.run(&["vex", "--product", "pkg:nuget/app@1.0.0"], &[]);
    let attested = vex.matches("\"status\": \"not_affected\"").count();
    assert_eq!((code, attested), (1, 0), "(vendor --check exit code, not_affected statements)");
}
test nuget_lock_pinned_to_other_bytes_is_not_verified ... FAILED
assertion `left == right` failed: (vendor --check exit code, not_affected statements)
  left: (0, 1)
 right: (1, 0)

The other ecosystems

I changed one character of each content pin the vendoring wrote into a lock, one at a time, on the ten fixtures of vendor_ecosystem_fixtures. vendor --check and vex pass on package-lock.json, pnpm-lock.yaml, pylock.toml and packages.lock.json. For the first three the writer agrees (already_vendored) and I know of no everyday command that writes such a lock, so this issue is about NuGet, where the package manager writes it itself. Not run: what real npm, pnpm and pip do with a file: entry whose pin is the upstream digest and a warm cache.

Not run: hosted NuGet after --force-evaluate (its lock-only VEX requires a contentHash to be present), SDK 6 and 9, Windows, and a real CI cache.

Planned fix

One rule, the writer's: a vendored NuGet package is wired only when every governed lock that locks the id at the patched version pins the vendored nupkg's contentHash.

  • vendor --check reports it as a wiring failure that names the lock, the two hashes and the remedy (socket-patch vendor, then delete the package's directory in the global packages folder).
  • vex omits the patch with vendor_lock_pin_mismatch, as it does for Bun, and its text stops saying "tarball".
  • vendor --dry-run counts the package as one it would re-vendor, and the wet run says the lock pin was stale, not the nupkg.
  • The contract's NuGet rows gain the rule.

The check is lock_pinned over the locks governed_locks already finds, called from the two verifiers. No new reader.


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 30, 2026
  2. added a commit that references this issue on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions