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

feat: possibility to add nonce attribute on script and style tags #2996

Conversation

erwingeiger
Copy link

This is about this topic: #1392
I added the possibility to add a nonce attribute on the <style> and <script> tags who are dynamically created by Stencil.
The value of the nonce attribute can be given with a global window variable.

@erwingeiger erwingeiger requested a review from a team August 10, 2021 14:42
@erwingeiger
Copy link
Author

Update.

After implementing the nonce, we still have problems with unsafe-eval. I've seen someone has a solution for this: #1287. Unfortunately the PR was closed because it was not supported in older browsers. Now we are a few years later. IE11 is not supported anymore. Is it possible to add it now?

@kliehm
Copy link

kliehm commented Jan 11, 2022

FYI, Firefox blocks all inline styles without a nonce. So basically Stencil cannot be used in production. Please prioritize this issue!

@rwaskiewicz
Copy link
Contributor

rwaskiewicz commented Jan 11, 2022

@kliehm Can you provide an example of Firefox blocking inline styles without a nonce? I'm able to get the following (although basic) HTML with inline CSS to render just fine in the following versions of Firefox:

  • 95.0.2 (64-bit)
  • 96.0b10 (64-bit)
<!DOCTYPE html>
<html>
<body>

<h1 style="color:blue;text-align:center;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>

</body>
</html> 

EDIT: I didn't see #3203 until after I commented here. Let's move the discussion to #3203

@erwingeiger
Copy link
Author

@rwaskiewicz It will go wrong where insertBefore is being used. Take this as an example.
Screenshot 2022-03-10 at 11 57 23

Maybe te best solution would be what I created in this PR: #2996
We still use this solution but it's a 'hacky' way. Everytime we update Stencil core we have to manually add this functionality to create these nonce values.

Could you add this functionality in the core? A lot of people would be very pleased!

@erwingeiger
Copy link
Author

Update.

After implementing the nonce, we still have problems with unsafe-eval. I've seen someone has a solution for this: #1287. Unfortunately the PR was closed because it was not supported in older browsers. Now we are a few years later. IE11 is not supported anymore. Is it possible to add it now?

What I said above is solved because we don't support IE11 anymore. Using the nonce is still necessary but with that we will not get any errors anymore

@rwaskiewicz
Copy link
Contributor

Initial support for CSP Nonces have been added in today's release of Stencil 2.22.1, with our official guidance on nonce usage with Stencil published here. As a result, I'm going to close this pull request. Thanks again for helping making Stencil better!

@erwingeiger
Copy link
Author

Initial support for CSP Nonces have been added in today's release of Stencil 2.22.1, with our official guidance on nonce usage with Stencil published here. As a result, I'm going to close this pull request. Thanks again for helping making Stencil better!

That is great news @rwaskiewicz! Thank you for this.

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