I'm trying to make reCAPTCHA work along with a strict Content Security Policy. This is the basic version I have, which works correctly:
HTML
<script src='//www.google.com/recaptcha/api.js' async defer></script>
HTTP Headers
Content-Security-Policy: default-src 'self'; script-src 'self' www.google.com www.gstatic.com; style-src 'self' https: 'unsafe-inline'; frame-src www.google.com;
However, I would like to get rid of the unsafe-inline
in the style-src
section. On the documentation, it is written that:
We recommend using the nonce-based approach documented with CSP3. Make sure to include your nonce in the reCAPTCHA api.js script tag, and we'll handle the rest.
But I can't make it work... This is what I tried:
HTML
<script src='//www.google.com/recaptcha/api.js' nonce="{NONCE}" async defer></script>
HTTP Headers
Content-Security-Policy: default-src 'self'; script-src 'self' https: 'nonce-{NONCE}'; style-src 'self' 'nonce-{NONCE}'; child-src www.google.com;
And this is the error I get on Chrome 53:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' https: 'nonce-{NONCE}'". Either the 'unsafe-inline' keyword, a hash ('sha256-MammJ3J+TGIHdHxYsGLjD6DzRU0ZmxXKZ2DvTePAF0o='), or a nonce ('nonce-...') is required to enable inline execution.
What I am missing?