-
Notifications
You must be signed in to change notification settings - Fork 374
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
CSRF failures due to duplicate XSRF-TOKEN values #1247
Comments
This prevents duplicates but the paths do change as you shuffle about. I don't know how acceptable a solution it is but it should at least prevent the CSRF failures we had. https://github.com/bitemyapp/yesod/commit/5e4cefc9ad3880258d9685849dea1f9ea0daf768 |
Oh, I didn't think about specifying the path when I implemented this. I haven't researched it yet, but
sounds good to me |
@MaxGabriel my solution doesn't currently do that, but I could modify it. I don't really understand what place duplicate cookie values or mostly duplicate ones with different paths are even supposed to mean here. I'd like to understand the problem a bit more first before doing more. |
Here's my guess of what's going on:
|
Hm, I'm having trouble reproing getting the CSRF token for a path like "/signup", not sure why. |
@MaxGabriel We have GHCJS code talking to the backend, did you try performing a CSRF secured AJAX call? |
Yes, using the comment AJAX text field that comes with the scaffolding. I can see the XSRF token in the headers of that POST request, too. |
Ok got it, wasn't thinking that the path needed to be something like:
for the cookie path to be |
* The default path of cookies is the current path making the request * e.g. an AJAX request made from http://example.com/foo/bar would be /foo * This causes multiple CSRF tokens to build up as you navigate a site * This will cause errors if the CSRF tokens have different values, and an invalid token is sent. * Closes #1247
* The default path of cookies is the current path making the request * e.g. an AJAX request made from http://example.com/foo/bar would be /foo * This causes multiple CSRF tokens to build up as you navigate a site * This will cause errors if the CSRF tokens have different values, and an invalid token is sent. * Closes #1247
* The default path of cookies is the current path making the request * e.g. an AJAX request made from http://example.com/foo/bar would be /foo * This causes multiple CSRF tokens to build up as you navigate a site * This will cause errors if the CSRF tokens have different values, and an invalid token is sent. * Closes yesodweb#1247
Presently, what you see in the screenshot will work because the XSRF-TOKEN values are the same, however if they differ, you'll get that CSRF token middleware error we all know and love.
I do not know how two different XSRF tokens were generated (no repro), but it's not clear to me why there isn't a single XSRF token for the
/
path which covers requests being made from other pages anyway.I read this thread: #1016
It did not clear up for me why there should be multiple
X-XSRF-TOKEN
values in the cookies.AFAICT, this code is responsible for the duplicates:
yesod/yesod-core/Yesod/Core/Handler.hs
Lines 858 to 859 in 8bbe91c
Some snippets:
The text was updated successfully, but these errors were encountered: