Repository navigation
Conversation
|
This draft needs a scope decision from a maintainer. #44968 decided the rule for
This is what choice 2 leaves open. Another user owns
No user issue reports this. A directory that is not sticky, with a |
|
Status: draft. It waits for a maintainer's scope decision (see the comment above). How it was reproduced. Another user owns PR: #46041 |
|
Updated 10:28 PM PT - Oct 20th, 2026
✅ @robobun, your commit c7218faa4e6a6133da7231a1a88c2dea1d99c18a passed in 🧪 To try this PR locally: bunx bun-pr 46041That installs a local version of the PR into your bun-46041 --bun |
`bun run --filter` and `bun run --workspaces` looked for the workspace root with their own upward loop. That loop took a package.json from a sticky, group- or world-writable directory above the cwd (/tmp) as the root, and ran the script in every package it lists. `bun install` passes over such a file with a warning (#44968). `get_candidate_package_patterns` now iterates `package_json_walk`, which is `PackageJsonWalk` of `bun install` behind one exported function. Both commands pass over the same directories and print the same warning. `PackageJsonWalk::next` stats the directory from the path it already holds, so the check no longer allocates.
50a1c68 to
c7218fa
Compare
Problem
bun run --filterand--workspacestake apackage.jsonin a sticky, shared directory above the cwd (/tmp) as the workspace root, and run every package it lists:evil build: PLANTED-SCRIPT-RAN.bun installpasses over that file since install: consolidate the open package manager pull requests #44968.get_candidate_package_patterns(src/runtime/cli/filter_arg.rs:49) had its own upward loop without the rule.Fix
get_candidate_package_patternsnow iteratespackage_json_walk, thePackageJsonWalkofbun installbehind one exported function. Both commands pass over the same directories with the same warning.PackageJsonWalk::nextstats the directory from the path it holds, so the check does not allocate.test/cli/run/filter-workspace.test.ts, 19 new cases, 15 fail on main. Five related files pass (Notes).Background
package.jsonabove the cwd with aworkspaceskey.bun_syspredicate: both keep a second upward loop.Downsides
node_modules/.binof that directory stays first onPATH, also forbun installon main.bun run --filterornpm run -wthen fails, also underbun install. No opt-out.Notes
The transcripts and cost numbers below were taken on main at 017b243 and on this change applied to it. The branch is now on a later main, and they were not measured again there. Since then #46021 changed the old loop for a
package.jsonpath that is too long (see below).Reproduction. Another user owns
/tmp/x/package.json({"name":"planted","workspaces":["*"]}) and/tmp/x/evil, whosebuildscript printsPLANTED-SCRIPT-RAN./tmp/xhas mode 1777. The project is/tmp/x/proj.--filter,-F,--workspaces, the forms withoutrun,--parallel,--sequentialand--cwd=all reachselect_packagesand give the same result.The rule. It is the rule of
PackageJsonWalk::next, unchanged. The open of<dir>/package.jsondid not fail with ENOENT,<dir>is not the directory the command started in, and<dir>is sticky and writable by its group or by everyone (a failedstatcounts as shared). Bun then prints the warning, does not read the file in the walk, and goes on upward. POSIX only. Apackage.jsonthere that is not JSON ended the command witherror: ParserErrorbefore. It is now passed over like any other.What stays open. None of these is changed here. Each was run on this change. The scope comment below asks which of them a maintainer wants closed.
node_modules/.binof every directory above the cwd comes first onPATH(RunCommand::path_for_run), also for the lifecycle scripts ofbun install.package.json,bun run <script>,--paralleland--sequentialtake the script from the nearestpackage.jsonabove, and its directory is first onPATH.package.jsonabove the cwd before the walk runs. In a cwd with nopackage.json, a script still getsnpm_package_nameandnpm_package_jsonof the file that the warning names.bun run --filtertakes a root that does not list the cwd.bun installneeds the cwd to be a member.package.jsonin that directory blocks both commands inopen.node_modulesof every directory above, as in Node.package.jsonthat another user owns. That is the rule by file owner.What other tools do with the same files. npm 11.16.0:
npm prefixin/tmp/x/projprints/tmp/x, andnpm run build -w evilruns the planted package.npm run buildandnode --run build(v26.3.0) run a planted/tmp/x/node_modules/.bin/node. Neither has a rule by directory mode. The difference from npm is the one that #44968 made forbun install.A real root in such a directory. Root at mode 1777 with
workspaces: ["packages/*"], membersaandb,bun run <flags> build:--filter '*',--workspacespackages/--filter '*',--workspacespackages/a--filter '*'packages/a--workspaceserror: No workspace packages foundpackages/a--filter berror: No workspace packages matched the filter "b"After a pass-over with no other root above, the candidates are the packages in and below the cwd (
**/package.json), as when there is no root. The last row is also what a script ofagets when it runsbun run --filter b buildornpm run build -w b(which bun rewrites), while the command was started in the root. With that script as thepostinstallofa,bun installin the root ends witherror: postinstall script from "a" exited with 1. On main all three work. To keep such a tree working, move it one directory down, or remove the sticky bit or the group and world write bits from the directory.Costs, measured. Debug builds of main and of this change,
gdbwith a syscall catchpoint and breakpoints on the Rust allocator entry points, counted between entry and return ofget_candidate_package_patterns. Command:bun run --filter '*' --if-present nosuchscript. Cases: the cwd is the root, a member,packages/with no manifest, a project with no root above it, and the mode-1777 case above.statof a directory above the cwd that has apackage.json. The last number includes thewriteof the warning.Vecof the walk, once per process.bun pm lsfrom a member, allocations insidePackageJsonWalk::next: main 2, PR 1.size: text 106,738,870 to 106,739,214 bytes (+344), data 116,624 in both.warn: ignoring package.jsonlines for one command with one nestedbun run --filter, below a straypackage.jsonin a mode-1777 directory: main 0, PR 2.bun run <script>does not reach this code.Long working directory. #46021 made the old loop treat a
package.jsonpath that does not fit a path buffer like a missing file, and go on to the parent directory. The walk returnsENAMETOOLONGfor such a path, and this PR passes over it in the same way. The tests that #46021 added for it pass.Tests.
test/cli/run/filter-workspace.test.ts, block "package.json in a sticky, shared directory above the cwd": 19 cases. No case needs a second user. As uid 65534 all 19 run: 15 fail on a debug build of main, and 4 are controls that pass both ways. As root 18 run, because one case needs a file that cannot be opened. With the debug build of this PR:filter-workspace.test.ts149 pass,test/cli/install/bad-workspace.test.ts44 pass (file unchanged),test/cli/install/bun-workspaces.test.ts285 pass,test/cli/run/workspaces.test.ts4 pass,test/cli/run/run_command.test.ts33 pass,test/cli/run/multi-run.test.ts132 pass. On an earlier base,cargo check --workspacepassed forx86_64-pc-windows-msvcandaarch64-apple-darwin.Related. An earlier branch for this command had only the rule by file owner. It was never a PR, and this PR replaces it. #41797 (tsconfig.json) and #29310 (bunfig.toml) are open PRs with their own upward lookups.
no test proof · iteration 1 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/run/filter-workspace.test.ts