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

Getting an ActionController::InvalidAuthenticityToken exception? (R: Take a look at CSRF answers!) #37

Closed
amalagaura opened this issue Mar 7, 2014 · 4 comments
Labels
off topic question When closed, this issue will become part of the FAQ.

Comments

@amalagaura
Copy link

I am having the strangest issue. I am only having successful authentications on GET's. I am passing the email and token via headers, not params: X-User-Email It works on GET, but not on PUT or PATCH.

When I run a debugger it goes to the authenticate_entity_from_token! method only on GET. But on a PATH or PUT I get a ActionController::InvalidAuthenticityToken
and it does not go to the authenticate_entity_from_token! method.

My routes are regular REST resources. It is a simple Rails 4 app with a single model just for testing.

@gonzalo-bulnes
Copy link
Owner

Hi @amalagaura,

The token which is missing is not the authentication token, but the authenticity token - which is a security mecanism used to prevent cross-site request forgery (CSRF).

The behavior you describe seems related to a change that Rails 4 introduced in the forms behavior and does not seem to involve Simple Authentication Token. Does this StackOverflow answer help you?

I can be wrong, but I'm pretty sure that once you'll solve the authenticity token issue, your non-GET requests will go through and token authentication will just go fine. Please keep me updated : )

@amalagaura
Copy link
Author

Thank you for your attention. It was unexpected but I did not figure out the authentication vs authenticity which you pointed out.

I think this Stack Overflow answer is also relevant. When I change the protect_from_forgery line as the comments on the default Rails app suggests it indeed works. I thought that had to do with the error message, but I should have paid attention.

It is out of the scope of this github issue, because I don't understand the full mechanics of CSRF protection. Thank you for your attention. You have done a nice job with this gem.

@gonzalo-bulnes
Copy link
Owner

Be welcome! As you did, I've been reading a bit more about CSRF and, as you pointed it, API do not seem to require CSRF protection.
From the same thread, I find particularly interesting this thought about the registration step.

Thanks for your feedback!

@gonzalo-bulnes
Copy link
Owner

(I've edited the issue title to improve it's discoverability in the solved questions list.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
off topic question When closed, this issue will become part of the FAQ.
Projects
None yet
Development

No branches or pull requests

2 participants