Skip to content

Commit

Permalink
Ignore S3 requests in Rack::Attack
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Aug 20, 2024
1 parent 945711c commit eb6f263
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
Rack::Attack.safelist_ip(ip_or_subnet)
end

Rack::Attack.safelist "allow S3 redirects" do |request|
regexes = [
%r~https://[^/]+?/rails/active_storage/blobs/redirect/[A-Za-z0-9=]+--[A-Za-z0-9=]+/~,
%r~https://[^/]+?/rails/active_storage/representations/redirect/[A-Za-z0-9=]+--[A-Za-z0-9=]+/[A-Za-z0-9=]+--[A-Za-z0-9=]+/~
]

regexes.any? { _1.match? request.url }
end

Rack::Attack.throttle('requests by ip', limit: 100, period: 10, &:ip)

Rack::Attack.blocklist('secure admin logins') do |req|
Expand Down

0 comments on commit eb6f263

Please sign in to comment.