Rails app using Kickstarter rack-attack
In my config / rack-attack.rb file, I have:
class Rack::Attack Rack::Attack.blacklist ('block ip') do |req|
This worked fine until I started using CloudFlare. Now req.ip is the cloud IP address, and the actual IP address of the end user
I had a similar problem when trying to save a user's IP address in my server logs (this is saving Cloudflare IP addresses). To fix this, I added the following to the application controller:
module ActionDispatch class Request < Rack::Request alias :remote_ip_orig :remote_ip def remote_ip @remote_ip ||= (@env['HTTP_CF_CONNECTING_IP'] || remote_ip_orig) end end end
Is there a similar process for using HTTP_CF_CONNECTING_IP as req.ip in a rack?
source share