From 04c468195a0ae20dfeabab305588a63def71265d Mon Sep 17 00:00:00 2001 From: Jeremy Andre Date: Fri, 25 Sep 2026 23:40:28 +0200 Subject: [PATCH] fix(panel): thread the tunnel bearer through every daemon call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=&token=, 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). --- src/app/panel/page.tsx | 85 +++++++++++++++++-- src/components/SessionChatView.tsx | 38 +++++---- src/components/SessionEventsView.tsx | 27 ++++-- src/components/SessionTerminal.tsx | 15 ++-- src/lib/use-daemon.ts | 121 +++++++++++++++++++-------- src/lib/use-session-events.ts | 6 +- 6 files changed, 217 insertions(+), 75 deletions(-) diff --git a/src/app/panel/page.tsx b/src/app/panel/page.tsx index 9e4dae8..ebde6df 100644 --- a/src/app/panel/page.tsx +++ b/src/app/panel/page.tsx @@ -441,6 +441,11 @@ function ConnectBar({ daemon }: { daemon: UseDaemonResult }) { const [urlInput, setUrlInput] = useState("") const [tokenInput, setTokenInput] = useState("") const [copied, setCopied] = useState(false) + const [shareOpen, setShareOpen] = useState(false) + // Opt-in — a copied link with the token embedded grants full access to + // whoever opens it (agentproto/ts#1398: a remote daemon in bearer mode + // requires this exact token on every route), so it defaults off. + const [includeToken, setIncludeToken] = useState(false) const submit = () => { if (!urlInput.trim()) return @@ -450,12 +455,18 @@ function ConnectBar({ daemon }: { daemon: UseDaemonResult }) { setTokenInput("") } - // Shareable deep-link: the tunnel wss origin, no token (auth rides the - // trusted panel Origin). Opening it on another machine auto-connects. + // Shareable deep-link: the fragment form (`#daemon=&token=`) — fragments + // never reach a server (no Referer, no access/proxy log, no CDN cache + // key), unlike the legacy `?daemon=&token=` query-string form this panel + // still accepts for back-compat. The token is only embedded when + // `includeToken` is explicitly checked; without it, whoever opens the + // link still needs to paste the token in themselves via "connect ▾". const shareLink = (): string => { if (typeof window === "undefined" || !daemon.url) return "" const wss = daemon.url.replace(/^http/, "ws") - return `${window.location.origin}/panel?daemon=${encodeURIComponent(wss)}` + const params = new URLSearchParams({ daemon: wss }) + if (includeToken && daemon.token) params.set("token", daemon.token) + return `${window.location.origin}/panel#${params.toString()}` } const copyLink = async () => { @@ -464,6 +475,7 @@ function ConnectBar({ daemon }: { daemon: UseDaemonResult }) { try { await navigator.clipboard.writeText(link) setCopied(true) + setShareOpen(false) setTimeout(() => setCopied(false), 1500) } catch { /* clipboard blocked — ignore */ @@ -535,9 +547,67 @@ function ConnectBar({ daemon }: { daemon: UseDaemonResult }) { )} {daemon.remote && ( - +
+ + {shareOpen && ( +
+ +
+ {daemon.token + ? includeToken + ? "Anyone with this link gets full access to this daemon — share it only with someone you trust." + : "Without the token, whoever opens this link must paste it in themselves via “connect”." + : "This connection has no token to embed."} +
+ +
+ )} +
)} {daemon.remote && (