fix(auth): do not send a code to an unregistered address - #186
Merged
Merged
Conversation
8 tasks
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
POST /api/auth/resend-codehad no recipient-existence check, unlike its siblingPOST /api/auth/forgot-password. Of the threesend_codecall sites in this module:registerusersrow first (legitimate)forgot_passwordif !exists { return Ok(..) }, commented 「防枚举:统一返回 ok(不发送)」resend_codeTwo consequences:
send_with_retryattempts up to 3 SMTP sends per call. Bounded (60 s per address, 10-minute code lifetime), but a real abuse of the mail relay and a real inconsistency in the verification flow.Reproduced on a live instance (SMTP mode):
resend-codewith a non-existent address → call 1 200, call 2 429. The 429 is the proof: it only appears whenresend_too_soonis true, which requires a verification row created by the handler's ownsend_code— i.e. the first call did proceed to send. Control:forgot-passwordwith the same non-existent address → 200, 200 (its guard short-circuits before the rate limiter).Related Issue
None — this defect was found by a self-directed sweep of the email-verification / mail-sending surface, and no issue exists for it. No issue is fabricated and none is closed.
Changes
src/routes/mod.rs,resend_code: added the same existence gate its sibling has, beforesend_code— look updao::find_user_by_emailand, when absent, return the existing anti-enumeration response{status: "ok", email}with no send. No new 404/400 branch: that would create the very oracle the module avoids. The response is now identical whether or not the address exists, preserving the documented behavior.verified == 0: the resend button is the "didn't get the code" path for a user who has ausersrow but is not yet verified, so an existence gate keeps the legitimate flow working while closing the send-to-anyone hole (this matchesforgot_password, which also serves unverified accounts).config/config.example.tomluntouched (not applicable).Tests
cargo test— 169 passed / 0 failed (baseline 168 + 1 new).cargo fmt --check— clean.cargo clippy --all-targets -- -D warnings— clean.resend_code_unknown_email_not_sent, with a positive control: an unregistered address returns 200 withoutdev_code(and is not rate-limited, since no row is created); then a real registered address, rate-limit record cleared, still returns 200 with adev_code— so the test cannot pass by simply always returningok.未注册邮箱不应发码), with the leakeddev_codevisible in the failure output; both existing resend tests (resend_code_rate_limited,register_smtp_failure_502) stay green in both legs.Checklist
fix/)fix(auth): …)⛔ Not in scope: per-IP rate limiting for the mail endpoints — a separate, larger change that would need a store we do not have.