Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Forked from anonymous/local_settings.yml
Last active August 29, 2015 14:02
Show Gist options
  • Save pier-oliviert/4b03237f83b26b90f919 to your computer and use it in GitHub Desktop.
Save pier-oliviert/4b03237f83b26b90f919 to your computer and use it in GitHub Desktop.
ip_address_whitelist:
- 127.0.0.1
- 1.2.3.4
- 5.6.7.8
whitelisted_pages:
- /assets/.*
- /
- /login
module YourProject
class Application < Rails::Application
whitelist = YAML.load_file(File.expand_path('../local_settings.yml', __FILE__))
Rack::Attack.whitelist 'requests' do |req|
whitelist['whitelisted_pages'].find do |str|
regexp = Regexp.new(str)
req.path =~ regexp
end.any?
end
Rack::Attack.whitelist 'ips' do |req|
whitelist['ip_address_whitelist'].include? req.ip
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment