-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Content Security Policy (CSP) is a security header better documented at https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP
In order to use it with a Prado app it's currently necessary to specify unsafe-inline to let the browser load script and styles that Prado places inline inside the page.
Three possible alternatives:
- move every script/style block to an external file
- calculate an hash for each script/style block and add it to the header
- create a per-response nonce value and add it to each script/style block.
The first alternative is probably the best generic solution, but in order to implement this we would need to create a few new javascript files for each request (eg. for beginScripts and endScripts registered by TClientScripManager), handle their lifecycle (aka delete them after load) and ensure they can't be reached by other clients (they may contain private data).
The second alternative requires Prado to calculate the base64(sha256($content)) for every script and style block, making all of them available to be added to the CSP header. Additional integrity attributes (content hashes) must be present on external scripts. This is solution meant to be used for static scripts, eg. while importing a common library from a CDN.
The third alternative requires Prado to generate a nonce (that is a random string) to be added to the CSP header and then add a "nonce" attribute on every script/style block.
We should possibly move whatever is possible to external scripts (solution 1), create some hooks to permit the generation of hashes for script/style blocks (solution 2) and add support for optional nonces wherever we output a script/style blocks (solution 3).
Once this is in place, a new module can be created taking care of:
- collect the CSP configuration
- output the CSP header
- implement solution 2 (hashes)
- implement solution 3 (nonces)