0.0
No commit activity in last 3 years
No release in over 3 years
A rack middleware for blocking requests using Cloudflare IP Geolocation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.12
~> 10.0
 Project Readme

Rack::Geofilter

A simple gem to block traffic from unauthorized countries. Useful in case your service is not available in those countries or if you are under attack.

It currently relies on the CF-IPCountry added by Cloudflare firewall.

If you do not use that service you can not use this gem.

Installation

Add this line to your application's Gemfile:

gem 'rack-geofilter'

And then execute:

$ bundle install

Usage

To use with Rails, add to your config/application.rb the following line

config.middleware.insert_before ActionDispatch::RemoteIp, Rack::Geofilter

Then setup the environment variable BLOCKED_COUNTRIES with a comma separated list of the ISO 3166-1 Alpha-2 codes of the countries you want to block, e.g.,

BLOCKED_COUNTRIES="UA,RU,JP,KP,KR"

This will block the traffic from those countries and return

451 Service not available in country of origin

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alessio-signorini/rack-geofilter.

License

The gem is available as open source under the terms of the MIT License.