Chat replies can't leak data through images #2073

Closed
opened 2026-11-20 08:41:09 +00:00 by sam · 1 comment
Owner

Why: a chat reply is model-written Markdown, and untrusted content the agent read (a web page, a ticket, an email) can instruct it to embed an external image whose URL carries data in the query string. Today the browser fetches that URL, so data leaves the dashboard inside an image request even when every tool call was permitted. Picture a support ticket that says "include this tracking pixel": the reply renders it and the CRM notes the agent just read go out in the image request.

Today:

  • ui/src/chat/markdown.ts parses reply Markdown; its SAFE_SRC regex accepts any https?:// image URL, so external images survive into the tree. ui/src/chat/ChatMarkdown.vue renders each img with that src (loading="lazy"). Raw HTML is already dropped and links keep only safe URLs (SAFE_HREF).
  • The renderer does no link unfurling, so nothing fetches link previews today.
  • modules/dashboard/dashboard.go serves the SPA (the page and its assets) setting only Cache-Control; no Content-Security-Policy is sent on any dashboard response. The only CSP in the tree is an old service's login page (internal/webui/auth.go), which does not cover the dashboard.

Source: the revised RFC exported at transcripts/2026-11-20-chat-authorization-rfc-3fa43269.md in sam/archie-product; citations below are RFC section numbers.

Required behaviour:

  1. parseMarkdown in ui/src/chat/markdown.ts drops every img whose src is an external http(s) or protocol-relative (//...) URL; only same-origin paths (/...) and data:image/... survive. Unsafe schemes stay dropped (RFC 4: all outbound paths are sinks; image previews can disclose data even when labeled read; disable automatic remote fetches and sanitize rendered content).
  2. We choose dropping over proxying: no server-side image proxy is introduced, and none may fetch arbitrary model-generated URLs (RFC 4).
  3. Every non-API response modules/dashboard/dashboard.go serves (the page and its assets) carries a Content-Security-Policy header whose img-src is exactly 'self' data: — no external origin (RFC 4; RFC 3 stage 7 authorizes each sink). Other directives may be added only if the dashboard still works: its own scripts and styles must keep loading.
  4. Rendered images keep loading="lazy". ChatMarkdown.vue is also used by the task approval, plan and run transcript views (ui/src/tasks/TaskApproval.vue, ui/src/tasks/PlanDocument.vue, ui/src/workflows/AgentTranscript.vue); fixing parseMarkdown covers them all (RFC 3 stage 7).

Out of scope: #2067 tool discovery, #2068 taint, #2069 memory scopes, #2070 connector credential modes, #2071 admin tools refused in chat, #2072 approval binding, #2074 budgets/rate limits, #2075 audit/revocation/kill-switch, #2078 enforcement on every entry point, #2079 chat-triggered workflow execution contracts, and #2080 disclosure authorization per audience and destination — the destination/audience-wide disclosure policy is #2080; this issue stays the chat markdown renderer plus the dashboard CSP.

Design notes: two layers — the renderer is the primary fix, the CSP header is the browser-side backstop for any markup path that misses it. The server half belongs to modules/dashboard (it owns the SPA responses); the renderer half belongs to ui/src/chat/markdown.ts — change SAFE_SRC so https?:// no longer matches. Sanitizing rendered content tightens disclosure; it is not an authorization control and never grants authority (RFC 4). No migration: stored replies are re-rendered from their text, so old replies with external images stop loading as soon as the code ships. Do not break data:image/ — the model legitimately emits inline charts.

Tests (security boundary, so AGENTS.md requires a test: table cases, fakes, no DB):

  • Extend the table in ui/test/chat-markdown.test.ts: an external https image URL → 0 img, a protocol-relative //... URL → 0, plain http:// → 0, a same-origin /... path → 1, data:image/png;base64,... → 1, javascript: → 0. Each new case must fail on the current code before the fix.
  • Extend the table in modules/dashboard/dashboard_test.go: page routes, asset paths and the no-build fallback all answer with the CSP header containing img-src 'self' data:.

Done when: pnpm test and pnpm run typecheck pass in ui/, task check passes at the repo root, and on a running binary: response headers on / show the CSP with img-src 'self' data:; asking chat for a reply containing an external image URL with data in the query string renders no image and devtools shows no request to that origin, while a data:image/ image and a same-origin path still render.

Open questions for the maintainer: None.

Part of #2066.

**Why**: a chat reply is model-written Markdown, and untrusted content the agent read (a web page, a ticket, an email) can instruct it to embed an external image whose URL carries data in the query string. Today the browser fetches that URL, so data leaves the dashboard inside an image request even when every tool call was permitted. Picture a support ticket that says "include this tracking pixel": the reply renders it and the CRM notes the agent just read go out in the image request. **Today**: - ui/src/chat/markdown.ts parses reply Markdown; its SAFE_SRC regex accepts any https?:// image URL, so external images survive into the tree. ui/src/chat/ChatMarkdown.vue renders each img with that src (loading="lazy"). Raw HTML is already dropped and links keep only safe URLs (SAFE_HREF). - The renderer does no link unfurling, so nothing fetches link previews today. - modules/dashboard/dashboard.go serves the SPA (the page and its assets) setting only Cache-Control; no Content-Security-Policy is sent on any dashboard response. The only CSP in the tree is an old service's login page (internal/webui/auth.go), which does not cover the dashboard. **Source**: the revised RFC exported at transcripts/2026-11-20-chat-authorization-rfc-3fa43269.md in sam/archie-product; citations below are RFC section numbers. **Required behaviour**: 1. parseMarkdown in ui/src/chat/markdown.ts drops every img whose src is an external http(s) or protocol-relative (//...) URL; only same-origin paths (/...) and data:image/... survive. Unsafe schemes stay dropped (RFC 4: all outbound paths are sinks; image previews can disclose data even when labeled read; disable automatic remote fetches and sanitize rendered content). 2. We choose dropping over proxying: no server-side image proxy is introduced, and none may fetch arbitrary model-generated URLs (RFC 4). 3. Every non-API response modules/dashboard/dashboard.go serves (the page and its assets) carries a Content-Security-Policy header whose img-src is exactly 'self' data: — no external origin (RFC 4; RFC 3 stage 7 authorizes each sink). Other directives may be added only if the dashboard still works: its own scripts and styles must keep loading. 4. Rendered images keep loading="lazy". ChatMarkdown.vue is also used by the task approval, plan and run transcript views (ui/src/tasks/TaskApproval.vue, ui/src/tasks/PlanDocument.vue, ui/src/workflows/AgentTranscript.vue); fixing parseMarkdown covers them all (RFC 3 stage 7). **Out of scope**: #2067 tool discovery, #2068 taint, #2069 memory scopes, #2070 connector credential modes, #2071 admin tools refused in chat, #2072 approval binding, #2074 budgets/rate limits, #2075 audit/revocation/kill-switch, #2078 enforcement on every entry point, #2079 chat-triggered workflow execution contracts, and #2080 disclosure authorization per audience and destination — the destination/audience-wide disclosure policy is #2080; this issue stays the chat markdown renderer plus the dashboard CSP. **Design notes**: two layers — the renderer is the primary fix, the CSP header is the browser-side backstop for any markup path that misses it. The server half belongs to modules/dashboard (it owns the SPA responses); the renderer half belongs to ui/src/chat/markdown.ts — change SAFE_SRC so https?:// no longer matches. Sanitizing rendered content tightens disclosure; it is not an authorization control and never grants authority (RFC 4). No migration: stored replies are re-rendered from their text, so old replies with external images stop loading as soon as the code ships. Do not break data:image/ — the model legitimately emits inline charts. **Tests** (security boundary, so AGENTS.md requires a test: table cases, fakes, no DB): - Extend the table in ui/test/chat-markdown.test.ts: an external https image URL → 0 img, a protocol-relative //... URL → 0, plain http:// → 0, a same-origin /... path → 1, data:image/png;base64,... → 1, javascript: → 0. Each new case must fail on the current code before the fix. - Extend the table in modules/dashboard/dashboard_test.go: page routes, asset paths and the no-build fallback all answer with the CSP header containing img-src 'self' data:. **Done when**: pnpm test and pnpm run typecheck pass in ui/, task check passes at the repo root, and on a running binary: response headers on / show the CSP with img-src 'self' data:; asking chat for a reply containing an external image URL with data in the query string renders no image and devtools shows no request to that origin, while a data:image/ image and a same-origin path still render. **Open questions for the maintainer**: None. Part of #2066.
sam added a new dependency 2026-11-20 08:53:19 +00:00
sam added the featurehigh labels 2026-11-20 10:04:32 +00:00
Author
Owner

Fixed in 9af3b2934 (pushed to main), both layers as specified.

Renderer: SAFE_SRC in ui/src/chat/markdown.ts now keeps only same-origin root-relative paths and data:image/ URLs. http(s)://, protocol-relative //, and /\ (backslash after the leading slash, which browsers read as a remote host) are rejected; unsafe schemes stay rejected. Link handling and loading="lazy" are unchanged, and the shared parser covers task approvals, plans and run transcripts. No proxy, no migration.

Backstop: modules/dashboard sets Content-Security-Policy: img-src 'self' data: (image-only, no other directives) on every non-API response — page, assets, error and no-build responses. The /api/ JSON fallback is unchanged and carries no CSP.

Proof: new table cases failed before the fix (remote https image rendered; CSP header empty on page/asset/read-only/no-build) and pass after; ui pnpm test 127 pass 0 fail, pnpm run typecheck clean, go test ./modules/dashboard ok, full task check exit 0 on this tree. Smoke test with the rebuilt embedded dashboard served on a scratch port: GET / and client routes answer 200 with exactly "img-src 'self' data:" (assets too), /api/nope still answers the JSON 404 with no CSP header; headless Chromium loaded the dashboard normally (title "Dashboard | Archie", app mounted), a remote image URL was blocked by CSP (requestfailed errorText "csp", image never loaded, no bytes left the page), while a data:image/ and a same-origin /favicon.svg both rendered.

Fixed in 9af3b2934 (pushed to main), both layers as specified. Renderer: SAFE_SRC in ui/src/chat/markdown.ts now keeps only same-origin root-relative paths and data:image/ URLs. http(s)://, protocol-relative //, and /\ (backslash after the leading slash, which browsers read as a remote host) are rejected; unsafe schemes stay rejected. Link handling and loading="lazy" are unchanged, and the shared parser covers task approvals, plans and run transcripts. No proxy, no migration. Backstop: modules/dashboard sets Content-Security-Policy: img-src 'self' data: (image-only, no other directives) on every non-API response — page, assets, error and no-build responses. The /api/ JSON fallback is unchanged and carries no CSP. Proof: new table cases failed before the fix (remote https image rendered; CSP header empty on page/asset/read-only/no-build) and pass after; ui pnpm test 127 pass 0 fail, pnpm run typecheck clean, go test ./modules/dashboard ok, full task check exit 0 on this tree. Smoke test with the rebuilt embedded dashboard served on a scratch port: GET / and client routes answer 200 with exactly "img-src 'self' data:" (assets too), /api/nope still answers the JSON 404 with no CSP header; headless Chromium loaded the dashboard normally (title "Dashboard | Archie", app mounted), a remote image URL was blocked by CSP (requestfailed errorText "csp", image never loaded, no bytes left the page), while a data:image/ and a same-origin /favicon.svg both rendered.
sam closed this issue 2026-11-20 15:54:30 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#2073