-
-
Notifications
You must be signed in to change notification settings - Fork 579
CSRF error when Clearing the Session and Redirecting to a form #886
Comments
I am having an issue with this also. I was following the tutorial linked above and I am unable to post from a form to a database without getting: CSRF token not found in request Here is my render.go file:
And here is the register.html file I call it in:
Here is my output: |
@wwaldbu your issue is different. Your just not setting the token correctly. If you look at your generated html you’ll see that. Your csrf is returning <%= authenticity_token%> instead of the actual token. Is there a reason you’re not using the form helpers? Those will set the token for you as well as generate all that boiler plate bootstrap code. The original issue is if you follow a very particular set of steps involving clearing the session first. |
* In the case realToken was regenerated, a scoped redefinition was overriding the token to nil.
Fixed with #1011. |
I have the same problem (not really sure if it is EXACTLY the same, but..) I'm trying to make an ajax call, and the response is always I have no idea what is a CSRF token since I usually do not code in web.. |
Just to know the goal of the CSRF token: https://en.wikipedia.org/wiki/Cross-site_request_forgery If you're trying to reach your website from another one, it's normal that it fails. You can deactivate the CSRF middleware, but if your application is going to be on the web I will not recommend it. Here is an example using Ajax call and Buffalo: https://github.com/gobuffalo/toodo And FYI:
|
We discussed the case with @markbates on Slack.
Here is the error:
Here is the code I used
I'm using the default form generated by auth:
I reproduce it with migrating down the db and migrating up and seeding my default user.
From here it's the explanation of Mark on Slack:
i can reproduce, not sure i know what the fix is, but here’s what’s happening:
this is where things get interesting.
the page is already rendered with a token, however that token was salted using a salt that was in the session that was clear after the page was drawn; cause cookies.
and that’s how you get a CSRF token in a form but not have it be valid. 🙂
the error message is misleading though.
it was found, but it’s not a valid CSRF token.
the work around would be to just delete the
current_user_id
from the session, but it would be great if someone can figure out a good way to stop this from happening in the future.The text was updated successfully, but these errors were encountered: