fix(auth): one invite makes one account, and a burst of sign-ups can't outrun the limit (#8106)
release / go (push) Successful in 2m8s
release / web (push) Successful in 1m13s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m7s
release / android (push) Successful in 4m15s
release / Build signed APK (push) Successful in 4m46s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 2m8s
release / web (push) Successful in 1m13s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m7s
release / android (push) Successful in 4m15s
release / Build signed APK (push) Successful in 4m46s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
Registration inserted the user and only then claimed the invite. When the claim lost a race it kept the account anyway, so parallel sign-ups on one invite link each made an account. The insert and the claim now run in one transaction: RedeemInvite's row lock makes the second sign-up wait for the first, find the invite used, and roll its account back with invite_invalid. The register and forgot-password limits checked and counted in two steps, so a parallel burst all read the count before any attempt was added. They now call AttemptLimiter.Allow, which does both under the lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,14 +52,14 @@ func (h *handlers) handleForgotPassword(w http.ResponseWriter, r *http.Request)
|
||||
// inbox). Applied whether or not the email matches, so a 429 says
|
||||
// nothing about which addresses are registered.
|
||||
addr := auth.ClientIP(r, h.netSettings.Hops())
|
||||
blockedAddr, waitAddr := h.forgotAddressLimit.Blocked(addr)
|
||||
blockedEmail, waitEmail := h.forgotEmailLimit.Blocked(email)
|
||||
if blockedAddr || blockedEmail {
|
||||
writeRateLimited(w, max(waitAddr, waitEmail))
|
||||
if ok, wait := h.forgotAddressLimit.Allow(addr); !ok {
|
||||
writeRateLimited(w, wait)
|
||||
return
|
||||
}
|
||||
if ok, wait := h.forgotEmailLimit.Allow(email); !ok {
|
||||
writeRateLimited(w, wait)
|
||||
return
|
||||
}
|
||||
h.forgotAddressLimit.Record(addr)
|
||||
h.forgotEmailLimit.Record(email)
|
||||
|
||||
q := dbq.New(h.pool)
|
||||
var matched bool
|
||||
|
||||
Reference in New Issue
Block a user