-
Notifications
You must be signed in to change notification settings - Fork 888
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
Add allow_no_origin option to CSRF #3512
Conversation
Things to discuss:
|
I think the name is fine. I thought about |
Great! Wrote up some docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, and I tested it on my app and confirmed that it fixes my issue - POST requests now work if the Referer
header is disabled, but still require a correct CSRF token.
There were just a couple of tiny things in the docs/comments I noticed. Thanks again for implementing this so quickly, I really appreciate it!
Thanks for catching those! Changes made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, I would say the client should make sure to send Origin, especially when the spec requires it, but if someone wants to turn a knob to turn off a security feature, this isn't half bad.
32cc1ae
to
0706420
Compare
Honestly I feel like the default for this should be |
To clarify it seems to me like the current logic is: same domain request -> no origin header sent, use referer I think (without testing) that even if you turn off the privacy settings named by @Deimos, the Origin header will still be sent on cross domain requests, and this PR is really focused on fixing same domain requests. The common case here, to me, should be permissive as compliant user agents will probably still sent an Origin header on cross-domain requests even in private browsing situations because it hides the origin's path and only shows the domain. The spec also leaves room for "null" as the value of the Origin header, which we aren't supporting atm but I'd claim should be handled permissively if set, which it is not right now. My proposed changes:
|
Personally, I'd support the check being disabled by default, at least for same-domain requests. I think the really key thing to recognize is that the token-based method is already considered strong, and it is individually good protection. The Origin/Referer check is just a second (weak) layer that isn't truly reliable and can cause issues like this. In the OWASP cheatsheet that I linked in the issue, it says:
The Origin check is one of the "Defense in Depth Mitigations". It's not an essential part, and wouldn't be considered proper protection on its own. The recommendation in the cheatsheet is:
|
I opened #3518, please let me know what you folks think. |
Fixes #3508