console: over the submit cap, write no challenge at all
The per-IP submission cap is the requester's own throttle and says nothing about anyone else, so a capped request writes no unsent challenge (the code box answers "used up" there). Unsent challenges remain only for refusals by the send limits, which the submit cap already bounds to 30 an hour per IP.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+26
−17
internal/console/emailsignin_test.go+13 −10internal/console/server.go+13 −7
diff --git a/internal/console/emailsignin_test.go b/internal/console/emailsignin_test.go| index c4d5ef393..bfb360fa4 100644 |
| --- a/internal/console/emailsignin_test.go |
| +++ b/internal/console/emailsignin_test.go |
| @@ -433,9 +433,10 @@ func TestContinuePageIdentical(t *testing.T) { |
| if n := len(m.sentCopy()); n != 2 { |
| t.Fatalf("mailer got %d messages, want 2 (the throttled and capped ones send nothing)", n) |
| } |
| - // Two sent, and one never-sent challenge for each refused fresh browser. |
| - if n := challengeRows(t, fx); n != 4 { |
| - t.Fatalf("%d challenges stored, want 4", n) |
| + // Two sent, one never-sent for the throttled fresh browser, and nothing |
| + // for the capped one. |
| + if n := challengeRows(t, fx); n != 3 { |
| + t.Fatalf("%d challenges stored, want 3", n) |
| } |
| if lookupCount(fx) != lookupsBefore { |
| t.Fatal("a capped submission still asked Keymail") |
| @@ -1297,7 +1298,8 @@ func TestContinueOverlappingFirstSubmissions(t *testing.T) { |
| // F1 (final review): an IP that has spent its submissions on the Keymail |
| // host's own addresses (no lookup, no email slot) gets no email for an |
| -// address it can no longer have looked up, here one Keymail serves. |
| +// address it can no longer have looked up, here one Keymail serves, and |
| +// its 31st submission writes no challenge row at all. |
| func TestContinueSubmitCapSendsNothing(t *testing.T) { |
| fx, m := newEmailFixture(t, true) |
| const addr = "kim@example.com" |
| @@ -1324,12 +1326,13 @@ func TestContinueSubmitCapSendsNothing(t *testing.T) { |
| if sent := m.sentCopy(); len(sent) != 0 { |
| t.Fatalf("a capped submission sent %q", sent) |
| } |
| - // Its challenge is the never-sent kind: no link was ever minted for the |
| - // mailbox, and the code box treats it as any other. |
| - if n := challengeRows(t, fx); n != 1 { |
| - t.Fatalf("%d challenges, want the one unsent", n) |
| + // The 31st submission from this IP, in a fresh flow, wrote no challenge |
| + // at all, so the code box finds nothing. |
| + if n := challengeRows(t, fx); n != 0 { |
| + t.Fatalf("%d challenges after a capped submission, want none", n) |
| } |
| - if status, _, body := postCode(t, fx, c, "000000"); status != http.StatusOK || !signedOut(t, fx, c) { |
| - t.Fatalf("a code against the unsent challenge = %d:\n%s", status, body) |
| + if status, _, body := postCode(t, fx, c, "000000"); status != http.StatusOK || |
| + !strings.Contains(body, esc(copyText("check.code_used_up"))) || !signedOut(t, fx, c) { |
| + t.Fatalf("a code after a capped submission = %d:\n%s", status, body) |
| } |
| } |
diff --git a/internal/console/server.go b/internal/console/server.go| index 3cdb57843..728c16991 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -2773,7 +2773,7 @@ func (s *Server) handleAcceptInvite(w http.ResponseWriter, r *http.Request) { |
| // lookup); Keymail's lookup is asked only under the cap; an email-bound |
| // address with no ready mailer is told so before any send limit (spec 4.2); |
| // and a request over the submission cap or the send limits is refused: no |
| -// email, and no challenge the mailbox could redeem. |
| +// email, and no challenge the mailbox could redeem (signinChallenge). |
| func (s *Server) handleContinue(w http.ResponseWriter, r *http.Request) { |
| if !s.sameOrigin(r) { |
| s.renderMessage(w, r, http.StatusForbidden, "Refused", "Cross-site request blocked.") |
| @@ -2831,17 +2831,23 @@ func (s *Server) handleContinue(w http.ResponseWriter, r *http.Request) { |
| // flow, under that flow's lock, so overlapping submissions from one browser |
| // take turns. Accepted (under the submission cap and every send limit), it |
| // records a new sign-in challenge for the flow, replacing the flow's earlier |
| -// ones, and returns its link and code to send. Refused, it sends nothing: |
| -// the flow's live challenge, if it has one, is left untouched so the email |
| -// already sent keeps working; otherwise a challenge nobody is ever told the |
| -// link or code of is recorded, so a code typed next answers exactly as it |
| -// would against a sent one. |
| +// ones, and returns its link and code to send. Refused, it sends nothing and |
| +// leaves the flow's live challenge, if any, untouched, so the email already |
| +// sent keeps working. Over the submission cap it writes nothing at all: that |
| +// throttle is the requester's own IP and says nothing about anyone else, so |
| +// the code box may answer "used up" there. Refused by the send limits (which |
| +// the submission cap bounds to 30 an hour per IP), a flow with no live |
| +// challenge gets one nobody is ever told the link or code of, so a code |
| +// typed next answers exactly as it would against a sent one. |
| func (s *Server) signinChallenge(flow, addr, next, ip string, underCap bool, now time.Time) (link, code string, sent bool, err error) { |
| mu := s.flowLock(flow) |
| mu.Lock() |
| defer mu.Unlock() |
| + if !underCap { |
| + return "", "", false, nil |
| + } |
| c := EmailChallenge{Purpose: ChallengeSignIn, Address: addr, Next: next, FlowHash: hashToken(flow)} |
| - if !underCap || !s.limits.signinSend(addr, ip) { |
| + if !s.limits.signinSend(addr, ip) { |
| log.Printf("console: sign-in email to %s from %s refused by its limits; not sent", addr, ip) |
| return "", "", false, s.store.HoldEmailChallenge(c, now) |
| } |