fix: add rate limiting in the forward auth endpoint#555
Conversation
📝 WalkthroughWalkthroughThe changes implement username-based account locking across the authentication flow, replacing IP-based rate limiting. New HTTP headers expose lock status and reset times. Login attempts are now recorded by username in both middleware and controller layers, with account-locked checks performed early in the request flow. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Middleware as Auth Middleware
participant AccountLock as Account Lock Service
participant Controller as Login Controller
participant Storage as User Storage
Client->>Middleware: HTTP request with Basic Auth
Middleware->>AccountLock: IsAccountLocked(username)
alt Account is locked
AccountLock-->>Middleware: true + remaining duration
Middleware->>Middleware: Set x-tinyauth-lock-locked: true<br/>Set x-tinyauth-lock-reset: reset_time
Middleware-->>Client: Short-circuit with headers
else Account is not locked
AccountLock-->>Middleware: false
Middleware->>Storage: Look up user by username
alt User not found
Storage-->>Middleware: unknown/error
Middleware->>AccountLock: RecordLoginAttempt(username, false)
Middleware-->>Client: 401 Unauthorized
else User found
Storage-->>Middleware: user
Middleware->>Middleware: Verify password
alt Password invalid
Middleware->>AccountLock: RecordLoginAttempt(username, false)
Middleware-->>Client: 401 Unauthorized
else Password valid
Middleware->>AccountLock: RecordLoginAttempt(username, true)
Middleware->>Controller: Continue to controller
Controller-->>Client: Login success
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #555 +/- ##
==========================================
- Coverage 19.49% 19.44% -0.06%
==========================================
Files 39 39
Lines 2267 2273 +6
==========================================
Hits 442 442
- Misses 1795 1803 +8
+ Partials 30 28 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Discovered by @offw0rld
This pull request fixes the vulnerability by using the rate limit function in the context controller too.
Summary by CodeRabbit
Release Notes
Security Improvements
Authentication Updates
✏️ Tip: You can customize this high-level summary in your review settings.