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

CSP Nonce Support for generated files #1392

Closed
MrMcGibblets opened this issue Feb 27, 2019 · 14 comments
Closed

CSP Nonce Support for generated files #1392

MrMcGibblets opened this issue Feb 27, 2019 · 14 comments
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.

Comments

@MrMcGibblets
Copy link

Stencil version:

 @stencil/core@0.18.0

I'm submitting a:
[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
Same as the closed issue - #496

When bundling we automatically create an inline style which violates the strict CSP usage

Whilst a workaround is to add each individual sha to the CSP policy it isn't ideal and not a nice dev experience.

In webpack this was achieved by adding a top-level nonce value which would then be added to all at bundle time. - styled-components/styled-components#887

Expected behavior:
To be able to provide a nonce for styles (should be for all scripts, img etc...) that will be added to all build-generated scripts, styles etc... Allowing apps to be CSP ready out of the box.

Steps to reproduce:
Add CSP Policy for style-src 'self' and run app.

@ionitron-bot ionitron-bot bot added the triage label Feb 27, 2019
@BorntraegerMarc
Copy link

Working in an organization this is a critical feature for us. It's quite a hazzle to add sha values for our styles.

Was there any internal discussion in the ionic team about this feature?

@FrancoisDF
Copy link

Is there any update from the Stencil team in regard of this feature? We also have some concern that limit some of our teams to move ahead with the stencilJs web-components used by our design system.

@ptrot001
Copy link

Hi, Any update on this one? I can't believe nothing have been done yet to handle CSP in stencil libraries. Angular and react have added support for CSP in 2015-2016!

I'm also working in a big organization and CSP is a basic security requirement for us. It's a blocker right now!

Any update would be appreciated! 👍 @adamdbradley ?

Thanks

@alexhhn
Copy link

alexhhn commented Apr 7, 2021

Hi,
Any update on this?

@sandersaspera
Copy link

sandersaspera commented Apr 8, 2021

We also need that quite urgently

@erwingeiger
Copy link

erwingeiger commented Jul 28, 2021

any updates about this? Also our organisation requires to use a CSP.

@sandersaspera
Copy link

sandersaspera commented Aug 2, 2021

any updates about this? Also our organisation requires to use a CSP.

In case that helps: I found out that the inline styles for hydrated components (components are invisible or inherit visibility when having the "hydrated" class) can be suppressed by setting "hydratedFlag: null" in the stencil configuration. Those hydrated styles are supposed to prevent the components from "flickering". Maybe a custom output target could be used to write those css rules into a proper css file and thus not violating the corresponding CSP. There is a corresponding suggestion here (#2245)

@splitinfinities splitinfinities added the Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. label Aug 3, 2021
@ionitron-bot ionitron-bot bot removed the triage label Aug 3, 2021
@splitinfinities
Copy link
Contributor

Hey everyone! Thank you so much for the feedback. We'll be taking this into consideration.

@erwingeiger
Copy link

For your information. Our best solution for now was to fork the source files of Stencil and made adjustments to the files
src/runtime/styles.ts
src/runtime/bootstrap-lazy.ts
and a few others , to add the nonce attribute to the generated style tags.
Then we used this fork as a dependency in our project.

Not the best solution, but it works for now. I hope Stencil will come with a better solution in the near future.

@splitinfinities
Copy link
Contributor

@erwingeiger Would you be able to make a PR into Stencil for that? Or do you believe there's a better approach than what you've done?

@erwingeiger
Copy link

erwingeiger commented Aug 3, 2021

@splitinfinities I would like, but this is a quick and dirty solution. So I think others can make better approaches.
But I can tell what I did.

In the file src/runtime/bootstrap-lazy.ts after the rule visibilityStyle.setAttribute('data-styles', ''); I placed another setAttribute but now with the nonce attribute.

I did this in the files:
src/client/polyfills/css-shim/load-link-styles.ts
src/runtime/bootstrap-lazy.ts
src/runtime/styles.ts

@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Sep 2, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Sep 2, 2021

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.

Thank you for using Stencil!

@ionitron-bot ionitron-bot bot closed this as completed Sep 2, 2021
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 2, 2021
@rwaskiewicz
Copy link
Member

Hey ionitron-bot, we didn't mean to close this. Bad bot!

@rwaskiewicz rwaskiewicz reopened this Sep 3, 2021
@rwaskiewicz rwaskiewicz removed the ionitron: stale issue This issue has not seen any activity for a long period of time label Sep 3, 2021
@rwaskiewicz
Copy link
Member

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 issue. Should anyone run into any issues with the feature, please feel free to open a new issue. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea.
Projects
None yet
Development

No branches or pull requests

9 participants