Pagefind WebAssembly & CSP Hash Isolation
How to run zero-telemetry client-side full-text search under strict Content Security Policies without unsafe-eval.
Setup
Pagefind compiles its search engine to WebAssembly, and browsers require 'wasm-unsafe-eval' in script-src to instantiate it. Adding that directive site-wide would weaken every page for the sake of one.
Method
- Build the index after
next buildfrom the prerendered article HTML only. - Add
'wasm-unsafe-eval'in the proxy for the exact route/search, nowhere else. - Check in a real browser that search works, that
eval()is still refused on/search, and that other pages carry no WebAssembly permission.
Outcome
All three checks passed. The decision is recorded in ADR 0006, and the route has been in use since Sprint 2. Try it on the search page.
Discussion
Loading the discussion…