fix(security): pin script-src to the inline script's sha256 hash (SEC-7)

unsafe-inline dropped for scripts (index has zero style/script attributes;
the single inline script is hash-pinned). style-src keeps unsafe-inline
(CV carries 2 style attributes + single-file convention). Verified in
hardened container: served-script hash == policy hash, JS executes.
This commit is contained in:
Bastien Chanot
2026-07-05 19:59:45 +02:00
parent d63a52ec50
commit c0632aefa8
+5 -2
View File
@@ -8,5 +8,8 @@ add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=(), payment=()" always;
# CSP: inline CSS + JS are allowed (project convention), fonts from Google.
add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; script-src 'self' 'unsafe-inline'; img-src 'self' data:; base-uri 'self'; form-action 'self'; frame-ancestors 'self'" always;
# CSP: inline CSS allowed (style attributes in the CV + single-file convention);
# the inline script is HASH-pinned (no script unsafe-inline). INVARIANT: after
# ANY edit to index.html's inline <script>, recompute the hash (command in
# CLAUDE.md) and update it here — a stale hash silently disables the JS.
add_header Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; script-src 'self' 'sha256-Al1M34KxI6Ye5Viu6aO//7CYyaLzqtpG9GX95FFlSOY='; img-src 'self' data:; base-uri 'self'; form-action 'self'; frame-ancestors 'self'" always;