feat(security): make auth-flow user scope independently enforceable (#506)#522
Merged
Conversation
…506) The multi-scope auth-flow rate limiter enforced session, IP, and user scopes at the same 100/60s limit and checked them session -> IP -> user. Because single-IP traffic accumulates the IP counter at least as fast as the user counter, the IP scope (checked first, equal limit) always tripped first and the user scope could never be the attributed blocker for real single-IP traffic -- it was effectively subsumed by the IP scope. Adopt options 1 + 2 from the issue: - Differentiate the limits: per-user limit is now 50/60s, half the per-IP limit (100/60s), so the user scope bites independently for single-account attacks (password-spray / account enumeration against one victim) from a single source IP. Lowering the user limit (rather than raising the IP limit) is strictly more restrictive and cannot lock out legitimate traffic: an interactive OAuth flow is a handful of requests, a client-credentials client with a 1h token needs ~1 request/hour, and ResetUserRateLimit clears the counter on a successful login. - Reorder to most-specific-first (session -> user -> IP) so the user scope is correctly attributed when it bites. Extracts the three limits into named constants and adds a regression test proving a single account from a single IP is blocked by the user scope at 50, not subsumed by the IP scope at 100. Unit and integration tests updated to the new per-user limit. Closes #506 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk9GxWS9EpazjbwBKfMpUX
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.
Summary
Closes #506.
The multi-scope auth-flow rate limiter (
api/auth_flow_rate_limiter.go) enforced session, IP, and user scopes at the same 100/60s limit and checked them session → IP → user. Because single-IP traffic accumulates the IP counter at least as fast as the user counter, the IP scope (checked first, at an equal limit) always tripped first — so theuserscope could never be the attributed blocker for real single-IP traffic. It was effectively subsumed by the IP scope.Change (issue options 1 + 2)
ResetUserRateLimitclears the counter on successful login.session → user → IP) so the user scope is correctly attributed when it bites.authFlowSessionLimit,authFlowUserLimit,authFlowDefaultIPLimit).Tests
TestAuthFlowRateLimiting_MultiScopeintegration sub-test to the new per-user limit.make lint,make build-server,make test-unit(2381 passed) all green.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kk9GxWS9EpazjbwBKfMpUX