Skip to content

Allow native add-on install scripts under npm 12's allowScripts policy - #1805

Merged
SawyerHood merged 1 commit into
mainfrom
bb/draft-pr-for-1120-fresh-install-silently-breaks-thr_mhgd5dvwux
Aug 18, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/draft-pr-for-1120-fresh-install-silently-breaks-thr_mhgd5dvwux

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What was wrong

bb ships as the bb-app npm 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 is npm@latest) enforces the new allowScripts policy: for npm install -g and npx, npm blocks dependency install scripts unless --allow-scripts, npm_config_allow_scripts, or a user/global .npmrc names them. npm does not read the installed package's own package.json#allowScripts for global installs, so bb-app cannot fix this from inside the package. npm still exits 0, prints only a warning, and bb then dies at startup with Could not locate the bindings file (server) or Failed 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 ✓ Installed before 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: both npm install -g lines pass --allow-scripts=better-sqlite3,node-pty,@parcel/watcher. After the install, the script requires better-sqlite3 and node-pty from the installed bb-app. If they do not load, it fails with npm installed bb-app, but its native add-ons (better-sqlite3, node-pty) did not load. and points to npm_config_allow_scripts=... npm_config_ignore_scripts=false.
  • apps/host-daemon/src/protocol-self-update.ts: the self-updater passes the same --allow-scripts argument to npm install -g.
  • apps/server/test/app/install-machine-script.test.ts: the fake npm now lays out lib/node_modules/bb-app/node_modules/{better-sqlite3,node-pty} like a real install; the argv assertions include the flag; a new test fails loudly when npm skipped the native add-on install scripts sets FAKE_NPM_SKIP_NATIVE_MODULES=1 and 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.md and packages/bb-app/README.md: document npx --allow-scripts=better-sqlite3,node-pty,@parcel/watcher bb-app@latest and npm config set allow-scripts=... --location=user in 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-run runs with no warning). No wire changes; no HOST_DAEMON_PROTOCOL_VERSION bump.

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

  • Before the change (installer script stashed), the three installer tests failed: 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.ts expects file mode 420 and gets 436 (local umask), and plugin-service.test.ts hit the 5 s timeout under full-suite load; both pass on rerun / are environmental. install-machine-script.test.ts (17 tests) passes.

Fixes #1120

AGENT GENERATED: by Claude Opus 5

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]>
@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md
`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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

  1. The fresh-install health check can accept a broken better-sqlite3 package. 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.

  2. The self-updater has no native health check. A user policy with ignore-scripts=true overrides the new allow-list. npm returns success, then bb can replace a valid daemon with a broken package and restart it.

  3. The ignore-scripts recovery 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 --help worked.
  • 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.

@SawyerHood
SawyerHood merged commit 3de9cce into main Aug 18, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/draft-pr-for-1120-fresh-install-silently-breaks-thr_mhgd5dvwux branch August 18, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant