Skip to content

Commit fe8c08f

Browse files
committed
CSP fixes
1 parent 2a51618 commit fe8c08f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

docs/content/docs/configuration/server.mdx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,22 @@ permissions_policy = "geolocation=(), microphone=()"
143143
Hadrian ships a default CSP tailored for the web UI's frontend tools (Python, JavaScript, SQL, and chart execution via WASM):
144144

145145
```
146-
default-src 'self'; script-src 'self' blob:; style-src 'self' 'unsafe-inline';
147-
img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self';
148-
worker-src 'self' blob:; frame-src 'self' blob:; object-src 'none'; base-uri 'self'
146+
default-src 'self'; script-src 'self' blob: 'unsafe-eval' https://cdn.jsdelivr.net;
147+
style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:;
148+
connect-src 'self' https://cdn.jsdelivr.net; worker-src 'self' blob:;
149+
frame-src 'self' blob:; object-src 'none'; base-uri 'self'
149150
```
150151

151-
| Directive | Value | Reason |
152-
| ------------ | ------------------------ | ---------------------------------------------------------------- |
153-
| `script-src` | `'self' blob:` | WASM workers (Pyodide, QuickJS, DuckDB) are loaded as blob URLs. |
154-
| `style-src` | `'self' 'unsafe-inline'` | Tailwind CSS injects styles dynamically. |
155-
| `worker-src` | `'self' blob:` | Web Workers run sandboxed code execution. |
156-
| `frame-src` | `'self' blob:` | HTML artifact previews render in sandboxed iframes. |
157-
| `img-src` | `'self' data: blob:` | Generated charts and inline images use data/blob URIs. |
158-
| `object-src` | `'none'` | Blocks plugin-based content (Flash, Java applets). |
159-
| `base-uri` | `'self'` | Prevents `<base>` tag injection attacks. |
152+
| Directive | Value | Reason |
153+
| ------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
154+
| `script-src` | `'self' blob: 'unsafe-eval' https://cdn.jsdelivr.net` | WASM workers as blob URLs; `unsafe-eval` for Pyodide Python bytecode execution; CDN for Pyodide modules. |
155+
| `style-src` | `'self' 'unsafe-inline'` | Tailwind CSS injects styles dynamically. |
156+
| `worker-src` | `'self' blob:` | Web Workers run sandboxed code execution. |
157+
| `frame-src` | `'self' blob:` | HTML artifact previews render in sandboxed iframes. |
158+
| `img-src` | `'self' data: blob:` | Generated charts and inline images use data/blob URIs. |
159+
| `connect-src` | `'self' https://cdn.jsdelivr.net` | Pyodide fetches WASM binaries and packages from CDN. |
160+
| `object-src` | `'none'` | Blocks plugin-based content (Flash, Java applets). |
161+
| `base-uri` | `'self'` | Prevents `<base>` tag injection attacks. |
160162

161163
Override this by setting `content_security_policy` explicitly. Set to an empty string to disable the CSP header entirely.
162164

src/config/server.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,18 @@ fn default_frame_options() -> Option<String> {
460460
/// Default Content-Security-Policy for the web UI.
461461
///
462462
/// Directives:
463-
/// - `script-src blob:` — WASM workers (Pyodide, QuickJS, DuckDB) loaded as blob URLs
463+
/// - `script-src blob: 'unsafe-eval' https://cdn.jsdelivr.net` — WASM workers loaded as blob
464+
/// URLs; `unsafe-eval` required by Pyodide for Python bytecode execution; CDN for Pyodide modules
464465
/// - `style-src 'unsafe-inline'` — Tailwind CSS dynamic styling
465466
/// - `worker-src blob:` — Web Worker sandboxed execution
466467
/// - `frame-src blob:` — HTML artifact preview iframes
467468
/// - `img-src data: blob:` — Generated charts/images and inline assets
469+
/// - `media-src blob:` — Audio playback from generated TTS blob URLs
470+
/// - `connect-src https://cdn.jsdelivr.net` — Pyodide fetches WASM/packages from CDN
468471
/// - `object-src 'none'` — Blocks plugins (Flash, Java applets)
469472
/// - `base-uri 'self'` — Prevents `<base>` tag injection
470473
fn default_csp() -> Option<String> {
471-
Some("default-src 'self'; script-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; worker-src 'self' blob:; frame-src 'self' blob:; object-src 'none'; base-uri 'self'".to_string())
474+
Some("default-src 'self'; script-src 'self' blob: 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; media-src 'self' blob:; connect-src 'self' https://cdn.jsdelivr.net; worker-src 'self' blob:; frame-src 'self' blob:; object-src 'none'; base-uri 'self'".to_string())
472475
}
473476

474477
fn default_xss_protection() -> Option<String> {

0 commit comments

Comments
 (0)