rack-attack/spec
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
..
integration Clarifying comments for #delete spec method 2015-05-22 13:48:32 -04:00
allow2ban_spec.rb Return 403 Forbidden instead of 401 2014-02-06 21:32:51 +01:00
fail2ban_spec.rb Support the ability to reset Fail2Ban count and ban flag 2015-05-22 09:47:32 -04:00
rack_attack_dalli_proxy_spec.rb Move individual proxy classes to separate files 2014-04-15 16:19:43 +01:00
rack_attack_path_normalizer_spec.rb Normalize request paths when using Rails' ActionDispatch 2015-12-18 11:12:11 -05:00
rack_attack_request_spec.rb Add a custom request class to allow for helper methods. 2014-04-04 14:41:59 -05:00
rack_attack_spec.rb Normalize request paths when using Rails' ActionDispatch 2015-12-18 11:12:11 -05:00
rack_attack_throttle_spec.rb Allow throttle period option to be a proc 2014-09-19 19:32:39 +02:00
rack_attack_track_spec.rb Changed track checker to track filter. Made track filter tests more clear. 2014-05-22 10:11:23 -07:00
spec_helper.rb Normalize request paths when using Rails' ActionDispatch 2015-12-18 11:12:11 -05:00