I successfully setup CSP on my flask app using Talisman, but the only item I haven't managed to get working is adding a nonce to the Google reCAPTCHA <style>
tag on my Contact form.
I've used the custom flask-wtf RECAPTCHA_HTML
Config option, and my rendered html now looks like this:
<script {{ csp_nonce() }} src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="aYSDvp4uev5dhAGsk6GbGRKEg7UFNmYc1JP9FSKf"></div>
How do I get Flask/Talisman/Flask-wtf to render the {{ csp_nonce() }}
so that my rendered html looks more like this:
<script nonce="RYcJMNtXC7nBC4iYECnzildNF6qBMnoT" src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="aYSDvp4uev5dhAGsk6GbGRKEg7UFNmYc1JP9FSKf"></div>
I've tried escaping the curly braces (ie. using \{\{
) and adding |safe
in the html template, but no luck there.
My actual template reads:
{{ form.recaptcha }}
Cheers.