fix(auth): rate-limit OTP email sending#260
Open
ttonyxx wants to merge 1 commit into
Open
Conversation
## Why this change is needed `/auth/otp/send` generated and emailed a fresh OTP on every request with no throttling. An attacker could: - bomb any victim's inbox by repeatedly POSTing their email (the address is fully attacker-controlled and the endpoint is unauthenticated), and - cheaply probe the system / drive up email-provider cost. The verify endpoint already caps guesses at 5 attempts per code, but nothing limited how often a new code could be requested. ## What this does - Adds a `CreatedAt` timestamp to `OtpCode`. - `sendOtp` now refuses to issue a new code if one was already sent to that email within a 30-second cooldown, returning `429 otp-rate-limited`. This is backward compatible: existing codes without `createdAt` decode to the zero time and are simply treated as outside the cooldown. The per-code 5-attempt verification cap is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
c5364ea to
62df3e5
Compare
5a50270 to
0bc149f
Compare
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.
Severity: 🟡 Medium — email bombing / abuse via unauthenticated endpoint
The problem
/auth/otp/sendis unauthenticated and emits a fresh OTP email on every request, with no throttling. Since the target email is fully attacker-controlled, anyone can:The verify endpoint caps guesses at 5/code, but nothing limited requesting codes.
The fix
CreatedAttoOtpCode.sendOtprefuses to issue a new code if one was sent to that email within a 30-second cooldown, returning429 otp-rate-limited.Backward compatible: pre-existing codes without
createdAtdecode to the zero time and fall outside the cooldown. The per-code 5-attempt verification cap is unchanged.🤖 Generated with Claude Code