How can you block or filter IP addresses on Heroku?
You should check out rack-attack. Looks like it does the same as rack-block, but is much more widely used and updated frequently. To block a specific IP you can do this:
# Block requests from 1.2.3.4Rack::Attack.blacklist('block 1.2.3.4') do |req| # Requests are blocked if the return value is truthy '1.2.3.4' == req.ipend
I added 'rack-block' as Rack middleware. In config/initializers, add a new file:
YourApp::Application.configure do config.middleware.insert_before(Rack::Lock, Rack::Block) do # Add your rules with the rack-block syntax in here endend
Works like a charm.