mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Merge pull request #402 from collimarco/patch-1
Add example: Match Actions in Rails
This commit is contained in:
commit
9e90b20122
1 changed files with 17 additions and 1 deletions
|
|
@ -90,4 +90,20 @@ Rack::Attack.blocklist('basic auth crackers') do |req|
|
|||
auth.credentials != [my_username, my_password]
|
||||
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