mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Update advanced_configuration.md
This commit is contained in:
parent
590ea36908
commit
1fa555f37c
1 changed files with 17 additions and 1 deletions
|
|
@ -91,3 +91,19 @@ Rack::Attack.blocklist('basic auth crackers') do |req|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Match Actions in Rails
|
||||||
|
|
||||||
|
Instead of matching the URL with complex regex, it can be much easier to mach specific controller actions:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Rack::Attack.safelist('unlimited requests') do |request|
|
||||||
|
safelist = [
|
||||||
|
'controller#action',
|
||||||
|
'another_controller#another_action'
|
||||||
|
]
|
||||||
|
route = (Rails.application.routes.recognize_path request.url rescue {}) || {}
|
||||||
|
action = "#{route[:controller]}##{route[:action]}"
|
||||||
|
safelist.any? { |safe| action == safe }
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue