Skip to content

Guard managed jobs against default-server CLI writes #5838

Open

Description

@brsbl

Summary

A managed QA job can send a bare bb plugin config write to the default production server. Add an accidental-routing guard in the CLI transport: reject non-GET/HEAD/OPTIONS requests to loopback port 38886 when HOST_CARE_JOB_ID is nonempty, unless BB_ALLOW_DEFAULT_SERVER_WRITES=1.

The reported October 20, 2026 incident overwrote a production PostHog API key. The original script's job ancestry is unknown, so this guard cannot be claimed to have prevented that exact invocation.

Versions and environment

Reproduced from source at b0bb68655adcc6cd79e495d3484f4011a0640e2e, Linux, in a real host-care job. All fetch calls were intercepted in process; no request reached production.

Steps to reproduce

  1. Build @bb/cli through Turbo.
  2. Save a fetch stub that logs and intercepts every request locally as mock-fetch.mjs.
  3. Run with a disposable log path:
env -u BB_CLI -u BB_PROJECT_ID -u BB_THREAD_ID -u BB_ENVIRONMENT_ID \
  HOST_CARE_JOB_ID=guard-repro BB_CLI_ERROR_LOG=0 \
  BB_SERVER_URL=http://127.0.0.1:38886 GUARD_PROBE_LOG="$PWD/requests.jsonl" \
  node --import "$PWD/mock-fetch.mjs" apps/cli/dist/index.js \
  plugin config guard-probe set probe fake-qa-value --json

Expected vs actual

Expected: nonzero exit, JSON error code managed_job_default_server_write, and zero PUT calls.

Observed exit code: 0. Intercepted requests:

{"url":"http://127.0.0.1:38886/api/v1/plugins/guard-probe/settings","method":"GET"}
{"url":"http://127.0.0.1:38886/api/v1/plugins/guard-probe/settings","method":"PUT"}

Evidence

What was ruled out

  • Duplicate search for managed job production writes and PostHog QA found no matching issue.
  • Thread context does not redirect an explicit isolated URL; verified by the investigation.
  • The regression reproduces with all transport stubbed, without touching production settings.

Acceptance

Cover implicit and explicit default URLs, loopback aliases, read methods, alternate ports, absent markers, exact override, Request methods/init overrides, BB_CLI re-exec, core SDK writes, and both plugin JSON command forms. Preserve behavior outside managed jobs. No host-care runtime changes.

AGENT GENERATED

Activity

  1. added theissue type on Oct 20, 2026
  2. added
    cli
    confirmed-repro
    on Oct 20, 2026
  3. bb-slop-cop commented on Oct 20, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · High priority · Low effort. Added missing classifications and cli; no existing values were replaced.
    • Reproduction and root-cause report: REPRODUCED, root-cause confidence high; reproduction label: confirmed-repro.
    • Root cause: the CLI defaults to the production loopback port, while its shared HTTP transport forwards mutations without checking the managed-job marker.
    • Evidence: two clean trusted origin/main checkouts at b0bb68655adcc6cd79e495d3484f4011a0640e2e produced identical results. Marked implicit-default, explicit-default and localhost cases exited 0 and dispatched PUT to the intercepted transport. The guard regression failed as expected; all six existing plugin-config tests passed. No production HTTP request was sent; historical incident causality remains unverified.
    • No new PR: existing open #5839 already links this issue. Its code was not executed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliconfirmed-repro

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions