rack_attack.rb 671 B

1234567891011121314151617
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. #
  3. # Throttle password reset requests
  4. #
  5. API_V1_USERS__PASSWORD_RESET_PATH = '/api/v1/users/password_reset'.freeze
  6. Rack::Attack.throttle('limit password reset requests per username', limit: 3, period: 60) do |req|
  7. if req.path == API_V1_USERS__PASSWORD_RESET_PATH && req.post?
  8. # Normalize to protect against rate limit bypasses.
  9. req.params['username'].to_s.downcase.gsub(%r{\s+}, '')
  10. end
  11. end
  12. Rack::Attack.throttle('limit password reset requests per source IP address', limit: 3, period: 60) do |req|
  13. if req.path == API_V1_USERS__PASSWORD_RESET_PATH && req.post?
  14. req.ip
  15. end
  16. end