Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trusted-types and require-trusted-types-for CSP Directive #486

Merged
merged 10 commits into from
Aug 2, 2022

Conversation

KyFaSt
Copy link
Contributor

@KyFaSt KyFaSt commented Jun 8, 2022

All PRs:

  • Has tests
  • Documentation updated

Adding a new CSP directive

This PR adds support for the TrustedTypes CSP directives, require-trusted-types-for and 'trusted-types'.

  • Is the directive supported by any user agent? If so, which?
    TrustedTypes are available in Chrome 83, Edge 83 and a polyfill exists for browsers that don't currently support.

  • What does it do?
    require-trusted-types-for disallows using strings with DOM XSS injection sink functions (functions like Document.write, Element.InnerHtml), and requires matching types created by Trusted Type policies.

  • What are the valid values for the directive
    require-trusted-types-for only allows script.
    trusted-types allows a list of strings, including one 'allow-duplicates' which allows multiples of the same named policy to be created.

@KyFaSt KyFaSt requested a review from a team June 8, 2022 16:35
@KyFaSt KyFaSt changed the title Kyfast add trusted types Add trusted-types and require-trusted-types-for CSP Directive Jun 8, 2022
Copy link
Contributor

@lgarron lgarron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

A few small optional nits.

lib/secure_headers/headers/content_security_policy.rb Outdated Show resolved Hide resolved
expect(csp.value).to eq("trusted-types blahblahpolicy")
end

it "allows duplicate policy names in trusted-types directive" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to test 'none' explicitly as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, probably. I'll add that

@KyFaSt KyFaSt merged commit 494b75f into main Aug 2, 2022
@KyFaSt KyFaSt deleted the kyfast-add-trusted-types branch August 2, 2022 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants