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:
Timothy Jaeryang Baek
2026-05-11 01:56:02 +09:00
parent 1388f4568b
commit 3bba1c2270
8 changed files with 30 additions and 6 deletions
@@ -1,5 +1,7 @@
<script lang="ts">
import { onDestroy, onMount, tick } from 'svelte';
import { config } from '$lib/stores';
import { injectCsp } from '$lib/utils/csp';
// Props
export let src: string | null = null; // URL or raw HTML (auto-detected)
@@ -192,7 +194,7 @@ window.Chart = parent.Chart; // Chart previously assigned on parent
{#if iframeDoc}
<iframe
bind:this={iframe}
srcdoc={iframeDoc}
srcdoc={injectCsp(iframeDoc, $config?.ui?.iframe_csp ?? '')}
{title}
class={iframeClassName}
style={`${initialHeight ? `height:${initialHeight}px;` : ''}`}