-
Notifications
You must be signed in to change notification settings - Fork 27.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
website with csp header require-trusted-types-for 'script' don't work after release of chrome 83 #13228
Comments
Looks like Trusted Types would be an important feature to support going forward. Considering the offending line in ...the easiest way to turn import DOMPurify from "dompurify"
...
script.src = DOMPurify.sanitize(url) That does add a new dependency, though... Would it be better to create a custom Trusted Types policy? According to that web.dev article, that would be implemented something like if (window.trustedTypes && trustedTypes.createPolicy) { // Feature testing
const escapeHTMLPolicy = trustedTypes.createPolicy('myEscapePolicy', {
createHTML: string => string.replace(/\</g, '<') // Escapes `<` characters to prevent the creation of new HTML elements
})
}
...
script.src = escapeHTMLPolicy.createHTML(url) So, DOMPurify? Custom policy? Something else? |
@tipra34, could I take a look at your source files for https://arcane-refuge-12762.herokuapp.com so I can do a little testing on my end? |
@tywmick here is the code https://github.com/tipra34/next-trusted-types-issue |
I think custom policy would be good, since we dont need any additional features that dompurify provides. |
Well, adding these lines to the beginning of // https://web.dev/trusted-types/#create-a-trusted-type-policy
if (window.trustedTypes && window.trustedTypes.createPolicy) {
const escapeHTMLPolicy = window.trustedTypes.createPolicy(
'myEscapePolicy',
{
createHTML: (string) => string.replace(/</g, '<'), // Escapes `<` characters to prevent the creation of new HTML elements
}
)
url = escapeHTMLPolicy.createHTML(url)
} And actually, putting a few The search continues. |
I added the following code at top of node_modules/next/dist/client/page-loader.js
and changed build is working good. Dev server is not working because of webpack, its setting innerHTML and script src at multiple places. |
Ah good catch! Got it working on my end with production builds, so I'll create a PR for that fix, at least. As far as fixing the dev server, do you think that's something that needs to be fixed in webpack, or should we be able to overcome that on our end if we find all the places it's setting innerHTML and script src's? |
According to me there is no need for solving the development server issue. Since as far as the security headers are concerned, I would prefer them to be on nginx/apache server and not in meta tag. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Bug report
Describe the bug
script loading does not work for site with csp header require-trusted-types-for 'script' don't work after release of chrome 83.
this disables assigning of script.src to unsafe url (non trusted types)
[bug location] (https://github.com/zeit/next.js/blob/7eaf9b8bab4e93b891be89704399644eafe70e21/packages/next/client/page-loader.js#L265)
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
it should work normally
Screenshots
System information
Additional context
related blog
The text was updated successfully, but these errors were encountered: