Skip to content

fix(panel): thread the tunnel bearer through every daemon call - #14

Merged
agentiknet merged 1 commit into
mainfrom
panel-token
Sep 25, 2026
Merged

agentiknet merged 1 commit into
mainfrom
panel-token

Conversation

@agentiknet

@agentiknet agentiknet commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Pairs with agentproto/ts#1398 (the P0 tunnel-auth fix). PHONE-PLAN.md sections P1.3 (this panel's token) and P1.2 (fragment link shape).

The problem

After ts#1398, a remote daemon in bearer mode 401s any non-loopback request that doesn't carry the real bearer — an allowlisted Origin is no longer a substitute. Several panel call sites never sent the bearer at all, so a panel connected over a tunnel would break:

  • PromptInput's POST in both SessionEventsView.tsx (~745) and SessionChatView.tsx (~745) — no Authorization header, and no token prop even threaded down to the component.
  • SessionChatView's transcript export fetches (~861, ~867) and SessionJsonView's (~1226, ~1231) — same gap.
  • use-session-events.ts's polling fetch (~144) — same gap.
  • SessionTerminal.tsx's SSE (EventSource) already threaded ?token= correctly but its own comment justified this as defense-in-depth ("the stream is ungated") rather than a requirement — now it actually is one.

use-daemon.ts's own refresh/killSession/createTerminalSession/health-probe fetches already sent the bearer via an ad hoc authHeaders() closure.

The fix

Two helpers in src/lib/use-daemon.ts:

  • daemonFetch(url, token, init?) — wraps fetch with mode:"cors", credentials:"include" and sets Authorization: Bearer <token> when present.
  • withToken(url, token) — appends ?token=<token> (the query-string form EventSource/WebSocket need, since they can't set headers).

Every daemon-facing call now goes through one of these: use-daemon.ts's own fetches (replacing authHeaders()), use-session-events.ts, both PromptInputs, SessionChatView's + SessionJsonView's export fetches, and SessionTerminal.tsx's WS/SSE URLs. token is now threaded as a prop from panel/page.tsx into SessionChatView/SessionEventsView/SessionJsonView, which previously never received it.

The fragment link

Added readFragmentConnection() alongside the existing readLinkConnection() (?daemon=&token=, kept for back-compat): it reads #daemon=<url>&token=<t> — the shape remote_enable's upcoming phoneUrl will use (ts P1.2) — and scrubs it from the address bar the same way. Fragments never reach a server (no Referer, no access/proxy log, no CDN cache key), unlike a query string.

The "copy link" button now produces the fragment form. Since a copied link with the token embedded grants full access to whoever opens it, the token is only included behind an explicit "include access token" checkbox (default off, disabled when there's no token to embed).

Gate

pnpm typecheck and pnpm build both pass (exit 0). No lockfile committed (this repo builds from package.json ranges in CI — see its own workflow's comment on why).


🤖 @agentproto-bot — PR · session sess_897aba74 (security: tunnel auth hardening (P0)) · claude-code / subscription · auth-profile Claude Subs Agentik · model claude-sonnet-5 · $21.0496 (daemon) · host mac.home · cwd agentproto/tunnel-auth-hardening

agentproto/ts#1398 makes a remote daemon in bearer mode require the real
bearer on every non-loopback route — an allowlisted Origin is no longer
sufficient. Several panel call sites never sent it: the prompt POST in
SessionEventsView/SessionChatView, the transcript export fetches, and the
SSE/PTY streams relied on a stale "Origin is enough" assumption.

Centralizes this in two helpers in use-daemon.ts (daemonFetch for
Authorization: Bearer, withToken for the ?token= query form SSE/WS need)
and routes every daemon-facing call through them, threading the token prop
down to SessionChatView/SessionEventsView/SessionJsonView from the panel
page where it was previously missing entirely.

Also accepts the connection as a URL fragment (#daemon=<url>&token=<t>,
paired with remote_enable's phoneUrl) alongside the existing ?daemon=&token=
query form — fragments never reach a server, so they can't leak into an
access log or Referer header the way a query string can. The "copy link"
button now produces the fragment form and only embeds the token behind an
explicit "include access token" toggle (default off).
@agentiknet
agentiknet merged commit 1c011a2 into main Sep 25, 2026
1 check passed
@agentiknet
agentiknet deleted the panel-token branch September 25, 2026 23:42
agentiknet added a commit to agentproto/ts that referenced this pull request Sep 25, 2026
…e enable --qr

PHONE-PLAN.md P1.2. remote_enable (MCP tool and the new POST /remote/enable
REST route) now also returns phoneUrl: the installed session-chat app's UI
when present (<tunnel>/apps/@agentik/session-chat/ui#token=<t>), else the
hosted panel fallback (https://cli.agentproto.sh/panel#daemon=<tunnel>&token=<t>).
The token rides in a URL fragment, never a query string, so it never reaches
a server log — matching agentproto/cli-site#14's readFragmentConnection.
Omitted for passthrough tunnels, same condition as bearerToken/mcpEndpoint.

Adds GET/POST /remote/status/enable/disable REST routes (RemoteController
was previously MCP-only) and a new `agentproto remote enable/disable/status`
CLI verb built on them, mirroring `agentproto tunnel`'s discoverDaemon()
pattern. `--qr` renders phoneUrl as a terminal QR code via the existing
qrcode-terminal dependency, extracted from pair.ts's printQr into a shared
util so both commands use the same renderer.
agentiknet added a commit to agentproto/ts that referenced this pull request Sep 26, 2026
…e enable --qr

PHONE-PLAN.md P1.2. remote_enable (MCP tool and the new POST /remote/enable
REST route) now also returns phoneUrl: the installed session-chat app's UI
when present (<tunnel>/apps/@agentik/session-chat/ui#token=<t>), else the
hosted panel fallback (https://cli.agentproto.sh/panel#daemon=<tunnel>&token=<t>).
The token rides in a URL fragment, never a query string, so it never reaches
a server log — matching agentproto/cli-site#14's readFragmentConnection.
Omitted for passthrough tunnels, same condition as bearerToken/mcpEndpoint.

Adds GET/POST /remote/status/enable/disable REST routes (RemoteController
was previously MCP-only) and a new `agentproto remote enable/disable/status`
CLI verb built on them, mirroring `agentproto tunnel`'s discoverDaemon()
pattern. `--qr` renders phoneUrl as a terminal QR code via the existing
qrcode-terminal dependency, extracted from pair.ts's printQr into a shared
util so both commands use the same renderer.
agentiknet added a commit to agentproto/ts that referenced this pull request Sep 26, 2026
…e enable --qr (#1402)

* feat(runtime,cli): remote_enable returns a phoneUrl; agentproto remote enable --qr

PHONE-PLAN.md P1.2. remote_enable (MCP tool and the new POST /remote/enable
REST route) now also returns phoneUrl: the installed session-chat app's UI
when present (<tunnel>/apps/@agentik/session-chat/ui#token=<t>), else the
hosted panel fallback (https://cli.agentproto.sh/panel#daemon=<tunnel>&token=<t>).
The token rides in a URL fragment, never a query string, so it never reaches
a server log — matching agentproto/cli-site#14's readFragmentConnection.
Omitted for passthrough tunnels, same condition as bearerToken/mcpEndpoint.

Adds GET/POST /remote/status/enable/disable REST routes (RemoteController
was previously MCP-only) and a new `agentproto remote enable/disable/status`
CLI verb built on them, mirroring `agentproto tunnel`'s discoverDaemon()
pattern. `--qr` renders phoneUrl as a terminal QR code via the existing
qrcode-terminal dependency, extracted from pair.ts's printQr into a shared
util so both commands use the same renderer.

* docs(cli): add agentproto remote verb page

The docs.mjs --check gate failed CI: a new verb (remote) with no
docs/cli/verbs/ page is a hard error. Covers enable [--qr]/disable/status,
the two phoneUrl shapes (session-chat link vs. the cli.agentproto.sh/panel
fallback) and why the token rides in a URL fragment, and the post-#1398
security model (every non-loopback route needs the bearer once enabled).

* chore: agentic reviewer — changeset

---------

Co-authored-by: agentproto-bot <bot@agentproto.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant