I have an express demo site using google sign in button and I have recently added Helmet JS to make the server more secure with the right headers.
Without HelmetJS, the Sign in Button loads without any problem and is able to pick logged in user as well. However after enabling Helmet JS in index.js and setting the required Content Security Policies (CSP) in the Helmet configurations, the following 2 scenarios happen:
To mitigate this, I added crossorigin="anonymous" to the script header like so:
<script crossorigin="anonymous" src="https://accounts.google.com/gsi/client" async defer></script>
as advised here
- Doing this, however, leads to the following CORS error and the button doesn't load, since the client library is not loaded:
I have gone through the following similar SO questions to no avail, I'm not sure if I'm missing something, since there is a lot to absorb for understanding COEP / CORP and others.
- Cross-Origin-Embedder-Policy: how to allow only certain domains?
- Helmet Express ERR_BLOCKED_BY_RESPONSE.NotSameOrigin 200
- Ressources not loaded after setting CSP and CORP headers using Helmet
The other options left is to disable COEP in Helmet, which I'm not sure is advisable. Please help, what exactly is the way forward for using COEP in such a scenario.
Thank you for your time!
Try this configuration of the helmet library - pass the one in constructor: