mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Clarify algorithm
This commit is contained in:
parent
0ca7b8cfac
commit
27a13f6971
2 changed files with 23 additions and 8 deletions
25
README.md
25
README.md
|
|
@ -34,10 +34,27 @@ Note that `Rack::Attack.cache` is only used for throttling; not blacklisting & w
|
|||
|
||||
The Rack::Attack middleware compares each request against *whitelists*, *blacklists*, *throttles*, and *tracks* that you define. There are none by default.
|
||||
|
||||
* If the request matches any **whitelist**, it is allowed. Blacklists and throttles are not checked.
|
||||
* If the request matches any **blacklist**, it is blocked. Throttles are not checked.
|
||||
* If the request matches any **throttle**, a counter is incremented in the Rack::Attack.cache. If the throttle limit is exceeded, the request is blocked and further throttles are not checked.
|
||||
* If the request was not whitelisted, blacklisted, or throttled; all **tracks** are checked.
|
||||
* If the request matches any **whitelist**, it is allowed.
|
||||
* Otherwise, if the request matches any **blacklist**, it is blocked.
|
||||
* Otherwise, if the request matches any **throttle**, a counter is incremented in the Rack::Attack.cache. If the throttle limit is exceeded, the request is blocked.
|
||||
* Otherwise, all **tracks** are checked, and the request is allowed.
|
||||
|
||||
The algorithm is actually more concise in code: See [Rack::Attack.call](https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack.rb):
|
||||
|
||||
def call(env)
|
||||
req = Rack::Request.new(env)
|
||||
|
||||
if whitelisted?(req)
|
||||
@app.call(env)
|
||||
elsif blacklisted?(req)
|
||||
blacklisted_response[env]
|
||||
elsif throttled?(req)
|
||||
throttled_response[env]
|
||||
else
|
||||
tracked?(req)
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
## About Tracks
|
||||
|
||||
|
|
|
|||
|
|
@ -50,10 +50,8 @@ module Rack::Attack
|
|||
req = Rack::Request.new(env)
|
||||
|
||||
if whitelisted?(req)
|
||||
return @app.call(env)
|
||||
end
|
||||
|
||||
if blacklisted?(req)
|
||||
@app.call(env)
|
||||
elsif blacklisted?(req)
|
||||
blacklisted_response[env]
|
||||
elsif throttled?(req)
|
||||
throttled_response[env]
|
||||
|
|
|
|||
Loading…
Reference in a new issue