Skip to content

Fix Bun defects: lock version 3, bundled trees, JSONC manifests, default-trusted packages - #2120

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
fix/bun-review-defects
Nov 18, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
fix/bun-review-defects

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the Bun defects found by running real Bun 1.1.45 to 1.4.4 against the released 5.1.0 CLI and reading the Bun code paths. Each one was reproduced first and checked again on real Bun after the fix.

What was wrong, and what changes

Defect Before After
lockfileVersion: 3 — Bun 1.4.0+ writes it when package.json has a nested override or a yarn-style path resolution Hosted mode patched nothing and exited 0; vendored mode failed; a checkout with no node_modules printed No packages found with no warning Versions 0 to 3 are accepted (only the lock's head differs in 3). A lock that is still refused is reported as bun_lock_unsupported instead of scanning as empty
Bundled trees — the dependencies of a bundleDependencies copy (a project that depends on npm has hundreds) Rewired and reported patched in hosted mode, vendored and attested not_affected by vex in vendored mode, while Bun kept installing the unpatched copies from the parent's tarball Treated as bundled copies: not rewired, reported as unpatched, never attested. Wiring an earlier release wrote there stays listed and can be undone
package.json with comments or trailing commas — Bun installs from it The workspace root looked like no workspace: a member's stray lock was attested while Bun installed the member unpatched from the root lock; agent mode skipped member copies under vendor/, build/, dist/; vex could not name the product Read the way Bun reads it
Default-trusted native packages (sqlite3, sharp, …) with no trustedDependencies in package.json Rewired with a warning; the next bun install skipped the install script and exited 0, and require('sqlite3') threw Left on the registry, unpatched, with the way to patch it (redirect_bun_default_trust_skipped, vendored: vendor_bun_default_trust_refused). A pin an earlier run wrote stays and keeps its warning
Revert with both locks — bun install --save-text-lockfile on Bun 1.1.39–1.1.45 keeps bun.lockb beside the new bun.lock rollback / vendor --revert restored bun.lockb and removed the tarball; bun.lock, which Bun installs from, still pointed at it, and every install failed ENOENT extracting tarball The lock Bun installs from is restored; a stale binary lock is left alone with vendor_bun_stale_binary_lock
Lock pin not checked — a vendored tuple whose sha512 is not the committed tarball's vendor --check passed and vex attested, while Bun failed the integrity check or (1.4, warm cache) installed a different tarball vendor --check fails with the remedy; vex omits the patch (vendor_lock_pin_mismatch)
Tarball shape not checked — the patched file under package/ and the original under a second root Verified and attested; Bun strips the first path segment whatever it is and installed the original A patched file that another entry would be extracted over fails vendor_artifact_non_canonical. Only the patch's files are judged, so upstream tarballs with a link or odd name elsewhere keep verifying
Decoy packages section — inside a /* */ comment or under another key, ahead of the real one Parsed, rewired and attested from a lockfile-only checkout; Bun installed the real section The section is the root object's first packages key

Decision worth a look: default trust

Bun reads trustedDependencies from package.json only. I measured a copy written into bun.lock alone on Bun 1.3.14 and 1.4.4: a frozen install still blocks the script and a plain install deletes the entry. So the only way to patch such a package without breaking it is to edit package.json, and declaring a list replaces Bun's default list for the whole project. This PR takes the conservative option: skip, and say how to patch it. Writing the trust list ourselves is the alternative. It would patch more, and it needs the lock mirror written byte-exact on every Bun version, a binary-lock equivalent, and package.json added to the files hosted mode may change (depscan's allowlist rejects it today).

The other behaviour change to weigh: vendored mode now exits 1 for a default-trusted package it refuses, as it does for its other refusals, where 5.1.0 vendored it and warned.

How it was checked

  • Real Bun 1.4.4, no Socket login, built from this branch. Each row was reproduced before and verified after (and a 9-package vendored project built from the service's tarballs still passes vendor --check and vex): version 3 hosted and vendored from a fresh checkout through a cold frozen install, vex and a byte-exact rollback; npm@6.14.18 beside a direct dependency on a package npm bundles; a JSONC workspace root with a member under vendor/; sqlite3@5.1.4 with and without declared trust; the both-locks revert on Bun 1.1.45 and 1.4.4 against the published 5.1.0; a tampered lock pin and a two-root tarball.
  • The bundled-copy rule was compared with what Bun 1.4.4 downloads into an empty cache for npm@6.14.18, npm@10.9.0, fsevents@1.2.9 and a 1,069-entry lock holding semantic-release: the entries the rule leaves unmarked are exactly the packages Bun fetched.
  • Tests. cargo test -p socket-patch-core --lib (7,822), the core golden suites, the CLI unit tests, and the CLI targets in_process_redirect, in_process_vendor, in_process_vendor_bun_takeover, vendor, scan, rollback, repair, remove, get, e2e_vex_lockfile, vendor_eject_bun_lockb, plus the real-Bun suites e2e_redirect_bun_build, e2e_vendor_bun_build, mode_migration_bun and e2e_bun_lockb on Bun 1.4.2 and 1.4.4. The full workspace suite was left to CI.

For depscan's next pin bump

The new golden redirect/npm/bun/lock-v3-nested-overrides needs a TS_LAGGING entry (or bun.ts accepting version 3), and lock-version-unsupported now uses version 4.

Not fixed here

  • bun update strips a pin (Bun's behaviour, every version tried), and a patched package drops out of bun audit / bun outdated. Both are now documented, with vendor --check as the CI check for vendored mode.
  • scan --vex attests before the patched bytes are installed. That is the open decision in Decide: should hosted VEX require installed evidence by default instead of attesting from lockfile wiring? #1099.
  • An entry from another registry with the same name and version is replaced by the public patched build without a warning. Telling a fork from a mirror needs the upstream digest, which the rewriters do not have.
  • Agent mode treats workspace members and URL or file: dependencies as registry packages: first-party names are sent to the patch API, and a name collision leaves a manifest entry that fails every later apply. Not Bun-specific; it needs its own change in the crawler.
  • scan --dry-run in vendored mode says "already vendored" when the lock wiring was dropped, while the wet run rewires it.
  • The semver@7.3.5 patch record lists a stray patch_manifest.json, so vendoring it fails and hosted vex omits it. That is catalog data, not this repo.
  • CI's Bun matrix stops at 1.4.2. e2e_bun_lockb now passes on 1.4.4 too; adding 1.4.4 and a nested-override shape to the matrix is a follow-up.

Code review

/code-review high reported 10 findings on the first three commits. Nine are fixed in 475e635: the tarball check judged whole archives and would have rejected upstream tarballs vendoring accepts; a stale trustedDependencies mirror in bun.lock counted as declared; vendored mode refused a package that already had a vendored copy; non-sha512 lock pins were ignored; one JSONC parse site was missed; the lenient package.json read leaked into npm and yarn workspace lookups; and three hot-path or dead-code items.

One is not changed: an entry inferred to sit inside a bundled copy is still treated as an unpatched copy of the name@version the lock names, so a patch for the same version elsewhere in the lock is not attested from the lockfile. Bun installs whatever version the parent packed, which the lock cannot tell (fsevents@1.2.9's tree has minimist 0.0.8 where the lock says 1.2.8), so this can withhold an attestation that would have been right. It is kept because the opposite error is a false not_affected: npm pins its bundled tree exactly, and there the lock's version is the unpatched copy on disk (checked for ip@1.1.5 under npm@6.14.18). The skip warning for such an entry now says the version may differ.


Generated by Claude Code

…ts, default trust

Found by running real Bun 1.1.45 to 1.4.4 against the released CLI. Each
fix was checked against real Bun 1.4.4 again.

lockfileVersion 3. Bun 1.4.0 and later write version 3 when package.json
has a nested override or a yarn-style path resolution. Only the lock's head
differs (its `overrides` object nests); the packages grammar is the
version-2 one, and Bun installs a hosted or local tuple written into such a
lock. The text lock gate now accepts 0 to 3, so hosted and vendored mode
patch these projects instead of doing nothing. A `bun.lock` the gate still
refuses (version 4 or later, a comment line, a re-indent) is now reported
by the lock inventory as `bun_lock_unsupported`: before, a checkout with no
node_modules scanned as an empty project and printed "No packages found".

Bundled trees. Bun flags only the names a package lists in
bundleDependencies. The dependencies of those copies get ordinary looking
lock entries (records, in bun.lockb) that Bun writes and never installs: a
project depending on `npm` has hundreds. Hosted mode rewired them and
reported them patched, and vendored mode vendored them and `vex` attested
them, while the installed bytes stayed unpatched. An entry now counts as
part of a bundled copy when it is nested, something depends on it, and
everything that depends on it is a bundled copy. Measured against what Bun
1.4.4 downloads into an empty cache for npm@6.14.18, npm@10.9.0,
fsevents@1.2.9 and a 1,069-entry lock with semantic-release: the entries
left unmarked are exactly the packages Bun fetched. Wiring an earlier
release wrote into such an entry stays listed and can be undone, and is
never attested.

JSONC manifests. Bun installs from a package.json with comments and
trailing commas. The workspaces reader was strict, so such a root looked
like no workspace: a member's stray lock was attested by `vex` while Bun
installed the member from the root lock, agent mode skipped member copies
under pruned directory names (vendor/, build/, dist/), and `vex` could not
name the product. package.json is now read the way Bun reads it.

Default trust. Bun 1.3.5 and later trust a default-listed package only
while it resolves from the npm registry, and read trustedDependencies from
package.json alone (a copy written only into bun.lock is ignored on a
frozen install and deleted by a plain one). Rewiring sqlite3@5.1.4 made
`bun install` skip its install script and exit 0, and `require('sqlite3')`
then threw. Such a package is now left on the registry, unpatched, with the
way to patch it (`redirect_bun_default_trust_skipped`, vendored:
`vendor_bun_default_trust_refused`), unless the project declares
trustedDependencies. A pin an earlier run wrote stays and keeps its
warning.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… caveats

docs/ecosystems.md and docs/testing/bun-compatibility.md now state what
changed in the previous commit and four things measured on real Bun that a
project patched in hosted or vendored mode should know:

- a bare `bun update`, or `bun update <patched package>`, writes the
  registry tuple back with exit 0 and no message (Bun 1.1.45 to 1.4.4);
  every other everyday command keeps the pin
- a default-trusted package is patched only when package.json declares
  trustedDependencies
- copies bundled inside another package's tarball are not patched outside
  agent mode
- a patched package drops out of `bun audit` and `bun outdated`

and that a vendored project's install needs `.socket/vendor/` present,
which a Dockerfile layer copying only package.json and bun.lock lacks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…evert

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. `vendor --check` reports it as a wiring failure with
the remedy; `vex` omits the patch (`vendor_lock_pin_mismatch`).

Tarball shape. A committed npm tarball is verified with the strict reader
that artifact reuse and repair already use. npm-family installers strip the
first path segment whatever it is and let a later entry win, so a tarball
with the patched file under package/ and the original under another root
verified and installed unpatched. It now fails
`vendor_artifact_non_canonical`. Every tarball vendoring writes is in the
canonical shape.

Section lookup. The packages section is the root object's first `packages`
key, found by brace depth outside strings and comments. The first line
spelled `  "packages": {` used to be taken, so a decoy section inside a
`/* */` comment, or under another key, was parsed, rewired and attested
while Bun installed the real one.

Revert with both locks. `bun install --save-text-lockfile` on Bun 1.1.39 to
1.1.45 writes bun.lock and keeps bun.lockb, and Bun then installs from
bun.lock. Reverting a package vendored against the binary lock restored
bun.lockb only and removed the tarball, so bun.lock pointed at a missing
file and every install failed `ENOENT extracting tarball` (reproduced with
5.1.0 on Bun 1.1.45 and 1.4.4). The revert now restores the lock Bun
installs from, and warns `vendor_bun_stale_binary_lock` when the binary
lock it leaves alone still names the removed tarball.

e2e_bun_lockb's workspace migration test accepts Bun 1.4.4, which writes
`workspace:*` itself when it migrates a binary lock to text.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Tarball shape: the strict reader rejected whole archives, so an upstream
  tarball with a link, a non-ASCII name or a case twin anywhere, which
  vendoring accepts, could never verify again. The check now judges only
  the patch's files: a file is shadowed when another entry lands on its
  installed path (another top-level directory, a second or case-variant
  spelling, a link) or sits where one of its directories must be.
- Default trust: package.json decides whether trustedDependencies is
  declared whenever it can be read. A stale mirror in bun.lock no longer
  counts, since Bun does not honour it and the package would be rewired
  into a skipped install script.
- Default trust, vendored: a package with one copy already vendored is no
  longer refused when the lock gains another registry copy, matching
  hosted mode. Bun trusts by name, so the first copy already took the
  default trust.
- Lock pin: a pin under any algorithm other than sha512 counts as a
  mismatch instead of being ignored.
- JSONC manifests: only a root holding a Bun lock is read leniently in the
  governing-root lookups, and the yarn classic readers stay strict, so an
  npm or yarn project below a JSONC ancestor keeps its own lock. The
  workspace-literal heal reads member manifests the way Bun does.
- Hosted hot path: the default-list lookup runs before any lock scan, the
  binary lock is decoded only for a default-listed override, and the
  per-entry bundled cache that memoized a field read is gone.
- An entry inferred to sit inside a bundled copy says that Bun installs
  what the parent packed, which may be another version than the lock
  names.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 17, 2026 21:35
@cursor

cursor Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted/vendored Bun behavior, workspace discovery, and VEX omission rules—high user impact for Bun projects but bounded to npm-family/Bun paths with extensive test coverage.

Overview
Bun-related correctness fixes across hosted redirect, vendored mode, discovery, and verification.

Lockfile lockfileVersion: 3 is now supported (nested overrides / path resolutions); unknown versions shift to v4 refusal. Unparseable bun.lock files surface bun_lock_unsupported on scan instead of acting like an empty project.

Bundled dependency trees (bundleDependencies / parent-packed copies) are no longer rewired or attested as patched; warnings clarify Bun never installs those lock entries.

JSONC package.json (comments, trailing commas) is parsed as Bun does so workspace roots and member crawls match what Bun actually installs; Bun-only workspace governance applies when only Bun locks are present.

Default-trusted packages without trustedDependencies in package.json stay on the registry (hosted: redirect_bun_default_trust_skipped; vendored: refused). Existing pins keep the prior “trust lost” advisory.

Revert/rollback restores the lock Bun installs from when both bun.lock and bun.lockb exist (vendor_bun_stale_binary_lock).

Vendored verification adds tarball shadowed_member checks (vendor_artifact_non_canonical), Bun vendor_lock_pin_mismatch on vendor --check and VEX, plus matching user-facing VEX copy in CLI_CONTRACT.md.

Reviewed by Cursor Bugbot for commit 475e635. Configure here.

@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 2 potential issues.

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 475e635. Configure here.

- A bundled lock entry (bun.lock) or bundled-only record (bun.lockb) that
  carries the hosted URL no longer counts as an earlier pin in the
  default-trust gate: Bun never reads a bundled copy's spec, so the
  registry copy beside it still runs its install scripts and must stay
  on the registry.
- The tarball shadow check resolves `..` segments as extractors do, so a
  later `package/x/../index.js` counts as landing on the patched
  `index.js`.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for 3642f3a

What it does. This fixes eight Bun defects that were reproduced on real Bun 1.1.45–1.4.4. Bun 1.4's lockfileVersion: 3 is now read. A lock that can't be read is reported instead of scanning as empty. Packages inside a bundled copy are no longer rewired or attested, and a package.json with comments or trailing commas is read the way Bun reads it. Default-trusted native packages (sqlite3, sharp, …) stay on the registry instead of losing their install scripts. Vendored mode now also checks that the lock pins the tarball's own sha512 and that no second tarball entry overwrites a patched file.

Risk: medium. It changes behavior users will see. Hosted mode now reports some bundled-tree and default-trusted packages as unpatched where 5.1.0 said they were patched. Vendored mode now exits 1 for a default-trusted package it refuses, where 5.1.0 warned. The new checks make vendor --check and vex stricter, so a project with a tampered pin or a shadowed tarball that passed before now fails. In every case the old behavior was the wrong one, because it claimed a patch that Bun never installed.

Look here

  • redirect/mod.rs:6203 skip_bun_default_trusted: this is the product decision the PR body asks about. It skips and explains how to patch, rather than writing trustedDependencies itself. A pin an earlier release wrote stays in place with its warning.
  • bun_lock_text.rs:481 mark_bundled_copies: an unflagged entry counts as bundled when bundled copies are the only way to reach it. That decides what is no longer attested.
  • package.rs:204 shadowed_member: only the patch's own files are judged, so upstream tarballs with a link or a case twin elsewhere still verify.
  • bun_lock.rs:309 lock_pin_mismatch: wired into vendor --check and vex. A 2-tuple with no digest still passes.
  • governing_root.rs:1053 workspace_patterns: a JSONC manifest names a workspace only next to a Bun lock, and only for Bun's lock.

Verified

  • I read the full source diff: the JSONC stripper, including strings, escapes and trailing-comma removal; the tarball shadow check and its entry and size bounds; the lock-pin check for text and binary locks; the binary-lock default-trust path; and the bundled inference. Benchmark tracking: socket-patch scan #580 removed the lazy bundled cache, but is_bundled_entry is now a precomputed field, so the per-patch cost is still gone.
  • CHANGELOG.md is untouched. The branch has no conflict and nothing new on main since its merge base.
  • Both Bugbot threads on the previous head are resolved and fixed in 3642f3a.
  • CI on 3642f3a is green: ci-ok success, clippy success.
  • I also ran the targeted core tests for the new code locally (cargo test -p socket-patch-core --lib filtered to shadowed_member, reads_the_comments, jsonc_manifest, default_trusted and lock_pin): 17 passed, 0 failed.

Changes I made: none.

Open questions (both are in the PR body)

  1. Default trust: should the PR keep the conservative skip, or have socket-patch write trustedDependencies itself?
  2. Is it acceptable that vendored mode now exits 1 for a refused default-trusted package?

The approval is the answer to both.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants