fix(dashboard): drop remote images from chat Markdown and add an image-only CSP (#2073)
SAFE_SRC in ui/src/chat/markdown.ts now keeps only same-origin root-relative paths and data:image/ URLs, rejecting http(s), protocol-relative and backslash-after-slash forms that the browser would read as a remote host. The shared parser also covers task approvals, plans and run transcripts. modules/dashboard sets Content-Security-Policy: img-src 'self' data: on every non-API response (page, assets, errors, no-build fallback) as the browser backstop; the /api/ JSON fallback is unchanged. No proxy, no migration: stored replies re-render from their text.
This commit is contained in:
4 files changed
+32
-5
No files matched your search
@@ -15,7 +15,10 @@ const processor = unified().use(remarkParse).use(remarkGfm).use(remarkRehype);
|
||||
// A #N the model wrote about a task. Not part of a word, entity or path.
|
||||
const TASK_REF = /(?<![\w&#/])#(\d{1,9})(?!\w)/g;
|
||||
const SAFE_HREF = /^(?:https?:\/\/|\/(?!\/)|#)/i;
|
||||
const SAFE_SRC = /^(?:https?:\/\/|\/(?!\/)|data:image\/)/i;
|
||||
// Images render only from same-origin paths and inline data: a remote image
|
||||
// URL is a data-exfil sink, and /\ or // makes the browser treat the rest as
|
||||
// a host, so both slash forms after the leading / are rejected too.
|
||||
const SAFE_SRC = /^(?:\/(?![/\\])|data:image\/)/i;
|
||||
|
||||
export function parseMarkdown(text: string | null | undefined): Root {
|
||||
const tree = processor.runSync(processor.parse(text ?? "")) as Root;
|
||||
|
||||
Reference in new issue
Block a user