Skip to content

Require local authentication on /api/v1 and the realtime socket #3708

Description

@benwaffle

Summary

The bb server authenticates host daemons on /internal/*, and since #1536 it rejects browser requests to /api/v1/* whose Origin is not trusted. Nothing else is checked. A request to /api/v1 or /ws that carries no Origin header, or one that arrives from a public hostname rebound to 127.0.0.1, is accepted with no credential at all. That means any process running as any user on the same machine, and any web page that can make a rebound request look like a local process (#1530 documented that these are header-indistinguishable), can list threads, read transcripts, send messages, and start terminals.

I would like the server to mint a per-install secret and require it on /api/v1, the SPA shell, and the /ws upgrades, while keeping the browser and CLI flows seamless. I have a working design on my fork and am offering to upstream it once the shape is agreed.

Versions and environment

Steps to reproduce

  1. Start bb normally (desktop app or npx bb-app). It listens on 127.0.0.1:38886.

  2. From any shell on the same machine, as any user:

    curl -s http://127.0.0.1:38886/api/v1/threads | head -c 300
  3. Observe the thread list. No header, cookie, or token was sent. POST routes behave the same way; I stopped at read-only requests for this report.

Expected vs actual

Expected: 401 until a credential is presented.

Actual: 200 with the thread list. The Origin guard does not apply because curl sends no Origin.

Evidence

  • Daemon-only auth in apps/server/src/server.ts:
    const daemon = await verifyAuthenticatedDaemon(
    deps,
    context.req.header("authorization"),
    );
    setAuthenticatedDaemon(context, daemon);
    } catch {
    return unauthorizedResponse();
    }
    return next();
    });
    const pluginService = createPluginService({
  • Origin guard, which only fires when a browser Origin is present:
    return next();
    }
    const problem = browserRequestProblem(context, deps);
    if (problem !== null) {
    throw new ApiError(problem.status, "forbidden_origin", problem.error);
    }
  • Rebound public hostnames are header-indistinguishable from local processes #1530 (closed in the Aug 13 sweep) records that a rebound public hostname sends neither Origin nor Sec-Fetch-*, so header-based guards cannot see it.

What I ruled out

Proposed design

Implemented on my fork as benwaffle@4709172, with one follow-up rule from benwaffle@6716c05:

  • On first start the server writes a random token to <dataDir>/api-token (mode 0600). The log records only the path.
  • Every /api/v1 request, the SPA shell, and /ws upgrades must present it either as Authorization: Bearer or as an HttpOnly; SameSite=Strict cookie. GET /auth/session?token=… installs the cookie and redirects to the app, so the launcher prints that session link as the app URL and the desktop main process installs the cookie before loading the window.
  • Loopback-bound servers also reject foreign Host headers, which closes the rebound-hostname path on its own.
  • The CLI and Node SDK read BB_API_TOKEN or the token file. The in-process plugin SDK receives the token from the server. The host daemon receives it in the session-open response and layers it onto the agent shell environment as BB_API_TOKEN, so bb inside an agent shell keeps working, including on other enrolled machines that never see the token file. This is a HOST_DAEMON_PROTOCOL_VERSION bump.
  • Bearer-authenticated requests skip the browser Origin guard: the guard exists to stop cross-origin pages from riding the cookie, and a caller that presents the secret itself has already proven possession. Cookie-authenticated requests keep the Origin requirement.

Open questions I expect reviewers to raise: mobile and Connect relay clients (a ServerAccessGrant header fits), nested servers using the Account Pooler parent URL (#3654), and upgrade ordering for enrolled remote daemons.

Tests on the fork: apps/server/test/security/api-token-auth.test.ts, apps/server/test/security/api-origin-guard.test.ts, apps/host-daemon/src/app.test.ts.

Suggested priority and effort

High priority: it affects every install, there is no workaround short of not running other software on the machine, and the exposed operations include command execution through terminals. Effort is medium-to-large because of the client plumbing, but the fork commit shows the full scope (29 files).

AGENT GENERATED

Activity

  1. added
    security
    on Sep 15, 2026
  2. bb-slop-cop commented on Sep 15, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Applied and verified Type: Feature, Priority: Urgent, Effort: High, label: security. No existing classification values were present.

    Trusted main explicitly tests acceptance of callers without Origin. Requiring local credentials adds an authentication contract; Urgent reflects the reported security exposure, and High reflects the cross-client design work.

    Final Type is Feature, so reproduction report and fix steps were skipped. No PR opened because authentication and security-boundary changes are outside the simple-fix rules.

    AGENT GENERATED

  3. BartSoj commented on Sep 25, 2026

    @BartSoj

    A consumer to keep in the design: plugins that serve sandboxed documents (sandbox without
    allow-same-origin). Such a frame has an opaque origin: it sends Origin: null, and its
    requests are cross-site — measured live on bb Connect 2026-09-25: Chrome 146 attaches the SameSite=Lax
    cookie to none of them; iPhone Safari 26.6 attaches it to an <img>, while a fetch() from the frame is
    refused and a <video> still fails. So what reaches the server already differs by browser. Today on loopback it can still load
    its own files because the local API asks for nothing; with a required secret it will not, exactly
    as already happens over bb Connect (#3617).

    Not asking to weaken the proposal — only that its credential have a path-scoped, GET-only,
    short-lived form a plugin can hand to a document it serves (the same shape proposed in #3617), so
    both surfaces get one mechanism rather than two.

    AGENT GENERATED

  4. nateberkopec commented on Sep 28, 2026

    @nateberkopec

    Not agent but I agree with this. I'd like individual threads to be pretty well insulated from other threads, right now you can you just ping /api/v1 and potentially read/modify everything else that's going on.

  5. vipanait commented on Oct 9, 2026

    @vipanait

    We'd like to see this land as well. We're evaluating bb as a locally-run tool for a team of developers, and an unauthenticated /api/v1 / /ws on loopback (with terminal and command execution behind it) is the first thing we'd need closed before recommending it internally. The design described here — per-install token file at 0600, Bearer or HttpOnly; SameSite=Strict cookie via /auth/session, BB_API_TOKEN passed into the agent shell, and the Host authority check on loopback — matches what we'd have built ourselves. Is there a maintainer view on the shape?

    AGENT GENERATED

  6. SawyerHood commented on Oct 19, 2026

    @SawyerHood
    Collaborator

    Consolidated unauthenticated-loopback report and sender-provenance requirements

    Consolidating #4529 into this canonical tracker at the maintainer's request following the open-issue duplicate sweep.

    #4529 supplies a concrete bb 0.44.0 Linux reproduction: an unauthenticated loopback request succeeds, and a CLI send with no BB_THREAD_ID is recorded as initiator=user / senderThreadId=null. Setting another thread's BB_THREAD_ID can spoof that sender. The original commands and observed event shape remain in #4529.

    The authentication portion belongs here. Preserve these additional requirements explicitly:

    • Separate privileged installation/UI credentials from scoped agent/thread credentials; do not hand the unrestricted install secret to every agent.
    • Derive agent sender identity from a verified credential, not a caller-controlled environment variable or claimed thread ID.
    • Preserve source provenance (UI session, CLI, plugin identity) when recording user-originated turns so consumers can distinguish them.
    • Document the local-process trust boundary and validate spoofing attempts as well as unauthenticated access.

    A single shared API token does not automatically solve sender attribution. Coordinate the provenance work with #3621 and host-verified authorization in #1541; if delivered separately, keep it linked and outstanding rather than closing it with the basic authentication fix.

    #4529 is being closed for consolidation, not because the exposure is resolved or all of its scope is an exact duplicate.

    AGENT GENERATED

  7. ShiawasenaHoshi commented on Nov 23, 2026

    @ShiawasenaHoshi

    On the first checklist item (scoped agent credentials), two concrete points from a setup where agents already run as a separate OS user (bb 0.49.0; code references checked against current main):

    1. Operator-only operations. Even with OS isolation, an agent shell can resolve its own approval (POST /api/v1/threads/:id/interactions/:interactionId/resolve), install or enable plugins, and change settings, providers and skills. A thread-scoped credential that gets 403 on exactly these routes would close that and keep every normal agent workflow working. plugin-rpc-caller.ts already mints per-caller tokens, but resolve(undefined) returns client, so a request with no token is not treated as an agent.
    2. POST /internal/hosts/enroll-key is exempt from daemon auth and only asserts a loopback peer (apps/server/src/internal/hosts.ts), so by my reading of the code any local process can mint an enrollment key and then enroll as a host daemon. The design described above covers /api/v1, the SPA shell and /ws, so this route would stay as it is.

    Happy to prototype (1) and (2) with tests on top of the proposed design, if that's useful.

    AGENT GENERATED

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

    security

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions