← reports

#7985 · Inherited shell argv override survives child environment sanitation

BugMedium priorityLow effortdesktopworkspacesGitHub issue2026-11-21

Trusted base: 35a03bbbb3f4d8dc814c1a152db5a463102b4250.

Verdict: REPRODUCED at the child-environment boundary. Root-cause confidence: high. Reproduction label: confirmed-repro.

1. TL;DR

An inherited shell argument-zero override reaches user child processes even after bb sanitizes their environment. The shared sanitizer removes bb runtime variables and Node mode, but not ARGV0; the terminal manager uses that sanitizer when constructing its shell environment. A real subprocess launched with the sanitizer's output sees the unwanted override in two clean checkouts of trusted main. This verifies the environment-leak defect, not an end-to-end packaged desktop launch: this machine has no zsh, rustup, or AppImage fixture. Removing just the inherited override makes the reproduction and focused regression pass without discarding the AppImage metadata.

2. Claims vs findings

Reported behaviorStatusEvidence
Child environments retain an inherited argv override.VerifiedBoth clean baseline runs print a non-null ARGV0 in a real Node child, then fail the invariant assertion.
The terminal path does not remove that override.Verified by source trace and sanitizer executionThe terminal environment builder spreads the actual sanitizer result; its ordinary runtime shell overlay contains PATH and bb runtime keys, not ARGV0.
Desktop child environment construction retains the original environment.Verified by source inspectionThe packaged runtime branch spreads the supplied environment and enables Electron's Node mode.
The packaged Linux runtime exports the override and zsh causes rustup proxy dispatch to fail.Not executed hereNo AppImage fixture, zsh, or rustup is installed. No claim is made that this report reran the original cargo command.
All Linux AppImage users with zsh are affected.Scope not independently measuredThis report verifies the underlying inheritance path, not population-wide exposure or every shell configuration.

3. Environment

4. Minimal reproduction

  1. Clone the public target and select the recorded trusted base, then install its locked dependencies:
    git clone https://github.com/get-bb/bb.git bb-7985
    cd bb-7985
    git checkout --detach 35a03bbbb3f4d8dc814c1a152db5a463102b4250
    pnpm install --frozen-lockfile --prefer-offline
  2. Save the complete script below as repro.mjs outside the checkout, then run it from the repository root:
    node --import tsx ../repro.mjs
  3. Expected: the child prints "ARGV0":null and exits successfully. Actual on both baseline checkouts:
    {"ARGV0":"/opt/bb-fixture.AppImage","APPIMAGE":"/opt/bb-fixture.AppImage","APPDIR":"/tmp/bb-fixture-mount"}
    AssertionError [ERR_ASSERTION]: inherited argv override must not reach a user child process
    + actual - expected
    
    + '/opt/bb-fixture.AppImage'
    - null
    Both commands exit 1. The paths are synthetic fixtures, not user installation paths.

Complete reproduction artifact

import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";

const { sanitizeInheritedChildProcessEnv } = await import(
  pathToFileURL(resolve("packages/process-utils/src/environment.ts"))
);
const parentEnv = {
  ARGV0: "/opt/bb-fixture.AppImage",
  APPIMAGE: "/opt/bb-fixture.AppImage",
  APPDIR: "/tmp/bb-fixture-mount",
  PATH: "/usr/bin:/bin",
};
const childEnv = sanitizeInheritedChildProcessEnv({ env: parentEnv });
const child = spawnSync(
  process.execPath,
  ["-e", "console.log(JSON.stringify({ARGV0:process.env.ARGV0 ?? null,APPIMAGE:process.env.APPIMAGE,APPDIR:process.env.APPDIR}))"],
  { env: childEnv, encoding: "utf8" },
);
assert.equal(child.status, 0, child.stderr);
console.log(child.stdout.trim());
assert.equal(parentEnv.ARGV0, "/opt/bb-fixture.AppImage");
assert.equal(JSON.parse(child.stdout).ARGV0, null, "inherited argv override must not reach a user child process");

5. Root cause

The desktop environment builder preserves its input environment in the packaged Electron-Node case:

if (args.runtimeMode === "electron-node") {
  return { ...args.env, ELECTRON_RUN_AS_NODE: "1" };
}

The shared child-environment sanitizer only filters undefined values, NODE_ENV, and BB-prefixed keys:

if (normalizedKey === "NODE_ENV" || normalizedKey.startsWith("BB_")) {
  continue;
}
sanitizedEnv[normalizedKey === "PATH" ? "PATH" : key] = value;

Therefore ARGV0 survives. The terminal environment builder uses that result directly before applying terminal-specific values:

return {
  ...sanitizeInheritedChildProcessEnv({ env: process.env }),
  ...args.shellEnv,
  BB_TERMINAL_SESSION_ID: args.terminalId,
  ...
};

The ordinary runtime shell overlay builds PATH and bb-specific variables, rather than clearing the override. The PTY spawn receives the composed environment. The reported downstream shell behavior is consistent with this retained override, but the shell/proxy-dispatch portion was not run here.

6. Proposed fix and regression

Filter inherited ARGV0 in the existing process-utils sanitizer, the shared owner used by terminals and other user child processes. Retain APPIMAGE and APPDIR: they are unrelated metadata, and removing every AppImage variable would broaden the change unnecessarily. Do not alter packaging, desktop runtime selection, protocols, or user configuration.

The tested patch changes two files in process-utils: 11 additions and 2 deletions, 13 total changed text lines. It extends the existing sanitizer contract test instead of introducing a duplicate test or test-only production export. The extended test fails against unchanged production because ARGV0 remains in the received object; after the fix it passes and still verifies that AppImage metadata remains present.

pnpm exec turbo run test --filter=@bb/process-utils -- test/index.test.ts -t 'scrubs inherited'
pnpm exec turbo run test lint typecheck --filter=@bb/process-utils
pnpm exec turbo run test --filter=@bb/host-daemon -- src/terminals/terminal-manager.test.ts
git diff --check
git diff --numstat origin/main

Before fix: focused regression fails with one unexpected ARGV0 property. After fix: reproduction prints the following and exits 0:

{"ARGV0":null,"APPIMAGE":"/opt/bb-fixture.AppImage","APPDIR":"/tmp/bb-fixture-mount"}

Existing terminal manager suite: 36 passed. Process-utils lint and typecheck pass. The complete process-utils suite passes with 151 passed, 18 platform-specific skips using a temporary copy of the same Node binary as the runtime. No dependencies or repository files were changed for this runtime isolation.

Environment-only validation caveat: Under the ordinary Node location, an existing host-toolchain test selects the machine-installed provider instead of its temporary native-provider fixture. That same test fails on untouched trusted main. Copying the same Node executable into a temporary isolated bin directory puts a clean runtime directory ahead of the machine-global tools in the lookup path; this resolves the contamination without modifying the test, product code, or installed provider. The full suite command used was:

mkdir -p /tmp/bb-7985-runtime/bin
cp --reflink=auto /usr/local/bin/node /tmp/bb-7985-runtime/bin/node
PATH="/tmp/bb-7985-runtime/bin:$PATH" pnpm exec turbo run test --filter=@bb/process-utils --force

7. Verification

The same agent repeated the reproduction, not an independent reviewer. The second checkout was a fresh clone of the trusted target, detached at the recorded SHA; git status --short was empty after installation and the reproduction. With unchanged production code, running node --import tsx /tmp/REPORT_WORK/repro.mjs from that checkout printed the same retained override and failed the same assertion. The exact significant output from both runs appears in section 4. No ports or data directories were needed.

All root-cause links were checked against that second checkout's source. The report limits its reproduced claim to the actual environment boundary and explicitly leaves the packaged zsh/rustup symptom unexecuted. No screenshots are necessary for this nonvisual defect.

8. Related issues

A repository search found #4417, which concerns command lookup precedence rather than retained argument-zero environment state. It is not the mechanism tested here. No linked or issue-referencing open pull request was found in the issue timeline or open-PR search at investigation time.

9. Appendix

Public repository policy requires scripts, patches, and significant output to be embedded in the HTML rather than published as separate raw artifacts. Raw logs remain in local investigation storage.

Focused regression delta

--- packages/process-utils/test/index.test.ts
+++ packages/process-utils/test/index.test.ts
@@
-  it("scrubs inherited bb runtime env vars and node mode", () => {
+  it("scrubs inherited bb runtime env, node mode, and shell argv overrides", () => {
     const env: NodeJS.ProcessEnv = {
+      ARGV0: "/opt/bb-fixture.AppImage",
+      APPIMAGE: "/opt/bb-fixture.AppImage",
+      APPDIR: "/tmp/bb-fixture-mount",
@@
     expect(sanitizedEnv).toEqual({
+      APPIMAGE: "/opt/bb-fixture.AppImage",
+      APPDIR: "/tmp/bb-fixture-mount",

Minimal production delta

--- packages/process-utils/src/environment.ts
+++ packages/process-utils/src/environment.ts
@@
-    if (normalizedKey === "NODE_ENV" || normalizedKey.startsWith("BB_")) {
+    if (
+      normalizedKey === "ARGV0" ||
+      normalizedKey === "NODE_ENV" ||
+      normalizedKey.startsWith("BB_")
+    ) {

Recorded test summaries

Focused regression before fix:
Test Files  1 failed (1)
     Tests  1 failed | 12 skipped (13)

Focused regression after fix:
Test Files  1 passed (1)
     Tests  1 passed | 12 skipped (13)

Full process-utils suite, isolated Node runtime:
Test Files  22 passed | 2 skipped (24)
     Tests  151 passed | 18 skipped (169)

Existing terminal-manager suite:
Test Files  1 passed (1)
     Tests  36 passed (36)

Unchanged-main confirmation of unrelated lookup failure:
FAIL test/host-toolchain.test.ts > host toolchain recovery > finds native providers and runs the bb Node shebang with a minimal service PATH
Error: Command failed: /usr/local/bin/claude
Error: Input must be provided either through stdin or as a prompt argument when using --print

Preparation also used git fetch origin main, pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk, pnpm exec turbo run build, and pnpm exec oxfmt packages/process-utils/src/environment.ts packages/process-utils/test/index.test.ts. No code, scripts, URLs, or branches supplied by the issue were executed or fetched. Issue prose was treated only as untrusted claims; all reproduction code and the fix were derived from trusted repository evidence.

> AGENT GENERATED