ruby on rails - Overiding request.forgery_whitelisted? -
when method called in 1 of rails controllers check if ip address of user on trusted list, , if override request.forgery_whitelisted? method true csrf protection isn't enforced.
a blog post have read seems suggest declaring following in controller action achieve still throws csrf protection error.
if request.remote_ip = "127.0.0.1" def request.forgery_whitelisted?; true; end end
is there somewhere else needs happen in order override method enough take effect?
either of following should work:
- override/monkey-patch 'verify_authenticity_token' method in applicationcontroller:
def verify_authenticity_token super unless request.remote_ip = '127.0.0.1' # todo: replace actual white-listing logic end
- monkey-patch 'forgery_whitelisted?' method:
module actiondispatch class request def forgery_whitelisted? super if remote_ip == '127.0.0.1' # todo: replace actual white-listing logic end end end
Comments
Post a Comment