From 120e480766a0ae43c8533ae31e8e9d5e60cbbbdc Mon Sep 17 00:00:00 2001 From: Suradet Pratomsak Date: Wed, 5 Aug 2026 09:09:37 +0700 Subject: [PATCH] fix: CSP violations - inline script bootstrap + SW network error Three CSP-related fixes: 1. script-src 'unsafe-inline' added to CSP (vercel.json) Trunk 0.21 generates an inline script for WASM bootstrap whose content changes per build (content-hashed filenames). A static SHA-256 hash is non-viable. Documented in SECURITY.md. 2. Service worker network error handling (sw.js) The stale-while-revalidate handler now catches network failures and returns a 503 response instead of an unhandled TypeError. 3. CI csp-verify job updated to allow 'unsafe-inline' in script-src with an explanatory comment. --- .github/workflows/ci.yml | 9 +++++---- SECURITY.md | 11 ++++++++--- static/pwa/sw.js | 23 ++++++++++++++++------- vercel.json | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c3774e..67731d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,17 +166,18 @@ jobs: exit 1 fi - # style-src may contain 'unsafe-inline' (Leptos requirement), but no other source should + # style-src may contain 'unsafe-inline' (Leptos requirement) style_val=$(echo "$csp" | sed -n 's/.*style-src \([^;]*\);.*/\1/p') if echo "$style_val" | grep -q "unsafe-inline"; then echo " style-src contains 'unsafe-inline' (expected for Leptos)" fi - # script-src must NOT contain 'unsafe-inline' + # script-src may contain 'unsafe-inline' (Trunk generates an inline + #