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

Allow nonce in reCaptcha #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kesara
Copy link

@kesara kesara commented Oct 24, 2017

Issue: #311
This adds a nonce attribute to script tag, which can be set via

RecaptchaField(nonce='<nonce>')

In order to use this, Flask app has to provide the nonce value via header.
Example:

 Content-Security-Policy: object-src 'none'; script-src 'nonce-<nonce>'

@codecov-io
Copy link

codecov-io commented Oct 24, 2017

Codecov Report

Merging #312 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #312      +/-   ##
==========================================
+ Coverage   99.66%   99.66%   +<.01%     
==========================================
  Files          18       18              
  Lines         894      908      +14     
  Branches       74       75       +1     
==========================================
+ Hits          891      905      +14     
  Misses          3        3
Impacted Files Coverage Δ
tests/test_recaptcha.py 100% <100%> (ø) ⬆️
flask_wtf/recaptcha/fields.py 100% <100%> (ø) ⬆️
flask_wtf/recaptcha/widgets.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d4c1dc...09fb2b6. Read the comment docs.

@lepture
Copy link
Contributor

lepture commented Oct 25, 2017

@kesara You need to add documentation for nonce.

@pogliamarci
Copy link

pogliamarci commented Apr 3, 2019

Hi @kesara, I was looking at this patch to integrate it in a small project of mine that uses nonce-based CSP. I was wondering, why is the nonce parameter to RecaptchaField used as a string rather than being a callable?

I'm using custom code to generate the nonce, but from what I see also popular extensions such as flask-talisman generate the nonce as a parameter of request, so the value of the nonce is not available when instantiating the class (and it shouldn't be, as the nonce changes for every request), as it would be accessed outside Flask's request context.

Perhaps I'm missing something... how do you generate the CSP nonce to use your patch?

@kesara
Copy link
Author

kesara commented Apr 4, 2019

Hi @pogliamarci, I totally forgot that this PR is hanging. :(
In my use case we end up, allowing everything required for reCaptcha in CSP rules.
IIRC initial idea was to generate the nonce for every request (anyway you like) and pass it to the headers

Your plan to use flask-tailsman makes more sense, but that also means flask-wtf will have to add flask-talisman as a dependency?
May be introduce a new configuration option and use flask-tailsman if that present?

@pogliamarci
Copy link

pogliamarci commented Apr 5, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants