feat(auth): #68: add in-memory rate limiting for register, login, and reset - #78
Merged
Conversation
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.
Implements #68.
Summary
Adds an in-memory rate limiter (
internal/platform/ratelimit) that locks a username out for 5 minutes after 5 consecutive failed attempts. Applied independently to register, login, and reset (each has its own quota), keyed by username.Changes
internal/platform/ratelimit/ratelimit.go(new): mutex-guardedLimiterwithCheck(returns remaining lockout),RecordFailure(locks at threshold),Reset. Lockout expiry starts a fresh window; entries never locked are left to accumulate.internal/features/auth/service.go: three independent limiters wired intoRegister,Login,ResetPassword. Check runs before any Argon2 work (blocked users never burn CPU); failures are counted only for genuine credential/identity errors; success resets the counter. Lockout error wrapsErrTooManyAttemptswith the live countdown.internal/shared/errors/errors.go: newErrTooManyAttemptssentinel; movedErrInvalidSecrethere from crypto as an internal marker.internal/shared/crypto/encryption.go:DecryptDatawraps AES-GCM auth failures withErrInvalidSecret.Fixes along the way
cipher: message authentication failedfrom the keyring credential decrypt). Now mapped toErrInvalidPassword(invalid username or password), and it counts toward the login lockout.RecordFailurereset the count on every failure (zero-valuelockedUntiltreated as expired), andCheckdeleted entries that had never tripped a lockout. Both fixed and verified.No test scripts added (no Go tests in the repo).