Repository navigation
fix(install): fall back to a private node shim directory instead of dropping node - #19
Merged
Merged
Conversation
…ropping node When the preferred per-user shim directory was unusable (another user pre-created it, it was group/other-writable, it was not a directory, or mkdir failed), `create_fake_temporary_node_executable` returned without touching PATH and without saying anything, so lifecycle scripts failed with `node: command not found`. Decide the shim directory once per process: use the preferred `<root>/bun-node-<uid>-<sha>` when it passes the existing ownership and mode guard, otherwise create a private `<preferred>-<16 random hex>` with mkdir 0700 (a successful mkdir means we own it). If no directory or symlink can be created, print one warning naming the directory and suggesting BUN_TMPDIR. The root now honors BUN_TMPDIR when it is absolute and free of ':' (the PATH delimiter), like the node-gyp directory lifecycle scripts already get; Bun still ignores $TMPDIR here. `bun run` sets NODE and npm_node_execpath from the directory actually in use after the shim is created, in both the --bun and plain paths. With --bun, load_node_js_config had set them to the preferred path before the directory was chosen, so a fallback left NODE pointing at the unusable (possibly attacker-planted) path. Windows is unchanged. The fork's shim naming stays a superset of upstream oven-sh#35565; keep the fork side when syncing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Follow-up to #17. #17 fixed the shared-
/tmpcollision by giving each user their own shim directory,/tmp/bun-node-<uid>-<sha>. It left three gaps, and this PR closes them.1.
nodestill vanished silently when the per-user directory was unusable. Another user can pre-create/tmp/bun-node-<victim-uid>-<sha>. The directory could also be group/other-writable, be a regular file, or failmkdir. In all of these casescreate_fake_temporary_node_executablereturned without touchingPATHor saying anything, and lifecycle scripts failed withnode: command not found.Bun now decides the shim directory once per process:
<preferred>-<16 random hex>withmkdir 0700. The name comes from BoringSSLRAND_bytes, and creation is retried only onEEXIST. A successfulmkdirmeans Bun created and owns the directory, so a squatter can neither predict nor pre-create it.BUN_TMPDIR, instead of silence.2.
NODEcould point at the unusable path.bun runsetsNODE/npm_node_execpathto the shim directory (a pre-existing quirk kept here). With--bun,load_node_js_configset them to the preferred path before the directory was chosen, so a fallback would leaveNODEpointing at a squatted, possibly attacker-planted path. Both variables are now re-set from the directory actually in use, after the shim exists, for both--bunand plainbun run. The old code pointedNODEat the shared/tmppath the same way.3. The shim root now honors
BUN_TMPDIR, like the node-gyp directory lifecycle scripts already get (get_default_temp_dir). It is only used when absolute and free of:, the PATH delimiter.$TMPDIRstays ignored, matching Bun's temp-dir convention everywhere else.The fork's naming stays a strict superset of upstream oven-sh/bun#35565. A one-line marker at
bun_node_dir()says to keep the fork side when an upstream sync conflicts there. Windows is untouched.Production delta:
src/install/lib.rs+90/-26,src/runtime/cli/run_command.rs+15/-10. Tests +117/-2. One changelog entry.How did you verify your code works?
New tests. Each uses its own
BUN_TMPDIR, an emptyPATH, and noNODE/npm_node_execpath, so they never touch/tmpand are safe to run concurrently:bun-install-lifecycle-scripts.test.ts:node probe.mjsruns under Bun through<BUN_TMPDIR>/bun-node-<uid>….chmod 0777and one with it replaced by a regular file. The second install still runs under Bun, through<preferred>-<16 hex>, owned by the user, mode0700.bun-run.test.ts, "node shim fallback keeps NODE and npm_node_execpath aligned with PATH": plainbun runandbun --bun runwith an unusable preferred directory.NODEandnpm_node_execpathequal the fallback directory onPATH.Results:
USE_SYSTEM_BUN=1), and all pass withbun bd test.NODEchange: with only therun_command.rsrefresh reverted, the--buncase fails withNODEstill set to…/bun-node-501-debugwhilePATHuses…/bun-node-501-debug-8f0260ef08ac0610. It passes with the refresh.test/cli/run/as-node.test.tspasses 11/11.test/cli/install/bun-run.test.ts: 287 pass / 2 skip / 10 fail. These are exactly the 10 failures this Mac's debug build shows on cleanmain(twoSIGILLexpectations, eight cases where the local shell can't findbun-debug).EACCESon symlink creation each print exactly one warning and add no shim entry toPATH.rust:check-allforx86_64-pc-windows-msvcandx86_64-unknown-linux-gnupasses. rustfmt and Prettier are clean.