Repository navigation
Route agent bb calls through the machine proxy after a server move - #4277
SawyerHood wants to merge 1 commit into
Conversation
On a machine whose config.json names a bb connect server, the packaged launcher replaced the BB_SERVER_URL the host daemon gives threads (its authenticated loopback proxy) with the saved serverUrl, so agent bb calls reached the public gateway without credentials and failed with 401. The bundled CLI also ignored BB_SERVER_HEADERS, so the same calls from the user's own terminal failed too. The launcher's CLI path now uses a caller-supplied BB_SERVER_URL and passes config serverHeaders only when the target is the saved serverUrl. Daemon and server launches keep config first. The CLI attaches BB_SERVER_HEADERS only to requests for its server origin. Fixes #4243 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
|
Technical review of head In I reproduced this with Node 24.12.0, two disposable loopback HTTP servers on different ports, and a synthetic credential. I executed the functions extracted from this PR with TypeScript types stripped and the config loaders supplied by the isolated harness; this was not a full packaged Connect e2e. Reproduction:
Control: calling Please prevent credential-bearing requests from following redirects across origins, or handle redirects with the origin binding enforced at every hop. Add a regression test using two local servers. This is a conditional security defect in the proposed change, not evidence of a real credential compromise and not an explanation for the automated closure of this PR.
|
Human comments
What was wrong
A host daemon on a machine enrolled with a bb connect server gives each thread
BB_SERVER_URLpointing at its loopback proxy, which adds the machine'sserverHeaders. Such machines include the old computer after a server move. When an agent ran the packagedbblauncher,resolveServerUrlputconfig.jsonserverUrlahead of that env var, and the launcher rewroteBB_SERVER_URLto the public gateway address before re-running$BB_CLI. The bundled CLI never readBB_SERVER_HEADERS, so these direct calls carried no credential and got401. The same gap also brokebbin the user's own terminal on those machines.The config-first order is still needed for
bb-host-daemon/bb-app. A daemon relaunched from a thread shell must not adopt its predecessor's proxy address, so this PR keeps that order for daemon and server launches and changes only the CLI path.What changed
packages/bb-app/src/launcher.ts:runBbCliresolves in a newclimode. In that mode a non-blankBB_SERVER_URLfrom the caller wins over the savedserverUrl. The launcher passes configserverHeaders/machineCredentialto the CLI asBB_SERVER_HEADERSonly when the target is the savedserverUrl, so the credential never goes to an address it wasn't issued for. It also stops being copied into thread CLI processes. Daemon and server launches (managed/local) are unchanged.apps/cli/src/client.ts,packages/config/src/cli.ts:cliFetch, which carries every CLI server request including SDK calls, attachesBB_SERVER_HEADERSonly when the request origin matches the CLI'sBB_SERVER_URL.docs/configuration.md(BB_SERVER_URLrow, machine header paragraphs),packages/bb-app/README.md(CLI and SDK resolution), and thebb guide machinestemplate.This goes past the issue's suggested fix, which was to prefer env everywhere. Env-first applies only to the CLI, and the header binding plus CLI header support are new.
How you verified
New tests fail on
origin/mainand pass with the change:packages/bb-app/test/index.test.ts: in CLI mode a caller URL wins and gets noBB_SERVER_HEADERS. This test also runs the realrunBundledCliCommandchild. Unset, blank, and same-URL overrides keep the saved URL and its headers. Without config, the CLI uses the default local server. The existing config-over-env test still passes; it is renamed to say it covers non-CLI launches.apps/cli/src/__tests__/client.test.ts: real local HTTP servers. Headers go only to the configured origin, both as a URL string and as aRequest, and SDK calls carry them. Nothing is sent whenBB_SERVER_HEADERSis unset.pnpm exec turbo run typecheck lint --filter=bb-app --filter=@bb/cli --filter=@bb/config --filter=@bb/sdk --filter=@bb/templates,pnpm exec turbo run test --filter=bb-app --filter=@bb/cli --filter=@bb/config, andpnpm exec turbo run smoke:tarball --filter=bb-appwithpioff PATH: all pass.Real Connect migration e2e using only the repo's local
pnpm cloud:devgateway, fresh disposable data dirs and test credentials. Setup: installed packaged tarballs → paired server A with the gateway → enrolled B → ranbb server move --to Bin connect mode. Afterwards A'sconfig.jsonheld the gatewayserverUrlplusserverHeaders. A terminal opened on A through the moved server hadBB_SERVER_URL=http://127.0.0.1:<proxy>andBB_CLIset, and noBB_SERVER_HEADERS. Packagedbb.jsresults, cross-checked against the gateway request log:project list --json,machine list --json)BB_SERVER_URL+BB_CLI)401,--helpshows gateway URL--helpshows proxy URL; CLI child has noBB_SERVER_HEADERSBB_SERVER_URL)401"$BB_CLI"in the thread env (control)An isolated harness with a real packaged server, a header-checking gate and the daemon's real
startMachineAuthProxyreproduced the same table. It also covered a blankBB_SERVER_URL, which falls back to the saved URL and authenticates. An explicitBB_SERVER_URLpointed at an unrelated server received no credential header, and the credential never appeared in any log or output.Fixes #4243
🤖 Generated with Claude Code