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

Remove support for CSRF tokens #187

Closed
atruskie opened this issue Mar 10, 2015 · 4 comments
Closed

Remove support for CSRF tokens #187

atruskie opened this issue Mar 10, 2015 · 4 comments

Comments

@atruskie
Copy link
Member

There is legacy support in the angular app for sending CSRF tokens back to the rails API.

However it seems that CORS support in rails/browsers means we don't need to worry about CSRF tokens anymore.

@cofiem can you confirm the above is accurate?

@cofiem
Copy link
Contributor

cofiem commented Mar 28, 2015

I'm really not sure.

Looks like we might need something like OAuth - APIs are still vulnerable. API and UI could use different auth mechanisms. This is not ideal, since then the UI can't use the API for a single page app.

Easiest is to rely on CORS for API and CSRF token for UI. Still potential for CSRF in API. Hardest, but most secure is OAuth for API, where key can be used by UI.

Resources:

@atruskie
Copy link
Member Author

The other option is to include the CSRF tokens. Support is already there, just no way to get a token from server at the moment, and not sure of semantics of reusing the token multiple times in concurrent AJAX requests.

@cofiem
Copy link
Contributor

cofiem commented Mar 28, 2015

This seems to give the answer: http://stackoverflow.com/questions/7600347/rails-api-design-without-disabling-csrf-protection

In responses to authenticated API requests, include the CSRF token.

This is partially implemented in https://github.com/QutBioacoustics/baw-server/blob/develop/app/controllers/application_controller.rb#L85

Next Steps

Server side:

  • Change the server CSRF implementation to include a CSRF token in a cookie named XSRF-TOKEN only for logged in users
  • Check that API requests from logged in users include a valid CSRF token in the X-XSRF-TOKEN header

Client Side:

  • Angular should get the CSRF token from a cookie named XSRF-TOKEN. It will only be available to logged in users.
  • set angular to include the CSRF token in a header named X-XSRF-TOKEN in requests made by logged in users.

@atruskie
Copy link
Member Author

After much debugging and pain, we've decided that an auth token (as opposed to using cookies + xsrf tokens is ideal).

For now, in development mode, only auth tokens will be used.

When deployed to staging / production, angular's is built XSRF token parsing (from cookies) will kick in and also in work in addition to the auth token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants