Description
I'm building a JSON API with an Ember front-end. Therefore, I want to be able to turn of CSRF validation for JSON requests, as references a number of times in previous issues. If I do that, requiring authentication tokens is the only way to secure JSON requests.
However, based on what I can see in https://github.com/gonzalo-bulnes/simple_token_authentication/blob/master/lib/simple_token_authentication/acts_as_token_authentication_handler.rb#L23-L26, this gem delegates to Devise's default authentication mechanism after doing token authentication.
Devise's default authentication makes every request fallback to cookie authentication. That means any existing users will still be using cookies until they sign out & sign back in. Also, when I disable CSRF validation on JSON requests, I'll still be vulnerable to CSRF attacks. The reason I want token authentication is so I can force clients to send identifying information with every request. Falling back to devise's authentication seems to defeat that purpose.
I can think of a few possible ways to solve this:
- Remove the fallback entirely, but that might not work well for existing users
- Only fallback for non-JSON requests by default (maybe with an opt-in for the previous behavior)
- Disable fallback for all requests with opt-in to fallback on all requests
I'm thinking I might implement option 2 and send a PR. @gonzalo-bulnes any thoughts on this?
Activity