Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): send same-origin cookies with uploads
David Klaper2732e2b3ce52
diff --git a/docs/websocket.md b/docs/websocket.mdindex 8d0d212c2..ce7f28971 100644--- a/docs/websocket.md+++ b/docs/websocket.md@@ -243,7 +243,7 @@ The upload path accepts the existing image, document, and video MIME whitelist.Update WebUI and TUI together with the gateway. Existing messages and attachments remain available without a history migration. Clients must use HTTP uploads; `media.data_url` message uploads are no longer accepted. Local previews and the separate audio transcription protocol are unchanged.-Reverse proxies must forward `POST /api/attachments` (including its authorization header) to the gateway and permit the configured file sizes. Do not enable public CORS for this capability endpoint.+Reverse proxies must forward `POST /api/attachments` (including its authorization header) to the gateway and permit the configured file sizes. Same-origin browser uploads include origin cookies for edge authentication; cross-origin uploads do not send cookies. Do not enable public CORS for this capability endpoint.For a remote host opened through the local WebUI, update the local installation and the remote gateway together to use binary attachments. An older host's text chats and HTTP reads remain available.diff --git a/packages/client-events/attachments.ts b/packages/client-events/attachments.tsindex d072d7027..0cef843ca 100644--- a/packages/client-events/attachments.ts+++ b/packages/client-events/attachments.ts@@ -20,7 +20,7 @@ export async function uploadAttachments(if (!capability || !stillConnected()) throw new Error("Attachment upload connection is not ready");const url = new URL(capability.path, baseUrl.replace(/^ws:/, "http:").replace(/^wss:/, "https:"));if (!["http:", "https:"].includes(url.protocol)) throw new Error("HTTP upload is unavailable");- // No handshake credentials in the URL, no redirects leaking the capability.+ // Send same-origin edge-auth cookies without following redirects with the capability.url.search = "";url.username = "";url.password = "";@@ -32,7 +32,7 @@ export async function uploadAttachments(const raw = atob(match[2]);const bytes = Uint8Array.from(raw, (character) => character.charCodeAt(0));const response = await fetch(url, {- method: "POST", redirect: "error", credentials: "omit",+ method: "POST", redirect: "error", credentials: "same-origin",headers: {Authorization: `Bearer ${capability.token}`,"Content-Type": match[1],diff --git a/webui/src/tests/nanobot-client.test.ts b/webui/src/tests/nanobot-client.test.tsindex c6a254b74..6e3f3a22f 100644--- a/webui/src/tests/nanobot-client.test.ts+++ b/webui/src/tests/nanobot-client.test.ts@@ -2444,6 +2444,7 @@ describe("binary attachment transport", () => {expect(request.method).toBe("POST");expect(request.headers.Authorization).toBe("Bearer upload-capability");expect(request.redirect).toBe("error");+ expect(request.credentials).toBe("same-origin");expect(await request.body.text()).toBe(raw);const frame = socket.sent.find((value) => value.includes("opaque-ref"))!;expect(frame.length).toBeLessThan(1024);