-
-
Save kivanio/f6e0f9cd446fc7f76baf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip_address_whitelist: | |
- 127.0.0.1 | |
- 1.2.3.4 | |
- 5.6.7.8 | |
whitelisted_pages: | |
- /assets/.* | |
- / | |
- /login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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