Skip to content

Instantly share code, notes, and snippets.

@julianlconnor
Last active April 21, 2016 16:02
Show Gist options
  • Save julianlconnor/bb58de878357ea458c4013d006426df5 to your computer and use it in GitHub Desktop.
Save julianlconnor/bb58de878357ea458c4013d006426df5 to your computer and use it in GitHub Desktop.
rack attack, whitelist cloudflare
class Rack::Attack
CLOUDFLARE_SUBNETS = [
IPAddr.new("103.21.244.0/22"),
IPAddr.new("103.22.200.0/22"),
IPAddr.new("103.31.4.0/22"),
IPAddr.new("104.16.0.0/12"),
IPAddr.new("108.162.192.0/18"),
IPAddr.new("131.0.72.0/22"),
IPAddr.new("141.101.64.0/18"),
IPAddr.new("162.158.0.0/15"),
IPAddr.new("172.64.0.0/13"),
IPAddr.new("173.245.48.0/20"),
IPAddr.new("188.114.96.0/20"),
IPAddr.new("190.93.240.0/20"),
IPAddr.new("197.234.240.0/22"),
IPAddr.new("198.41.128.0/17"),
IPAddr.new("199.27.128.0/21")
]
whitelist("Always allow CloudFlare") do |req|
!!CLOUDFLARE_SUBNETS.find { |subnet| subnet === req.ip }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment