nibtime / next-safe-middleware

Strict CSP (Content-Security-Policy) for Next.js hybrid apps https://web.dev/strict-csp/
https://next-safe-middleware.vercel.app
MIT License
79 stars 20 forks source link

Hash-based Strict CSP by inline proxy loader (to support Firefox and Safari) #63

Closed nibtime closed 2 years ago

nibtime commented 2 years ago

Motivation

The lib currently uses an approach that injects script hashes as integrity attribute, also for scripts with src attribute.

The problem is that Firefox messes up SRI validation on scripts with src attribute (#5, #47). I conjecture that it's the same with Safari, which supports strict-dynamic since version 15.4, but also doesn't work with this lib.

This doesn't happen with inline scripts. So the idea is to collect and replace all scripts with an src attribute and insert them with a trusted inline proxy loader, so they get transitive trust for strict-dynamic.

References