Commit ae7ed0d
fix(security): add base-uri 'self' + object-src 'none' to the admin CSP (CoreBunch#158)
The admin CSP was `frame-ancestors 'none'` only. Add two directives that are
safe to enforce today and close two injection vectors as defense-in-depth
behind the htmlAttributes/custom-tag hardening:
- `base-uri 'self'` — a `<base href>` injection can otherwise rewrite the
resolution of every relative URL on the page (script/style/fetch targets).
The admin never emits a `<base>` element.
- `object-src 'none'` — blocks `<object>` / `<embed>` plugin content. The
admin never embeds either.
A `script-src` / `style-src` policy is deliberately still NOT set: the admin
ships an inline `<script type="importmap">` the plugin runtime needs, the
visual-editor canvas is `srcDoc` iframes (which inherit this policy) that
inject the site's runtime scripts as inline `<script>`, and the editor relies
on inline styles for dynamic custom properties. A safe `script-src` needs
per-request nonce plumbing through the served-HTML patcher and the canvas
script injector plus a full editor browser sweep — a dedicated follow-up.
Tests: security-headers.test.ts updated to assert the three-directive policy
on every /admin path and the absence on public/uploads/root.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 75086cf commit ae7ed0d
2 files changed
Lines changed: 42 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
| |||
57 | 66 | | |
58 | 67 | | |
59 | 68 | | |
60 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
61 | 73 | | |
62 | 74 | | |
63 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
105 | 117 | | |
106 | 118 | | |
107 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
108 | 122 | | |
109 | 123 | | |
110 | | - | |
| 124 | + | |
111 | 125 | | |
112 | 126 | | |
113 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
114 | 130 | | |
115 | 131 | | |
116 | 132 | | |
| |||
0 commit comments