Repository navigation
Allow native add-on install scripts under npm 12's allowScripts policy - #1805
Conversation
npm >= 12 blocks dependency install scripts for global installs unless they are named in --allow-scripts, and it does not read the installed package's own package.json#allowScripts for -g / npx. bb-app's native add-ons (better-sqlite3, node-pty, @parcel/watcher) then install without their binaries, npm exits 0, and bb crashes at startup with "Could not locate the bindings file" / "Failed to load native module: pty.node". - Pass --allow-scripts=better-sqlite3,node-pty,@parcel/watcher on both `npm install -g` lines in install-machine.sh and in the daemon self-updater argv. npm 10 ignores the flag; npm 11 accepts it. - After the install, the installer requires better-sqlite3 and node-pty from the installed bb-app and fails loudly with a pointer to npm_config_allow_scripts / ignore-scripts instead of failing 30 s later in the daemon with a raw stack trace. - Update the fake npm and argv assertions in the installer test and add a regression test for the loud failure. - Document the npx --allow-scripts form in the README quick start and troubleshooting sections and in packages/bb-app/README.md. Fixes #1120 Co-Authored-By: Claude <[email protected]>
|
🚨 SLOP COP 🚨 · I am SlopCop. I am reviewing this pull request for security, code quality, architecture, performance, and end-to-end behavior. I will post one final review after the parallel checks finish. |
| bb_app_root="$bb_app_npm_prefix/lib/node_modules/bb-app" | ||
| if ! node -e ' | ||
| const root = process.argv[1]; | ||
| require(root + "/node_modules/better-sqlite3"); |
There was a problem hiding this comment.
🚨 slopcop/review — The better-sqlite3 check does not load the native binding
require("better-sqlite3") only loads JavaScript. The native binding loads when code creates a database.
I reproduced this with npm 12.0.2. npm returned 0 after it blocked only the better-sqlite3 script. This exact probe also returned 0. Creating new Database(":memory:") then failed with Could not locate the bindings file.
Please create and close an in-memory database here. The test fixture should keep the package JavaScript and remove only its native output, because an empty module directory does not model npm 12.
There was a problem hiding this comment.
Fixed in #1816: the installer probe now opens and closes an in-memory better-sqlite3 database, then requires node-pty (which loads pty.node at module load). The fake npm keeps the add-on JavaScript and omits only the native output, per module; the new case with only better-sqlite3 blocked failed with the old probe and passes now.
| }); | ||
| await runProcess( | ||
| "npm", | ||
| ["install", "-g", BB_APP_ALLOW_SCRIPTS_ARG, ...prefixArgs, tarballPath], |
There was a problem hiding this comment.
🚨 slopcop/review — Validate the installed native add-ons before the daemon restarts
ignore-scripts=true overrides this allow-list. npm 12 still returns 0, so this method reports success after it installs a broken package. The caller then stops the valid daemon and restarts into missing native bindings.
The fresh installer adds a health check, but this update path has no equivalent check. Please run real SQLite and PTY operations before this update returns updated.
There was a problem hiding this comment.
Fixed in #1816: after npm install -g the self-updater runs npm root -g [--prefix] and the same probe (in-memory SQLite database + node-pty load, which loads pty.node) in a node child process; a failure throws before it reports updated, so the daemon returns failed and keeps running. Requiring node-pty is the real native load (its module top level calls loadNativeModule('pty')); I did not spawn a PTY so the check cannot fail on hosts without /dev/ptmx.
| `npm config set allow-scripts=better-sqlite3,node-pty,@parcel/watcher --location=user`. | ||
| npm 10 and 11 accept or ignore the flag, so it is safe on every supported Node. | ||
|
|
||
| The second cause is `ignore-scripts=true` in your `~/.npmrc`. Set the |
There was a problem hiding this comment.
🚨 slopcop/review — The recovery commands below still fail on npm 12
Clearing ignore-scripts does not approve the three dependency scripts. npm 12 blocks them, returns 0, and leaves bb without its native binaries.
Please combine both controls in the npx and global-install examples. For example: npm_config_ignore_scripts=false npx --allow-scripts=better-sqlite3,node-pty,@parcel/watcher bb-app@latest.
There was a problem hiding this comment.
Fixed in #1816: both README ignore-scripts recovery commands now also pass --allow-scripts=better-sqlite3,node-pty,@parcel/watcher (npx and npm install -g forms), and the text says ignore-scripts overrides the allow-list.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: This change lets npm 12 build the three native add-ons that bb needs. It updates machine installs, daemon updates, tests, and user instructions.
I found three correctness issues.
-
The fresh-install health check can accept a broken
better-sqlite3package. Importing the package does not load its native binding. The check must create and close an in-memory database. The test must model missing native output, not missing JavaScript. -
The self-updater has no native health check. A user policy with
ignore-scripts=trueoverrides the new allow-list. npm returns success, then bb can replace a valid daemon with a broken package and restart it. -
The
ignore-scriptsrecovery commands omit--allow-scripts. Those commands still produce a broken npm 12 install. The examples must set both controls.
Architecture note: The package list now appears in TypeScript, shell code, two documents, and several tests. A single policy manifest and a contract test would prevent drift. The tarball smoke test must also use the npm 12 command and run in pull-request checks.
Security review found no command injection or new privilege escalation. The shell quotes the fixed argument. The daemon uses execFile without a shell. Prefer the one-command policy because a user-wide name policy also permits future package versions.
I found no new performance regression. The added health check runs once during machine setup. Existing repeated setup still performs a complete package install, but this pull request does not add that behavior.
Validation results:
- A real npm 12.0.2 install with the allow-list succeeded. SQLite, PTY, Parcel watcher, and
bb-app --helpworked. - A real npm 12.0.2 blocked-script test reproduced the health-check error. npm and the current probe returned 0, but SQLite failed to open.
- The exact host-daemon test passed 12 tests.
- An isolated machine-installer run passed 17 tests. One loaded shared-host run had an unrelated daemon-connect failure.
- Both focused type checks passed.
- All GitHub checks passed, including both package smoke jobs.
I did not use a browser because this change has no browser workflow. The real npm 12 install tested the affected end-to-end path.
What was wrong
bb ships as the
bb-appnpm package. Three of its dependencies are native add-ons:better-sqlite3,node-pty, and@parcel/watcher. npm install scripts download or build their binaries. npm 12 (12.0.2 isnpm@latest) enforces the newallowScriptspolicy: fornpm install -gandnpx, npm blocks dependency install scripts unless--allow-scripts,npm_config_allow_scripts, or a user/global.npmrcnames them. npm does not read the installed package's ownpackage.json#allowScriptsfor global installs, sobb-appcannot fix this from inside the package. npm still exits 0, prints only a warning, and bb then dies at startup withCould not locate the bindings file(server) orFailed to load native module: pty.node(host daemon). The report reproduced this on all three install paths (npm install -g bb-app,npx bb-app@latest, and the "Add machine" installer). On npm 11 the policy is only advisory: npm warns and runs the scripts. The installer, the daemon self-updater, and the docs passed no allow-list, and the installer printed✓ Installedbefore it failed 30 s later at the join step with a raw stack trace.Independent investigation report: https://get-bb.github.io/reports/issues/1120.html
What changed
apps/server/src/assets/install-machine.sh: bothnpm install -glines pass--allow-scripts=better-sqlite3,node-pty,@parcel/watcher. After the install, the script requiresbetter-sqlite3andnode-ptyfrom the installedbb-app. If they do not load, it fails withnpm installed bb-app, but its native add-ons (better-sqlite3, node-pty) did not load.and points tonpm_config_allow_scripts=... npm_config_ignore_scripts=false.apps/host-daemon/src/protocol-self-update.ts: the self-updater passes the same--allow-scriptsargument tonpm install -g.apps/server/test/app/install-machine-script.test.ts: the fake npm now lays outlib/node_modules/bb-app/node_modules/{better-sqlite3,node-pty}like a real install; the argv assertions include the flag; a new testfails loudly when npm skipped the native add-on install scriptssetsFAKE_NPM_SKIP_NATIVE_MODULES=1and asserts exit 1, the message, and that no daemon starts.apps/host-daemon/src/protocol-self-update.test.ts: argv assertions include the flag.README.mdandpackages/bb-app/README.md: documentnpx --allow-scripts=better-sqlite3,node-pty,@parcel/watcher bb-app@latestandnpm config set allow-scripts=... --location=userin the quick start and troubleshooting sections.npm 10 ignores the unknown flag and npm 11 accepts it (verified:
npm 11.16.0 install -g --allow-scripts=... --dry-runruns with no warning). No wire changes; noHOST_DAEMON_PROTOCOL_VERSIONbump.Deviation from the report: none in substance. The loud-failure check is the report's diff with the message wording adjusted and the module list stored in one shell variable.
How I verified
installs the server tarball even when a same-version bb-app is on PATH,falls back to npm only when the server artifact returns 404,fails loudly when npm skipped the native add-on install scripts.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/host-daemon→ pass.pnpm exec turbo run test --filter=@bb/host-daemon→ 583 passed.pnpm exec turbo run test --filter=@bb/server→ 1729 passed, 2 failed. Both failures are unrelated to this change:internal-skill-trees.test.tsexpects file mode 420 and gets 436 (local umask), andplugin-service.test.tshit the 5 s timeout under full-suite load; both pass on rerun / are environmental.install-machine-script.test.ts(17 tests) passes.Fixes #1120