Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

User agent blocks

  • Loading branch information...
commit 394789e841f41c9a31117af8b2377878724f0812 1 parent f552984
Elad Meidar authored
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/rack/contrib/deflect.rb
15 lib/rack/contrib/deflect.rb
View
@@ -29,6 +29,7 @@ module Rack
# :block_duration Duration in seconds that a remote address will be blocked. Defaults to 900 (15 minutes)
# :whitelist Array of remote addresses which bypass Deflect. NOTE: this does not block others
# :blacklist Array of remote addresses immediately considered malicious
+ # :ignore_agents a list of words from user agents allow in.
#
# === Examples:
#
@@ -52,14 +53,20 @@ def initialize app, options = {}
:interval => 5,
:block_duration => 900,
:whitelist => [],
- :blacklist => []
+ :blacklist => [],
+ :ignore_agents => []
}.merge(options)
end
def call env
- return deflect! if deflect? env
- status, headers, body = @app.call env
- [status, headers, body]
+ if options[:ignore_agents].any? {|word| env["HTTP_USER_AGENT"].downcase.include?(word) }
+ status, headers, body = @app.call env
+ [status, headers, body]
+ else
+ return deflect! if deflect? env
+ status, headers, body = @app.call env
+ [status, headers, body]
+ end
end
def deflect!
Please sign in to comment.
Something went wrong with that request. Please try again.