github / secure_headers

Manages application of security headers with many safe defaults
MIT License
3.16k stars 252 forks source link

Add require-trusted-types-for to CSP #474

Closed dorianmariecom closed 2 years ago

dorianmariecom commented 2 years ago

From https://csp-evaluator.withgoogle.com :

Consider requiring Trusted Types for scripts to lock down DOM XSS injection sinks. You can do this by adding "require-trusted-types-for 'script'" to your policy.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-trusted-types-for

Example:

Content-Security-Policy: require-trusted-types-for 'script';

Feature Requests

Adding a new CSP directive

Screenshot 2021-12-10 at 08 06 37

When used, those functions only accept non-spoofable, typed values created by Trusted Type policies, and reject strings. Together with trusted-types directive, which guards creation of Trusted Type policies, this allows authors to define rules guarding writing values to the DOM and thus reducing the DOM XSS attack surface to small, isolated parts of the web application codebase, facilitating their monitoring and code review.

https://w3c.github.io/webappsec-trusted-types/dist/spec/#require-trusted-types-for-csp-directive

Seems like there is only 'script' as a valid value, not sure

lgarron commented 2 years ago

@dorianmariefr: require-trusted-types-for is implemented in v6.4.0. Does this meet your needs?

dorianmariecom commented 2 years ago

@lgarron I don't maintain an application that uses secure_headers anymore

lgarron commented 2 years ago

Alright, thanks! I'll mark this as closed, and we can use new issues if there is something to change about the implementation.