← reports

#5092 · Literal environment paths are saved without explaining expansion semantics

BugPriority: MediumEffort: Lowhostcliconfirmed-repro Issue on GitHubOctober 7, 2026 · base 68a1e8b7aa84fbd836eb8825e4d042ae0c52e74a

Verdict: REPRODUCED · Root-cause confidence: high, for literal propagation and missing CLI guidance.

1. TL;DR

Machine environment values are stored and delivered as literal strings, not as shell expressions. Three home-relative spellings survive a real CLI save, HTTP API validation, encrypted SQLite storage, daemon environment assembly, and execution in a child shell unchanged. The CLI emits no notice, and listing metadata deliberately hides saved values. A generic child that uses such a value as a directory path creates a relative directory inside its working tree; an absolute-path control creates its directory outside the working tree. This confirms the configuration/feedback defect without running Claude Code or accessing any real credentials.

Literal string preservation is appropriate for opaque secrets; the defect is the undisclosed path interpretation, not proof that all environment values should undergo interpolation.

2. Claims vs findings

ClaimStatusEvidence
Home-relative spellings reach child environments unchanged.VerifiedReal CLI, real server route, encrypted in-memory database, production resolver, production daemon helper, and a real /bin/sh process; repeated in a second clean checkout.
The CLI does not disclose that values remain literal.VerifiedAll three saves exit successfully with empty stderr. The new notice-contract assertion fails with exactly those three values. CLI help only mentions stdin and trailing-newline removal.
Saved values are concealed in settings.VerifiedActual save responses contain value:null and secret:true. UI code defaults the input to password and disables reveal for saved values; static inspection only.
The editor supplies no expansion guidance.Verified in sourceThe settings description discusses scope, not path semantics; the row renders supplied captions and validation errors, with no expansion notice. No visual desktop or browser reproduction is claimed.
Such a value can create a literal path inside a workspace.Verified for a generic childA real Node child calls mkdirSync with the delivered value, creating relative paths for all three spellings. This is a path-consumer demonstration, not a simulated Claude login test.
Claude Code creates a new config directory and reports a login failure on macOS.Unverified hereNo Claude Code executable, authenticated directory, macOS system, or provider turn was used. Provider-specific behavior remains a reporter claim.
The problem is limited to Claude Code.Refuted as a limitationThe independent reproduction uses a synthetic variable and no provider.
An absolute path avoids the relative-workspace-directory problem.Verified for a generic childThe absolute-path control remains literal but creates its directory under a synthetic home outside the workspace. This does not verify provider login.

3. Environment

4. Minimal reproduction

Run the trusted checkout's normal install/build commands, then save the inline test at the stated path and run it through Turbo. Exit 1 is the expected evidence of the bug, not an infrastructure failure.

git clone https://github.com/get-bb/bb.git bb-5092
cd bb-5092
git checkout --detach 68a1e8b7aa84fbd836eb8825e4d042ae0c52e74a
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build

# Save the test below as apps/server/test/public/issue-5092-repro.test.ts.
SLOPCOP_EVIDENCE_PATH=/tmp/5092-first-evidence.txt pnpm exec turbo run test --env-mode=loose --filter=@bb/server -- test/public/issue-5092-repro.test.ts

# Repeat in a second clean checkout, with the same test file.
git worktree add --detach ../bb-5092-verify 68a1e8b7aa84fbd836eb8825e4d042ae0c52e74a
cd ../bb-5092-verify
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
SLOPCOP_EVIDENCE_PATH=/tmp/5092-second-evidence.txt pnpm exec turbo run test --env-mode=loose --filter=@bb/server -- test/public/issue-5092-repro.test.ts
  1. The test starts the repository's real HTTP test server with no provider registrations.
  2. It saves three shell-style path strings, plus an absolute-path control, using the compiled CLI's actual stdin handling and SDK transport.
  3. It confirms the API masks saved values, decrypts through the production settings resolver, and applies the production daemon environment helper.
  4. It starts a real shell to inspect the synthetic variable and a separate real Node directory consumer. Assertions verify literal values and the resulting path locations.
  5. Finally it expects a path-semantics notice. This assertion fails because all three relative spellings are accepted without a notice.

Expected vs actual

Expected user-visible contract: if the path expression is kept literal, saving it explains that shell expansion does not occur. No expectation of interpolating opaque secrets is imposed.

Actual first-run output:

Real CLI -> real HTTP API -> encrypted in-memory database -> daemon environment -> child shell
server=http://127.0.0.1:47813; dataDir=/tmp/TEMP-DATA; database=:memory:; provider=none
input=$HOME/synthetic-config; shell=$HOME/synthetic-config; stderr=""; API hides saved value=true; directory=$HOME/synthetic-config
input=${HOME}/synthetic-config; shell=${HOME}/synthetic-config; stderr=""; API hides saved value=true; directory=${HOME}/synthetic-config
input=~/synthetic-config; shell=~/synthetic-config; stderr=""; API hides saved value=true; directory=~/synthetic-config
input=<synthetic-home>/synthetic-config; shell=<synthetic-home>/synthetic-config; stderr=""; API hides saved value=true; directory=outside workspace
Missing path-semantics notices: 3

Actual focused-test result:

AssertionError: Unexpanded path values are saved without a notice
Expected: []
Received:
[
  "$HOME/synthetic-config",
  "${HOME}/synthetic-config",
  "~/synthetic-config",
]
Test Files  1 failed (1)
Tests       1 failed (1)
Exit status 1 (expected reproduction failure)

Complete reproduction test

This is investigator-authored code derived from trusted repository services, not a copied issue script. It uses existing test infrastructure and adds no dependency or production seam. The only value fixtures and filesystem accesses are synthetic.

import { spawn } from "node:child_process";
import { existsSync } from "node:fs";
import { mkdir, writeFile } from "node:fs/promises";
import { join, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { getAppSettings, setAppSettings } from "@bb/db";
import { expect, it } from "vitest";
import { startTestServer } from "../helpers/test-app.js";
import { resolveUserMachineEnvironment } from "../../src/services/machines/environment-settings.js";
import { operationEnvironment } from "../../../host-daemon/src/operation-environment.js";

function childOutput(
  file: string,
  args: string[],
  options: { cwd: string; env: NodeJS.ProcessEnv; input?: string },
): Promise<{ stdout: string; stderr: string }> {
  return new Promise((resolveOutput, reject) => {
    const child = spawn(file, args, options);
    let stdout = "";
    let stderr = "";
    child.stdout.on("data", (chunk: Buffer) => {
      stdout += chunk.toString();
    });
    child.stderr.on("data", (chunk: Buffer) => {
      stderr += chunk.toString();
    });
    child.on("error", reject);
    child.on("close", (code) => {
      if (code !== 0) reject(new Error(`Child exited ${code}: ${stderr}`));
      else resolveOutput({ stdout, stderr });
    });
    child.stdin.end(options.input);
  });
}

it("discloses literal path handling when saving through the real CLI", async () => {
  const harness = await startTestServer({ seedFirstPartyProviders: false });
  const evidence: string[] = [];
  try {
    setAppSettings(harness.db, {
      ...getAppSettings(harness.db),
      machineGitCredentialsEnabled: false,
    });
    const workspace = join(harness.config.dataDir, "workspace");
    const syntheticHome = join(harness.config.dataDir, "home");
    await mkdir(workspace);
    await mkdir(syntheticHome);
    const cli = fileURLToPath(
      new URL("../../../cli/dist/index.js", import.meta.url),
    );
    const base = {
      HOME: syntheticHome,
      PATH: "/usr/bin:/bin",
      BB_DATA_DIR: harness.config.dataDir,
      BB_SERVER_URL: harness.baseUrl,
    };
    evidence.push(
      "Real CLI -> real HTTP API -> encrypted in-memory database -> daemon environment -> child shell",
    );
    evidence.push(
      `server=${harness.baseUrl}; dataDir=${harness.config.dataDir}; database=:memory:; provider=none`,
    );
    const missingWarnings: string[] = [];
    for (const value of [
      "$HOME/synthetic-config",
      "${HOME}/synthetic-config",
      "~/synthetic-config",
      join(syntheticHome, "synthetic-config"),
    ]) {
      const result = await childOutput(
        process.execPath,
        [cli, "machine", "env", "set", "SYNTHETIC_PATH", "--json"],
        { cwd: workspace, env: base, input: `${value}\n` },
      );
      const response: unknown = JSON.parse(result.stdout);
      expect(response).toMatchObject({
        variables: [
          { name: "SYNTHETIC_PATH", value: null, secret: true, note: null },
        ],
      });
      const entries = await resolveUserMachineEnvironment(
        harness.db,
        harness.config.dataDir,
      );
      const env = operationEnvironment(entries, base);
      const shell = await childOutput(
        "/bin/sh",
        ["-c", 'printf "%s" "$SYNTHETIC_PATH"'],
        { cwd: workspace, env },
      );
      expect(shell.stdout).toBe(value);
      await childOutput(
        process.execPath,
        [
          "-e",
          'require("node:fs").mkdirSync(process.env.SYNTHETIC_PATH, { recursive: true })',
        ],
        { cwd: workspace, env },
      );
      expect(existsSync(resolve(workspace, value))).toBe(true);
      const absolute = value.startsWith(syntheticHome);
      const displayValue = absolute
        ? "<synthetic-home>/synthetic-config"
        : value;
      const location = absolute
        ? "outside workspace"
        : relative(workspace, resolve(workspace, value));
      evidence.push(
        `input=${displayValue}; shell=${displayValue}; stderr=${JSON.stringify(result.stderr)}; API hides saved value=true; directory=${location}`,
      );
      if (
        !absolute &&
        !/literal|not expanded|absolute path/iu.test(result.stderr)
      ) {
        missingWarnings.push(value);
      }
    }
    evidence.push(`Missing path-semantics notices: ${missingWarnings.length}`);
    const artifact = process.env.SLOPCOP_EVIDENCE_PATH;
    if (artifact) await writeFile(artifact, `${evidence.join("\n")}\n`);
    expect(
      missingWarnings,
      "Unexpanded path values are saved without a notice",
    ).toEqual([]);
  } finally {
    await harness.close();
  }
}, 30_000);

5. Root cause

Input processing does not invoke a shell. apps/cli/src/commands/machine-environment.ts:21 limits stdin and removes one trailing newline, but otherwise preserves its content. apps/cli/src/commands/machine-environment.ts:78 sends the value through the SDK and prints masked metadata; it does not issue a semantic notice.

  return Buffer.concat(chunks)
    .toString("utf8")
    .replace(/\r?\n$/u, "");

The boundary schema packages/server-contract/src/api/machine-environment.ts:7 checks type, length, and NUL bytes, not shell/path semantics. The server's apps/server/src/services/machines/environment-storage.ts:182 encrypts the exact supplied value, and apps/server/src/services/machines/environment-settings.ts:10 decrypts it into a contributed environment entry without interpolation.

The final decisive assignment is apps/host-daemon/src/operation-environment.ts:4:

  for (const entry of entries) {
    if (typeof entry.value === "string") env[entry.name] = entry.value;
    else {
      if (!base.BB_SERVER_URL)
        throw new Error("Host environment requires BB_SERVER_URL");
      env[entry.name] = `${base.BB_SERVER_URL}${entry.value.serverPath}`;
    }

Both apps/host-daemon/src/terminals/terminal-manager.ts:608 and apps/host-daemon/src/plugin-host-manager.ts:294 use this helper. A child shell expanding the variable once does not recursively evaluate dollar signs or tildes inside its value. A path consumer therefore receives an ordinary relative string; directory resolution uses its current working directory, not HOME.

The editor's apps/app/src/components/settings/MachineEnvironmentSettings.tsx:270 describes global/project scope but not literal interpretation. Its apps/app/src/components/settings/MachineEnvironmentSettings.tsx:628 defaults to a concealed input, receives no saved plaintext, and disables saved-value reveal. The API's apps/server/src/services/machines/environment-settings.ts:34 deliberately replaces saved values with null. This is sensible secret protection but makes missing save-time guidance consequential.

Underlying cause: a general-purpose secret-preserving string setting lacks discoverable interpretation guidance for users entering path syntax. The daemon's literal assignment alone is not evidence of an unsafe expansion bug that should be fixed by indiscriminately interpreting all secret strings.

6. Proposed fix and autopilot decision

Preserve all bytes of submitted secrets. Add clear literal-value guidance at the editing boundary, CLI save feedback/help, and discoverable configuration documentation; recommend an absolute path for directory-valued settings. A non-blocking notice should not echo the submitted value or reveal saved plaintext. Keep SDK behavior documented and consistent without changing stored values.

No pull request is opened. A complete warning-only repair spans the app and CLI, so it fails this autopilot's requirement that a fix stay in one existing subsystem. Interpolation is not a safe one-subsystem substitute: it changes the interpretation of general-purpose secret values and requires a product-policy decision. The investigator-authored focused test demonstrates the missing-notice failure before any production edits; no speculative production fix, branch, commit, or push was made to get-bb/bb.

No open linked pull request was present in the issue timeline, and an open-PR search for the numeric issue reference also found none. This does not justify relaxing the simple-fix gate.

7. Related issues

Repository search independently identified #4070 (directory environment inheritance) and #4384 (environment profiles). These concern environment selection/inheritance, not disclosure of literal path-string interpretation; they were reviewed for classification context only. No duplicate conclusion is claimed.

8. Verification

The same agent repeated the reproduction in a second clean trusted checkout at the same recorded commit. Only the investigator-authored test was copied; production code remained pristine. The second run used newly allocated HTTP and data-directory resources. It reproduced the same successful CLI saves, concealed metadata, literal shell values, three workspace-relative paths, and final notice assertion failure. This is a repeat verification, not independent verification by another agent.

Real CLI -> real HTTP API -> encrypted in-memory database -> daemon environment -> child shell
server=http://127.0.0.1:28722; dataDir=/tmp/TEMP-DATA; database=:memory:; provider=none
input=$HOME/synthetic-config; shell=$HOME/synthetic-config; stderr=""; API hides saved value=true; directory=$HOME/synthetic-config
input=${HOME}/synthetic-config; shell=${HOME}/synthetic-config; stderr=""; API hides saved value=true; directory=${HOME}/synthetic-config
input=~/synthetic-config; shell=~/synthetic-config; stderr=""; API hides saved value=true; directory=~/synthetic-config
input=<synthetic-home>/synthetic-config; shell=<synthetic-home>/synthetic-config; stderr=""; API hides saved value=true; directory=outside workspace
Missing path-semantics notices: 3

No change in verdict or root-cause explanation was needed after the second run. The report explicitly narrows the provider claim: Claude Code authentication and the macOS desktop were not tested.

Existing focused suites passed unchanged: host-daemon operation/machine environment, 3 tests; CLI machine environment command-output suite, 10 tests. Both full builds passed. The new reproduction test intentionally remains failing in local detached checkouts; it is not a landed change.

9. Appendix

Issue title, body, code blocks, links, and any comments were treated as untrusted claims. No issue-supplied command, script, branch, patch, or external link was executed or fetched. There were no comments at investigation time. Only repository evidence from trusted main, installed reporting tooling, and investigator-authored test/report code was executed. Raw logs and the test remain outside the public report repository; the complete reproducible test and sanitized results are inline here.

Verification commands

pnpm exec turbo run test --filter=@bb/host-daemon -- src/operation-environment.test.ts src/machine-environment.test.ts
pnpm exec turbo run test --filter=@bb/cli -- src/__tests__/command-output/machine-environment.test.ts
git diff --check
git fetch origin main
git rev-parse origin/main

GitHub reads checked repository visibility/identity, current issue properties, all available comments and cross-references, label options, similar issue classifications, and open PR metadata. Classification writes used the supplied SlopCop GitHub wrapper. Report publication applies the same wrapper to any GitHub API writes.