Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2014 12:42
Show Gist options
  • Save anonymous/3dbe80256f70d7f261b3 to your computer and use it in GitHub Desktop.
Save anonymous/3dbe80256f70d7f261b3 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
if LOCAL_SETTINGS['ip_address_whitelist'] && LOCAL_SETTINGS['whitelisted_pages']
class Rack::Attack
#if request.path.includes?(LOCAL_SETTINGS['whitelisted_pages'])
LOCAL_SETTINGS['whitelisted_pages'].map! { |str| Regexp.new(str) }
blacklist('allow whitelisted pages') do |req|
LOCAL_SETTINGS['whitelisted_pages'].none? { |regexp| req.path =~ regexp }
end
#elsif remote.request_ip.includes?(LOCAL_SETTINGS['ip_address_whitelist'])
blacklist('allow from localhost') do |req|
!LOCAL_SETTINGS['ip_address_whitelist'].include?(req.ip)
end
#end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment