Skip to content

bb Connect: a plugin serving a sandboxed document cannot serve that document's own files #3617

Open

Description

@BartSoj

The workflow

I maintain a bb plugin that gives each session an HTML page the reader opens on their phone. The
page is a directory in thread storage: index.html plus its own stylesheet, scripts and data
files, referenced relatively, exactly as a static site would.

  1. An agent writes index.html and data.js beside it into its session's storage.
  2. The reader opens the page. The plugin serves index.html into an iframe with
    sandbox="allow-scripts allow-forms", because the document is agent-authored and must hold no
    host authority.
  3. The document requests data.js.

On loopback, step 3 works. Over bb Connect it does not, and nothing errors: the page shell,
the chrome and every capability call work, and only the page's own content is missing. A reader saw
a fully functional interface reporting that a 300-row dataset was empty. The developer cannot see
this from their own machine, because a local bb requires no credential and a remote one does.

What happens today

Unauthenticated GETs, no cookie, from one machine on 2026-09-09 (bb 0.42.1):

Path loopback 127.0.0.1:38886 <handle>.getbb.app
/api/v1/plugins/<plugin>/http/page?session=… 200 401
/api/v1/threads/<id>/thread-storage/files/index.html 200 401
/api/v1/health (does not exist) 404 401
/api/v1/plugins/nonexistent-xyz/http/page 404 401

The last row is the one that identifies the layer: a plugin that does not exist returns bb's own
404 locally and a 401 remotely. The remote responses carry server: cloudflare and a cf-ray,
and their body is the Connect sign-in gate — so the refusal happens at the edge, before bb is
reached at all. Re-checked 2026-09-13: a Connect port share (<handle>--<port>.getbb.app) answers
the same 401 to a cookieless request, including the CORS preflight.

Observed (above). What I think the cause is, labelled as inference:

  • The gate is the end of the worker's credential ladder — no session cookie and no desktop cookie
    ⇒ signInPage(...):
    const cookieHeader = request.headers.get("cookie");
    const cookie = parseCookie(cookieHeader, runtime.sessionCookieName);
    const desktopCookie = parseCookie(
    cookieHeader,
    runtime.desktopSessionCookieName,
    );
    const appUrl = runtime.accountAppUrl;
    if (!cookie && !desktopCookie)
    return signInPage(label, appUrl, url.toString());
    const verifiedSession = cookie
    ? await verifySessionCookieDetails(cookie, env.BETTER_AUTH_SECRET, db)
    : null;
    const sessionUserId = verifiedSession?.userId ?? null;
    const desktopUserId = desktopCookie
    ? await verifyDesktopSessionCookie(desktopCookie, env.BETTER_AUTH_SECRET)
    : null;
    if (!sessionUserId && !desktopUserId) {
    return signInPage(label, appUrl, url.toString());
    }
  • The sandboxed frame has an opaque origin. Its document request is issued by the trusted
    parent, whose site-for-cookies is the Connect host, so the SameSite=Lax cookie is attached and
    the document loads. Every subresource request issued from inside that frame has an opaque
    origin in its ancestor chain, so its site-for-cookies is null, the request counts as cross-site,
    and a Lax cookie is not attached.
  • Both Connect cookies are Lax:
    await args.cookieStore.set({
    domain: cookie.domain,
    expirationDate: cookie.expiresAt / 1000,
    httpOnly: true,
    name: cookie.name,
    path: "/",
    sameSite: "lax",
    secure: remoteOrigin.startsWith("https://"),
    url: remoteOrigin,
    value: cookie.value,
    });

I could not instrument the last point directly — that needs devtools on the authenticated remote
origin, which I do not have. It is the only account consistent with the measurements above, but I
am marking it inference rather than presenting it as fact.

This is not specific to my plugin. It applies to any plugin serving sandboxed content over
Connect, which is the shape the plugin HTTP surface invites.

What I would expect

A page's own files reach it on every origin the page itself reaches.

Concretely: a fourth rung on the worker's credential ladder — a short-lived, signed, GET-only
grant, scoped to one user, one handle and one plugin, that the worker verifies and strips before
forwarding.

It has to ride in the URL path, not a query parameter: relative URL resolution drops the query,
so a query parameter never reaches a subresource, which is the entire problem. Shape:

/api/v1/plugins/<pluginId>/http/__grant/<token>/<rest...>

A document served under that prefix resolves style.css to the same prefix automatically.

Prototype: https://github.com/BartSoj/bb/tree/feat/connect-page-grant — one commit on 9e16411.

Mint endpoint beside the other /api/connect/* handlers, authenticated by the existing cookie
ladder; verification rung between the machine-credential rung and the cookie check; token is the
same HMAC payload scheme as the desktop session cookie (extracted to a shared module, existing
caller rewired, its tests unchanged); 1 hour TTL, matching DESKTOP_SESSION_TTL_MS. Refused:
non-GET/HEAD, a different user, handle or plugin, a --<port> share target, /internal, a
non-plugin path, percent-encoded traversal, a tampered signature. It bypasses serveWithCache so
the token never becomes an edge cache key, and it forwards through requestForTunnelDo, so the
same inbound headers are stripped as on every other rung, the machine-id header included.
pnpm exec turbo run test --filter=@bb/connect: 6 files, 133 tests pass; typecheck passes; the
rung was mutation-checked.

Heads-up: the unmerged branch bb/mobile-perf/connect-tunnel (last commit 2026-08-19)
rewrites the cookie check exactly where this rung sits. If that lands first, the rung moves with
it.

This depends on #1632. A path-segment grant is only serveable once a plugin can match a path
prefix; today plugin routes match exactly. See my comment there.

Context and alternatives

  • SameSite=None on the Connect cookies. Two lines and it would work. Rejected: it attaches
    the cookie to every cross-site request to the Connect domain, including subresource GETs that
    carry no Origin header for bb's own origin checks to reject. That is a CSRF widening across
    the product to fix one feature. Partitioned (CHIPS) would mitigate it, but I cannot test
    browser support here, and it is a change to the whole auth system rather than to this feature.
  • Serving the files from a plugin prefix route with auth: "none". Does not help on its own —
    the edge 401s it before bb sees the route's auth mode. I believed this was the fix until the
    fourth row of the table above; recording it so nobody else spends the time.
  • What I ship, and am keeping: the plugin resolves each relative reference when it serves the
    document and rewrites it to a data: URL, so the entry document carries its own files. It works
    on every origin. So this does not block my plugin — but every plugin that serves sandboxed
    content over Connect has to discover the problem and build something like that resolver, it
    costs document size (plus a third for base64), and page script still cannot fetch() its own
    files. The grant would make the ordinary static-site shape just work.
  • Not a duplicate: searched open and closed issues for "connect", "cookie", "sandbox",
    "subresource" and "getbb.app" in titles. Tolerate event-loop starvation in the connect tunnel heartbeat #2718, Evaluate safe retries for retryable Connect Durable Object dispatch failures #2065, Feature: connect Codex via device login from the BB UI #1683 and Codex provider does not expose account-backed Apps/connectors in BB threads #2429 are unrelated. Nothing on
    main up to 9e16411 adds a grant or changes the Connect cookies' SameSite.

AGENT GENERATED

Activity

  1. added theissue type on Sep 13, 2026
  2. added
    remote
    plugins
    connect
    partial-repro
    on Sep 13, 2026
  3. bb-slop-cop commented on Sep 13, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority: Medium · Effort: High. Added remote, plugins, connect, and partial-repro; no existing classifications were replaced.

    Reproduction report: PARTIALLY REPRODUCED · confidence: medium. Five worker-level assertions passed in each of two clean checkouts of trusted origin/main. Cookieless plugin requests and port-share GET/OPTIONS receive the 401 sign-in gate before host routing; a valid synthetic owner cookie passes authentication. Actual sandbox-driven browser cookie omission remains unverified.

    No PR: a complete remedy requires an authentication/security-boundary decision, outside this rule’s simple-fix criteria.

  4. BartSoj commented on Sep 25, 2026

    @BartSoj
    Author

    Following up with the browser half the triage report could not run, a correction to my own
    prototype, and the decision stated as options.

    Live, on the real edge (bb 0.43.4, a signed-in <handle>.getbb.app tab, Chrome 146 macOS).
    The same stored image and video, same tab, same session:

    Loaded from self.origin image video
    the top-level document https://<handle>.getbb.app loaded —
    <iframe sandbox="allow-scripts"> null failed error 4
    <iframe sandbox="allow-scripts allow-same-origin"> https://<handle>.getbb.app loaded metadata
    <iframe> (no sandbox) https://<handle>.getbb.app loaded metadata

    Only the opaque-origin frame fails; a cookieless request to the same URL is the 401 sign-in page
    from cloudflare. The same result through a real plugin page (a Thread Pages page frame,
    sandbox="allow-scripts allow-forms"). iPhone Safari 26.6 behaves differently, through the same plugin page: the image
    loads from the sandboxed frame (WebKit attaches the Lax cookie to element subresources), while a
    fetch() from the frame is refused and the video still fails with error 4. Playwright's WebKit
    agreed on the image. So today a sandboxed page's own files half-work on iPhone and not at all in
    Chrome — which makes the bug harder to see, not smaller: an author testing on an iPhone sees
    images and nothing else.

    To reproduce in one minute on any signed-in Connect tab (replace the path with any stored image):

    const u = `${location.origin}/api/v1/threads/<thread-id>/thread-storage/files/<image>.png`;
    const top = new Image();
    top.onload = () => console.log("top-level: loaded");
    top.onerror = () => console.log("top-level: failed");
    top.src = u;
    addEventListener("message", (e) => console.log("sandboxed:", e.data));
    document.body.append(Object.assign(document.createElement("iframe"), {
      sandbox: "allow-scripts",
      srcdoc: `<img src="${u}" onload="parent.postMessage('loaded','*')"
                onerror="parent.postMessage('failed','*')">`,
    }));

    A correction to the prototype. The issue says the grant token "is the same HMAC payload scheme
    as the desktop session cookie". That was a bug: the desktop-cookie check only needs userId and
    expiresAt, which a grant also carries, so a grant — a token that travels in URLs — could be
    replayed as the desktop session cookie and pass as an account-wide session for its hour. The
    branch is fixed: grants now carry their own bbpg_ prefix and are signed with a key derived by
    HKDF from the secret (the construction #4227 used for tunnel tickets); the desktop cookie's format
    is byte-for-byte unchanged. A test pins the separation. Rebased onto 9c8112e, forwarding through
    the replaying tunnel helper from #4313; @bb/connect 157 tests (main 143). A Miniflare run of the
    real worker with Playwright shows a sandboxed frame's image, script and fetch() loading through
    the grant in Chromium, Firefox and WebKit, and a grant presented as a cookie refused.
    https://github.com/BartSoj/bb/tree/feat/connect-page-grant

    The decision, as options — any of them unblocks us; I would build 1:

    1. A signed, short-lived, path-scoped grant (the branch): GET/HEAD only, one user, one handle,
      one plugin, carried in the path so relative URLs inherit it; its own key.
    2. SameSite=None; Partitioned on the Connect cookie. Two lines; widens every cross-site
      request's credentials, so CSRF on bb's routes would rest entirely on the Origin checks.
    3. A plugin-owned second origin (the github.io pattern): parity, but Connect serves and
      authenticates another domain.
    4. Won't fix; plugins carry or proxy their files — then a line in the plugin guide would save
      the next author the discovery.

    Related: #4339 (thread-storage files ignore Range, so video can't seek and Safari won't play it
    even with a cookie), #1632 (prefix routes, which option 1 needs), and #3708 (a required local
    secret would bring the same case to loopback; see my comment there).

    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

    connectpartial-repropluginsremote

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions