Repository navigation
Fix Bun defects: lock version 3, bundled trees, JSONC manifests, default-trusted packages - #2120
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
Conversation
…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>
PR SummaryMedium Risk Overview Lockfile Bundled dependency trees ( JSONC Default-trusted packages without Revert/rollback restores the lock Bun installs from when both Vendored verification adds tarball Reviewed by Cursor Bugbot for commit 475e635. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ 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.
| !already_pinned | ||
| && entries.iter().zip(&specs).any(|(entry, spec)| { | ||
| spec.as_deref() == Some(&target_spec) && !is_bundled_entry(entry) | ||
| }) |
There was a problem hiding this comment.
Bundled pins skip default-trust gate
Medium Severity
already_pinned treats a hosted URL on a bundled lock entry as a live pin. Bun never installs from that spec, so a later non-bundled registry copy of a default-trusted package still runs install scripts. The skip then lets the rewriter take that copy off the registry, and Bun 1.3.5+ silently drops the scripts.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 475e635. Configure here.
| // What is left after the installer drops the first segment. | ||
| let Some((_, installed)) = folded.split_once('/') else { | ||
| continue; | ||
| }; |
There was a problem hiding this comment.
Tarball check misses parent-path overwrites
Medium Severity
shadowed_member drops empty and . segments but not .., then strips only the first path segment. A later tar entry such as package/foo/../index.js therefore does not count as landing on index.js, even though npm-family extractors normalize that path and overwrite the patched file.
Reviewed by Cursor Bugbot for commit 475e635. Configure here.


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
lockfileVersion: 3— Bun 1.4.0+ writes it whenpackage.jsonhas a nested override or a yarn-style path resolutionnode_modulesprintedNo packages foundwith no warningbun_lock_unsupportedinstead of scanning as emptybundleDependenciescopy (a project that depends onnpmhas hundreds)not_affectedbyvexin vendored mode, while Bun kept installing the unpatched copies from the parent's tarballpackage.jsonwith comments or trailing commas — Bun installs from itvendor/,build/,dist/;vexcould not name the productsqlite3,sharp, …) with notrustedDependenciesinpackage.jsonbun installskipped the install script and exited 0, andrequire('sqlite3')threwredirect_bun_default_trust_skipped, vendored:vendor_bun_default_trust_refused). A pin an earlier run wrote stays and keeps its warningbun install --save-text-lockfileon Bun 1.1.39–1.1.45 keepsbun.lockbbeside the newbun.lockrollback/vendor --revertrestoredbun.lockband removed the tarball;bun.lock, which Bun installs from, still pointed at it, and every install failedENOENT extracting tarballvendor_bun_stale_binary_lockvendor --checkpassed andvexattested, while Bun failed the integrity check or (1.4, warm cache) installed a different tarballvendor --checkfails with the remedy;vexomits the patch (vendor_lock_pin_mismatch)package/and the original under a second rootvendor_artifact_non_canonical. Only the patch's files are judged, so upstream tarballs with a link or odd name elsewhere keep verifyingpackagessection — inside a/* */comment or under another key, ahead of the real onepackageskeyDecision worth a look: default trust
Bun reads
trustedDependenciesfrompackage.jsononly. I measured a copy written intobun.lockalone 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 editpackage.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, andpackage.jsonadded 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
vendor --checkandvex): version 3 hosted and vendored from a fresh checkout through a cold frozen install,vexand a byte-exact rollback;npm@6.14.18beside a direct dependency on a packagenpmbundles; a JSONC workspace root with a member undervendor/;sqlite3@5.1.4with 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.npm@6.14.18,npm@10.9.0,fsevents@1.2.9and a 1,069-entry lock holdingsemantic-release: the entries the rule leaves unmarked are exactly the packages Bun fetched.cargo test -p socket-patch-core --lib(7,822), the core golden suites, the CLI unit tests, and the CLI targetsin_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 suitese2e_redirect_bun_build,e2e_vendor_bun_build,mode_migration_bunande2e_bun_lockbon 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-overridesneeds aTS_LAGGINGentry (orbun.tsaccepting version 3), andlock-version-unsupportednow uses version 4.Not fixed here
bun updatestrips a pin (Bun's behaviour, every version tried), and a patched package drops out ofbun audit/bun outdated. Both are now documented, withvendor --checkas the CI check for vendored mode.scan --vexattests 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.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 laterapply. Not Bun-specific; it needs its own change in the crawler.scan --dry-runin vendored mode says "already vendored" when the lock wiring was dropped, while the wet run rewires it.semver@7.3.5patch record lists a straypatch_manifest.json, so vendoring it fails and hostedvexomits it. That is catalog data, not this repo.e2e_bun_lockbnow 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 highreported 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 staletrustedDependenciesmirror inbun.lockcounted 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 lenientpackage.jsonread 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@versionthe 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 hasminimist0.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 falsenot_affected:npmpins its bundled tree exactly, and there the lock's version is the unpatched copy on disk (checked forip@1.1.5undernpm@6.14.18). The skip warning for such an entry now says the version may differ.🤖 Generated with Claude Code