Skip to content

Commit c11366b

Browse files
zknprclaude
andcommitted
fix(csp): Add nonce to style tag for CSP compliance
The <style> tag in viewer.html was being blocked by CSP after removing 'unsafe-inline' from style-src. This caused the entire UI to render without any styling. Fix: - Add nonce="<!--NONCE-->" attribute to <style> tag in viewer.html - Add nonce to styleSrc CSP directive in editorController.ts - Update CLAUDE.md to reflect nonce-based style policy The nonce placeholder is replaced at runtime with the same nonce used for scripts, allowing the inline <style> block to pass CSP validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 58f5d33 commit c11366b

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ workerProxy.method(new Transfer(data, [data.buffer]));
141141

142142
### Content Security Policy (CSP)
143143
- **Scripts**: Strict nonce-based policy. No `'unsafe-inline'` allowed.
144-
- **Styles**: No `'unsafe-inline'` allowed. Dynamic inline styles are applied via CSSOM (`element.style.prop = ...`) which is permitted by CSP with `'self'`.
144+
- **Styles**: Nonce-based policy for `<style>` tags. Dynamic inline styles are applied via CSSOM (`element.style.prop = ...`) which is permitted by CSP.
145145
- **Isolation**: Webview communicates only via RPC.
146146

147147
### Cross-Site Scripting (XSS) Prevention

core/ui/viewer.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>SQLite Explorer</title>
77
<!--HEAD-->
8-
<style>
8+
<style nonce="<!--NONCE-->">
99
<!--STYLES-->
1010
</style>
1111
</head>

src/editorController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,11 @@ export class DatabaseViewerProvider extends Disposable implements vsc.CustomRead
231231
// wasm-unsafe-eval is still required for sql.js WASM compilation.
232232
//
233233
// NOTE: 'unsafe-inline' for styles has been removed.
234+
// The <style> tag in viewer.html uses a nonce for CSP compliance.
234235
// Dynamic inline styles for column widths and positioning are handled via
235-
// CSSOM (element.style.prop = ...) which is allowed by CSP 'self'.
236+
// CSSOM (element.style.prop = ...) which is allowed by CSP.
236237
[cspUtil.scriptSrc]: [webview.cspSource, cspUtil.wasmUnsafeEval, `'nonce-${nonce}'`],
237-
[cspUtil.styleSrc]: [webview.cspSource],
238+
[cspUtil.styleSrc]: [webview.cspSource, `'nonce-${nonce}'`],
238239
[cspUtil.imgSrc]: [webview.cspSource, cspUtil.data, cspUtil.blob],
239240
[cspUtil.fontSrc]: [webview.cspSource],
240241
[cspUtil.frameSrc]: [cspUtil.none],

0 commit comments

Comments
 (0)