Skip to content

Commit b0db69d

Browse files
committed
feat(mdviewer): add Content-Security-Policy to block injected scripts
Add CSP meta tag to md viewer iframe HTML: - script-src 'self': blocks inline scripts and external script URLs from markdown content, only allows the bundled mdviewer JS - connect-src 'self': blocks fetch/XHR to external URLs, preventing data exfiltration even if a script somehow executes - img-src allows external URLs (needed for markdown images) - style-src allows self + unsafe-inline (needed for element positioning) Combined with the existing iframe sandbox (no allow-same-origin), this provides defense-in-depth against malicious markdown content.
1 parent 79696f0 commit b0db69d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src-mdviewer/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta name="color-scheme" content="light dark" />
7+
<meta http-equiv="Content-Security-Policy"
8+
content="default-src 'self';
9+
script-src 'self';
10+
style-src 'self' 'unsafe-inline';
11+
img-src 'self' blob: data: phtauri: https: http:;
12+
font-src 'self' data:;
13+
connect-src 'self';" />
714
<script type="module" src="/src/embedded-main.js"></script>
815
</head>
916
<body>

0 commit comments

Comments
 (0)