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

ActionController::InvalidCrossOriginRequest after redirect in rails >= 4.1 #130

Open
MGotink opened this issue Jun 26, 2015 · 3 comments
Open

Comments

@MGotink
Copy link

MGotink commented Jun 26, 2015

I'm getting a ActionController::InvalidCrossOriginRequest exception when I try to redirect to another URL after the file upload.

Since rails 4.1 GET requests with javascript responses are now also covered by CSRF protection: https://github.com/rails/rails/blob/v4.2.2/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L219-L227
It looks like that because the X-Requested-With header is not set in the header (only in the form data) the browser won't use it as a header in the redirected request, triggering the InvalidCrossOriginRequest.

A sample application demonstrating the issue can be found here: https://github.com/MGotink/remotipart-redirect-demo

For now i've disabled forgery protection for the specific action. It would be nice if this wouldn't be necessary, but as far as I can see that might not be possible with the current solution of uploading the files.

@jszwedko
Copy link

Just ran into this as well -- did you find a better workaround @MGotink? Or are you still just disabling protection for that action.

@MGotink
Copy link
Author

MGotink commented Jan 12, 2016

I'm still disabling the CSRF protection for that specific action: protect_from_forgery except: :index

@jszwedko
Copy link

👍 thanks! I'll continue doing the same.

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

No branches or pull requests

2 participants