rack-attack/lib/rack/attack
Aaron Suggs 76c2e31430 Normalize request paths when using Rails' ActionDispatch
The issue
---

When using rack-attack with a rails app, developers expect the request
path to be normalized. In particular, trailing slashes are stripped so
a request path "/login/" becomes "/login" by the time you're in
ActionController.

Since Rack::Attack runs before ActionDispatch, the request path is not
yet normalized. This can cause throttles and blacklists to not work as
expected.

E.g., a throttle:

    throttle('logins', ...) {|req| req.path == "/login" }

would not match a request to '/login/', though Rails would route
'/login/' to the same '/login' action.

The solution
---

This patch looks if ActionDispatch's request normalization is loaded,
and if so, uses it to normalize the path before processing throttles,
blacklists, etc.

If it's not loaded, the request path is not modified.

Credit
---
Thanks to Andres Riancho at Include Security for reporting this issue.
2015-12-18 11:12:11 -05:00
..
store_proxy Merge pull request #119 from stanhu/add-delete-interface 2015-04-16 14:11:58 -04:00
allow2ban.rb Make Rack::Attack a class and Rack::Attack.new return an instance of that class, rather than Rack::Attack. 2014-03-28 14:53:51 +11:00
blacklist.rb Make Rack::Attack a class and Rack::Attack.new return an instance of that class, rather than Rack::Attack. 2014-03-28 14:53:51 +11:00
cache.rb Support the ability to reset Fail2Ban count and ban flag 2015-05-22 09:47:32 -04:00
check.rb Added limit and period options to track. Delegates [] to Throttle if they are present otherwise Check. 2014-05-19 11:11:01 -07:00
fail2ban.rb Support the ability to reset Fail2Ban count and ban flag 2015-05-22 09:47:32 -04:00
path_normalizer.rb Normalize request paths when using Rails' ActionDispatch 2015-12-18 11:12:11 -05:00
request.rb Improve documentation of Rack::Attack::Request 2014-06-17 11:37:25 -07:00
store_proxy.rb Move individual proxy classes to separate files 2014-04-15 16:19:43 +01:00
throttle.rb Allow throttle period option to be a proc 2014-09-19 19:32:39 +02:00
track.rb Changed track checker to track filter. Made track filter tests more clear. 2014-05-22 10:11:23 -07:00
version.rb Update changelog for #118; bump to v4.3.0 2015-04-16 14:06:46 -04:00
whitelist.rb Make Rack::Attack a class and Rack::Attack.new return an instance of that class, rather than Rack::Attack. 2014-03-28 14:53:51 +11:00