-
Notifications
You must be signed in to change notification settings - Fork 332
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
Ensure support for Trusted Types #4895
Comments
To my knowledge we have had one instance of this coming up on support, with the Accordion component causing a "This document requires 'TrustedHTML' assignment" error. The user in question followed the guidance on using a default policy and as far as I know this solved the immediate problem. I ran a highly unscientific x-govuk Slack poll in February asking about people's awareness of Trusted Types. Of the 8 people that responded, 7 had never heard of it and only 1 is using it in production. So my general sense is that this hasn't yet found much of a foothold in the GOV.UK estate. This may be partially due to the relatively low amount of user-generated content being displayed to other users, which means the XSS attack surface is relatively low to start with? 🤷🏻♂️ |
If we do pick this up, my suggestion would be to try and re-write code to avoid using the sink functions before we start introducing policies etc, unless doing so adds significant amounts of code or complexity. My reasoning for this is:
|
Some useful resources:
|
What
Trusted Types are a relatively new browser feature designed to the DOM XSS attack surface of a website or web app. They are enforced by setting new Content Security Policy (CSP) directives which then lock down 'risky sink functions':
At time of writing, we use
innerHTML
in a few places. We also usesetTimeout
andsetInterval
, but I believe they are only affected if passing a string instead of a function.The scope of this work would be to ensure that if a consumer of GOV.UK Frontend enforces trusted types in their service, GOV.UK Frontend does not trigger any violations.
We would likely need to:
Optionally, we may choose to introduce guidance on using GOV.UK Frontend with Trusted Types, especially if we have to introduce additional policies or rely on polyfills etc.
Why
Updating GOV.UK Frontend to support Trusted Types makes it easier for service teams to adopt Trusted Types, improving the security of government services.
However, there is a workaround for service teams enabling Trusted Types – they can create a default policy. Note that the example default policy provided in the linked guidance introduces a dependency on DOMPurify, a JavaScript library which is approx 21kB minified.
Trusted Types seem to be gaining traction across the web. Chrome's telemetry data suggests that more than 10% of page loads have trusted types enabled.
Trusted Types are currently only supported in Chromium browsers, however Mozilla have shown positive signals and Webkit at least seem to be considering it.
Who needs to work on this
Developers, tech writer?
Who needs to review this
Developers
Done when
The text was updated successfully, but these errors were encountered: