Skip to content

Commit

Permalink
Updated Rack Attack configuration to address vulnerabilities in passw…
Browse files Browse the repository at this point in the history
…ord updates.

Changes:
    The fix involves adding a new Rack Attack rule "profile_updates/ip" and
    rewriting the body of the rules "password_resets/ip" and "logins/ip" so
    the the request ip is returned if the rule is triggered.
  • Loading branch information
John Pinto committed Sep 24, 2024
1 parent 56759df commit acf5961
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Updated Rack Attack configuration to address vulnerabilities in password updates.

## v4.2.0

**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**
Expand Down
10 changes: 8 additions & 2 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

# Throttle attempts to a particular path. 2 POSTs to /users/password every 30 seconds
Rack::Attack.throttle "password_resets/ip", limit: 2, period: 30.seconds do |req|
req.post? && req.path == "/users/password" && req.ip
req.ip if req.post? && req.path == "/users/password"
end

# Throttle attempts to a particular path. 4 POSTs to /users/sign_in every 30 seconds
Rack::Attack.throttle "logins/ip", limit: 4, period: 30.seconds do |req|
# Don't apply sign-in rate-limiting to test environment
req.post? && req.path == "/users/sign_in" && req.ip unless Rails.env.test?
(req.ip if req.post? && req.path == "/users/sign_in") unless Rails.env.test?
end

# Throttle attempts to a particular path. 2 POST or PUTS to /users every 30 seconds
# This includes password updates.
Rack::Attack.throttle "profile_updates/ip", limit: 2, period: 30.seconds do |req|
req.ip if (req.put? || req.post?) && req.path == "/users"
end

0 comments on commit acf5961

Please sign in to comment.