-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More elegant way to block IPs? #111
Comments
In this block, Rack::Attack.blacklist('block <ip>') do |req|
# if variable `block <ip>` exists in cache store, then we'll block the request
Rails.cache.fetch("block #{req.ip}").blank?
end And yep, this sounds like a reasonable way to manage a blacklist set by admins. We could make an "Advanced Configuration" page in the project wiki to record these sorts of advanced techniques. We can link to that page from the README and "Example Configuration" to keep the README simple :) Some other possible techniques for inclusion:
|
Also, if you're using a redis instance as your caching store, I believe you can use sets as values which would be an easier data structure to manage (otherwise how would you list the currently blacklisted IPs?) |
Ahh, yes, I meant I like the idea of an "Advanced Configuration" page on the wiki... |
👍 pure awesomeness. Thanks @zmillman! |
👏 Thanks @zmillman |
Any time 😺 I think this can be closed now? |
The current documentation illustrates a static method to blocking/blacklisting an ip address:
I've been thinking about a more "elegant" (i.e., dynamic really) solution to blocking/blacklisting IPs. How about the following approach?
In the case of ip
1.2.3.4
, this snippet simply checks if the cache store has a variable calledblock 1.2.3.4
, which can be managed by a site maintainer via Rails console:Thoughts? I haven't tested this out. If you think the approach is good, we can update the docs.
Edit
Meant
Rails.cache.fetch("block #{req.ip}").present?
instead ofRails.cache.fetch("block #{req.ip}").blank?
The text was updated successfully, but these errors were encountered: