I'm working in a legacy rails application, I'm trying to clean up some CSRF vulnerabilities. If I remove the hidden CSRF field from the form I can still successfully submit the form.
The only indication that something is amiss is a warning in the logs: WARNING: Can't verify CSRF token authenticity
.
There are some pages where the protect_from_forgery
will catch the request and the app will crash if there is no csrf token but its hit and miss depending on the page: eg. the login page works without the token but the update user page does not.
I've tried coming up with a custom strategy (suggested by Marc Gauthier) for protect_from_forgery
, something like:
protect_from_forgery with: :MyStrategy
class MyStrategy
byebug
def initialize(controller)
@contriller = controller
end
def handle_unverified_request
puts "HELLO!"
Rails.logger.warn [
"handle_unverified_request",
"#{@controller.controller_name}-#{@controller.action_name}"
].join(" - ")
end
end
This didn't seem to do anything when starting the app the byebug
call will pause but I never get the puts
message or the error log.
I've also tried the normal strategies such as with: :exception
but nothing changes, some pages it works and some it doesn't, but they are consistent.
ApplicationController
(which is presumably where you callprotect_from_forgery
) could be helpful. – Clemens KoflerApplicationController
is over 400 lines long and I wouldn't feel comfortable sharing that much from their application. Is there something specific I should look for or a particular method you'd like to see? I realize that's not very helpful, I'm just hoping somebody may have encountered something similar. – tfantina