security: rate limit POST /api/auth with Rack::Attack#101
Open
AjayPAnand wants to merge 1 commit intothoth-tech:10.0.xfrom
Open
security: rate limit POST /api/auth with Rack::Attack#101AjayPAnand wants to merge 1 commit intothoth-tech:10.0.xfrom
AjayPAnand wants to merge 1 commit intothoth-tech:10.0.xfrom
Conversation
Add rack-attack with IP-based throttle (5 requests per 20 seconds) on login to mitigate brute-force and credential stuffing. Return 429 JSON with Retry-After when exceeded. Use MemoryStore for throttle counters so limits apply in development as well as production. changes made:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add rack-attack with IP-based throttle (5 requests per 20 seconds) on login to mitigate brute-force and credential stuffing. Return 429 JSON with Retry-After when exceeded. Use MemoryStore for throttle counters so limits apply in development as well as production.
Implemented brute-force protection for the login endpoint by adding IP-based throttling on POST /api/auth using [Rack::Attack]. This change mitigates brute-force and credential-stuffing attacks while preserving existing authentication behavior.
Fixes #0.1.9 Sr. No. - Brute Force Vulnerability in Login Endpoint
Changes made
Added dependency:
Added gem 'rack-attack' to Gemfile
Ran bundle install to update Gemfile.lock
Enabled middleware:
Added config.middleware.use Rack::Attack in config/application.rb
Added throttle rules:
Created config/initializers/rack_attack.rb
Configured Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Added IP-based throttling for POST /api/auth
Limit: 5 requests per 20 seconds per IP
Added custom throttled response:
Returns HTTP 429 Too Many Requests
JSON response:
{"error":"Too many login attempts. Please try again shortly."}
Includes Retry-After header when available
Added responder compatibility fix:
Updated handling to support Rack::Attack::Request object shape and avoid NoMethodError
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Manual testing steps
Verified:
Requests 1–5 within 20 seconds were processed normally
Request 6+ returned:
HTTP 429 Too Many Requests
JSON error response
Retry-After header
Screenshots 1:

Screenshots 2:

Checklist:
If you have any questions, please contact @macite or @jakerenzella.