Yes, the docs page is up-to-date, and it is not enough to only add the header, you need the other parts as well. This way of nonce-based CSP works on 24.5 and newer. For an example application, please check out the repository at GitHub - vaadin/flow-crm-tutorial at 24.5-strict-csp
Ok thank you and the csp.js must be also added -do i need to modify it or is it static?
Once it works i should see a green check for it on securityheaders.com or is there also a way to check it locally? (I dont see the header in network tab of developer console)
Edit: vaadin.productionMode=true in application.properties and run from IntelliJ with vm option -Dspring.profiles.active=prod works.
now i see the Header in devtools from the browser. But the app loads infinit
I get the following issue in the browser console:
Refused to execute inline script because it violates the following Content Security Policy directive: “script-src ‘nonce-xxxxx’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-4xxxxx’), or a nonce (‘nonce-…’) is required to enable inline execution.
Refused to create a worker from ‘http://localhost:8080/sw.js’ because it violates the following Content Security Policy directive: “script-src ‘nonce-xxx-3exxx7’”. Note that ‘worker-src’ was not explicitly set, so ‘script-src’ is used as a fallback.
Looks like it doesnt work without adding something
And the error contains another one, is that correct?
Refused to execute inline script because it violates the following Content Security Policy directive: “script-src ‘self’ ‘nonce-d9cc58xxxxxx-e5d4defab4ff’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-42l3QX/grwVfMPqfeV2KpGFj3WKVY5nMfWpTY5CMQmE=’), or a nonce (‘nonce-…’) is required to enable inline execution.
Are you using any Hilla features? The CSP only works for Flow, not Hilla.
Also, please clone the GitHub - vaadin/flow-crm-tutorial at 24.5-strict-csp repository and check if you are able to run the app from that branch (24.5-strict-csp). mvn spring-boot:run -Pproduction from command line should do it.
In my other app it’s the same script which has no nonce attribute and prevent the app from loading. No PWA, no Push. Using Vaadin 24.5.0 on it and on the other app its 24.5.5
Shouldnt be the demo also be with nonce in the scripts? Fusion CRM Tutorial Dont see them, also there is no header present
In my own app (which is not loading because of the script error) the header is set and securityheaders.com doesn’t complaint about its missing. So generally it works, but the script prevent the app from working
so the app starts and securityheaders.com shows a green tag for CSP. so far so good. But the val Method should be removed from FlowClient.js. Is that a bug or does any other add-on write into this file?
Great that you got forward. I updated the CRM tutorial 24.5-strict-csp branch to use latest stable Vaadin version, and added the Hilla exclusion as well. Will also add info about the exclusion to the docs page later on.
For some reason I’m not able to reproduce the issue you have with the FlowClient eval call. I am also not using the ‘self’ keyword in the header, just this what is in the github repo already:
Also, the deployed version of CRM demo is not built from the strict-csp branch so it does not use csp at all. I don’t think there are too many users of this CSP yet since it is such a new feature, I do know a couple though and so far the only reported issue was about push not working and that was fixed.
If it’s possible for you to provide a bare-bones example project that can be used to reproduce the FlowClient eval issue, it would be easier to troubleshoot. Maybe create an issue on Flow repo and attach project there?
thanks for tanking the topic serious and thanks good it works with push ;D Otherwise it would be a showstopper. Unfortunately i can not publish the project yet. Can a addon be the evil which adds the eval method? How could i find out which addon could this be?
If you have a limited set of add-ons you could potentially check the sources and search for offending calls. At least Page.executeJs and Page.addDynamicImport calls are potential offenders.
In my first project i could get CSP to work perfectly. Now i try to add it to antoher project but it want work, there i get the same issue with the flowclient.js
Hilla is excluded, nonce is set (except to <script>window.Vaadin = window.Vaadin ?? {}; window.Vaadin.views = {};</script>)
Well if Hilla is excluded, the <script>window.Vaadin = window.Vaadin ?? {}; window.Vaadin.views = {};</script> part should not be there at all. Not that it really matters since skipping executing that snippet does not break anything if you don’t have any Hilla views.
As for why you don’t get a browser log output for the FlowClient issue, I have no idea. Just to confirm - does this issue break the application, or does it work anyway?