I have a Rails application with login function which I have
protect_from_forgery with: :exception set on application_controller.rb.
I had encountered a problem where some user had been shown the exception page when they do the following actions:
- Open two tabs with a browser to the login screen.
- Log in using the first tab and then log out.
- Switch to the second tab and then proceeding to log in.
- The second tab resulted in exception screen due to the reason that session cookies already changed because the user had logged in and logged out with another tab.
I also consider changing protect_from_forgery with: :exception to protect_from_forgery with: :reset_session but it will allow CSRF attack which mentioned in this site: https://rubyplus.com/articles/4921-Rails-Forgery-Protection-Basics
I am wondering how other rails application tackles this problem.
You can try a couple of things here:
1) Rescue the exception:
2) Override handle_unverified_request in you Application controller:
3) Or just use a
prepend_before_actionin your ApplicationController:Hope it helps! :)