feat: add IFRAME_CSP env var for srcdoc iframe content security policy
Adds an IFRAME_CSP environment variable that injects a Content-Security-Policy <meta> tag into all srcdoc iframes rendering untrusted content: - Artifacts (LLM-generated HTML previews) - FullHeightIframe (tool/embed output) - FilePreview (user-uploaded HTML files) - CitationModal (RAG document HTML) Shared utility in src/lib/utils/csp.ts handles injection with HTML-safe attribute escaping. URL-based iframes (src=) are correctly excluded. Env-var only — no PersistentConfig, no admin UI, no DB. Set once at deploy time, requires restart. Empty string (default) means no CSP restriction.
This commit is contained in:
1 parent
1388f4568b
commit
3bba1c2270
8 files changed
+30
-6
No files matched your search
@@ -7,12 +7,14 @@
|
||||
import {
|
||||
artifactCode,
|
||||
chatId,
|
||||
config,
|
||||
settings,
|
||||
showArtifacts,
|
||||
showControls,
|
||||
artifactContents
|
||||
} from '$lib/stores';
|
||||
import { copyToClipboard, createMessagesList } from '$lib/utils';
|
||||
import { injectCsp } from '$lib/utils/csp';
|
||||
|
||||
import XMark from '../icons/XMark.svelte';
|
||||
import ArrowsPointingOut from '../icons/ArrowsPointingOut.svelte';
|
||||
@@ -242,7 +244,7 @@
|
||||
<iframe
|
||||
bind:this={iframeElement}
|
||||
title="Content"
|
||||
srcdoc={contents[selectedContentIdx].content}
|
||||
srcdoc={injectCsp(contents[selectedContentIdx].content, $config?.ui?.iframe_csp ?? '')}
|
||||
class="w-full border-0 h-full rounded-none"
|
||||
sandbox="allow-scripts allow-downloads{($settings?.iframeSandboxAllowForms ?? false)
|
||||
? ' allow-forms'
|
||||
|
||||
Reference in new issue
Block a user