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

Skip forgery protection in api controllers #2800

Merged
merged 3 commits into from
Oct 17, 2018

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Jul 18, 2018

Fixes #2799

Rails is now enabling forgery protection by default so we need to explicitly disable it for api requests, as described here:

http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html

This PR also enables forgery protection by default in the specs dummy app so that we can really test that the api code is working in a real Rails 5.2+ environment.

@kennyadsl kennyadsl self-assigned this Jul 18, 2018
This is how new (Rails 5.2+) apps are generated by default starting
from rails/rails@ec4a836 commit.

This change makes api specs fail since json POST requests are now
under forgery protection but we have a token based authentication
in place that should replace this check. This will be handled in
a next commit.

We are applying this changes only when rails version is >= 5.2
link_to with `method: :put` uses rails-ujs to append the csfr token
to the request taking that form a specific tag in the <head>.

These specs was only passing since forgery protection was previously
disabled in test mode.
Rails is now enabling forgery protection by default so we need
to explicitly disable it for api requests, as described here:

http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
@kennyadsl kennyadsl force-pushed the forgery-protection-api branch from 62f3245 to 6f3f172 Compare July 18, 2018 16:50
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@kennyadsl kennyadsl merged commit 8fd6b1f into solidusio:master Oct 17, 2018
@kennyadsl kennyadsl deleted the forgery-protection-api branch October 17, 2018 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants