console: one decked rate-limit sentence for the DPA writes
Branch review finding P2-7 and deferred item D1. - The accept POST and both /fleet/legal POSTs refuse over the write limit with dpaRateLimitText, deck row DPA-C98 (text pending Paul's approval), now in dpaCopyBuilt; a test checks all three answer 429 with it and write nothing. - dpaBidiControl's range bounds are \u escapes, not raw bidi runes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+57
−3
docs/superpowers/plans/2026-11-25-dpa-acceptance-copy.md+1 −0internal/console/approved_dpa_copy_test.go+3 −0internal/console/dpapane.go+5 −2internal/console/dpapane_test.go+47 −0internal/console/oplegal.go+1 −1
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/plans/2026-11-25-dpa-acceptance-copy.md b/docs/superpowers/plans/2026-11-25-dpa-acceptance-copy.md| index b3cc08bca..0c8eaf3bd 100644 |
| --- a/docs/superpowers/plans/2026-11-25-dpa-acceptance-copy.md |
| +++ b/docs/superpowers/plans/2026-11-25-dpa-acceptance-copy.md |
| @@ -113,3 +113,4 @@ found literally by the gate once their id is in `dpaCopyBuilt`. |
| | DPA-C95 | docs/site/data-processing.md (page heading) [docs.dpa.title] | (new) | Data processing agreement | gate | approved | |
| | DPA-C96 | docs/site/nav.json (menu label) [docs.dpa.nav_label] | (new) | Data processing agreement | gate | approved | |
| | DPA-C97 | docs/site/nav.json (menu description) [docs.dpa.nav_blurb] | (new) | Accept the agreement that covers personal data in your apps, and keep a record of it. | gate | approved | |
| +| DPA-C98 | internal/console/dpapane.go (rate limit) [dpa.ratelimit] | (new) | Too many requests. Wait a minute and try again. | gate | approved | |
diff --git a/internal/console/approved_dpa_copy_test.go b/internal/console/approved_dpa_copy_test.go| index f380823ad..5cfdda0a4 100644 |
| --- a/internal/console/approved_dpa_copy_test.go |
| +++ b/internal/console/approved_dpa_copy_test.go |
| @@ -34,6 +34,9 @@ var dpaCopyBuilt = map[string]bool{ |
| "DPA-C84": true, "DPA-C85": true, "DPA-C86": true, "DPA-C87": true, "DPA-C88": true, |
| "DPA-C89": true, "DPA-C90": true, "DPA-C91": true, "DPA-C92": true, "DPA-C93": true, |
| "DPA-C94": true, "DPA-C95": true, "DPA-C96": true, "DPA-C97": true, |
| + // The shared rate-limit refusal (dpa.ratelimit): the accept POST and |
| + // both /fleet/legal POSTs. |
| + "DPA-C98": true, |
| // Task 5: the account settings pane and its email (dpa.pane.*, dpa.form.*, |
| // dpa.flash.*, dpa.email.*). |
| "DPA-C01": true, "DPA-C02": true, "DPA-C03": true, "DPA-C04": true, "DPA-C05": true, |
diff --git a/internal/console/dpapane.go b/internal/console/dpapane.go| index 8f58c9eef..09cd74c6e 100644 |
| --- a/internal/console/dpapane.go |
| +++ b/internal/console/dpapane.go |
| @@ -36,6 +36,9 @@ const ( |
| dpaChangedText = "We published a new version while you were reading. Review it and accept again." |
| dpaAlreadyText = "An agreement is already in force for this account." |
| dpaAcceptedOK = "You accepted the data processing agreement." |
| + // dpaRateLimitText (dpa.ratelimit) refuses a write over allowWrite's |
| + // limit: the accept POST here and both /fleet/legal POSTs (oplegal.go). |
| + dpaRateLimitText = "Too many requests. Wait a minute and try again." |
| ) |
| // dpaDateLayout and dpaTimeLayout are how the pane and the email write a |
| @@ -264,7 +267,7 @@ func dpaField(v string, max int, lines bool) (string, string) { |
| // dpaBidiControl is a character that reorders the text around it: an |
| // embedding, override or isolate. |
| func dpaBidiControl(r rune) bool { |
| - return (r >= '' && r <= '') || (r >= '' && r <= '') |
| + return (r >= '\u202a' && r <= '\u202e') || (r >= '\u2066' && r <= '\u2069') |
| } |
| // dpaReadForm reads the acceptance form, and the per-field errors. |
| @@ -317,7 +320,7 @@ func (s *Server) handleDPAAccept(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| if !s.allowWrite(Principal{Address: addr}, time.Now()) { |
| - s.renderMessage(w, r, http.StatusTooManyRequests, "Refused", "too many requests. Wait a minute and try again") |
| + s.renderMessage(w, r, http.StatusTooManyRequests, "Refused", dpaRateLimitText) |
| return |
| } |
| if !s.requireFreshAuth(w, r, addr, raw) { |
diff --git a/internal/console/dpapane_test.go b/internal/console/dpapane_test.go| index f478a50e7..f13358590 100644 |
| --- a/internal/console/dpapane_test.go |
| +++ b/internal/console/dpapane_test.go |
| @@ -658,3 +658,50 @@ func TestDPAPaneShowsProcessorAndDocument(t *testing.T) { |
| t.Error("the agreement body is not rendered as stored") |
| } |
| } |
| + |
| +// Over the write limit, the accept POST and the /fleet/legal POSTs refuse |
| +// with the one deck sentence (DPA-C98), and nothing is written. |
| +func TestDPAWritesThrottled(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + dpaWorld(t, fx) |
| + c := signInOperator(t, fx) |
| + csrf := sessionToken(t, fx, c) |
| + dpaFreshAs(t, fx, c, "paul@keymail.dev") |
| + h := dpaHidden(t, dpaSettings(t, fx, c)) |
| + fx.srv.cli.write = newRateLimiter(1, time.Hour) |
| + if !fx.srv.allowWrite(Principal{Address: "paul@keymail.dev"}, time.Now()) { |
| + t.Fatal("the fresh limiter refused the first write") |
| + } |
| + want := oplDeck(t, "DPA-C98") |
| + if want != dpaRateLimitText { |
| + t.Fatalf("dpaRateLimitText = %q, the deck says %q", dpaRateLimitText, want) |
| + } |
| + for _, tc := range []struct { |
| + path string |
| + form url.Values |
| + }{ |
| + {fx.u("/dpa/accept"), dpaPost(csrf, h)}, |
| + {fx.ts.URL + "/fleet/legal/publish", url.Values{"csrf": {csrf}, "kind": {"dpa"}, "version": {"2"}}}, |
| + {fx.ts.URL + "/fleet/legal/letterhead", url.Values{"csrf": {csrf}, "entity": {"Shop Limited"}}}, |
| + } { |
| + status, _, body := postForm(t, c, tc.path, tc.form) |
| + if status != http.StatusTooManyRequests || !strings.Contains(oplText(body), want) { |
| + t.Errorf("POST %s = %d, want 429 with %q:\n%s", tc.path, status, want, body) |
| + } |
| + } |
| + if n := dpaRows(t, fx); n != 0 { |
| + t.Errorf("%d acceptance rows after a throttled accept", n) |
| + } |
| + if docs, lh := oplDocs(t, fx, "dpa"), dpaCurrentLetterhead(t, fx); len(docs) != 1 || lh.Entity != "Example Hosting Limited" { |
| + t.Errorf("a throttled publish or letterhead save wrote: %d dpa rows, letterhead %q", len(docs), lh.Entity) |
| + } |
| +} |
| + |
| +func dpaCurrentLetterhead(t *testing.T, fx *consoleFixture) *Letterhead { |
| + t.Helper() |
| + lh, err := fx.st.CurrentLetterhead(t.Context()) |
| + if err != nil || lh == nil { |
| + t.Fatalf("letterhead %v, %v", lh, err) |
| + } |
| + return lh |
| +} |
diff --git a/internal/console/oplegal.go b/internal/console/oplegal.go| index 284c76bdc..0a23c6b2a 100644 |
| --- a/internal/console/oplegal.go |
| +++ b/internal/console/oplegal.go |
| @@ -303,7 +303,7 @@ func (s *Server) legalFormGate(w http.ResponseWriter, r *http.Request) (addr, ra |
| return "", "", false |
| } |
| if !s.allowWrite(Principal{Address: addr}, time.Now()) { |
| - s.renderMessage(w, r, http.StatusTooManyRequests, "Refused", "too many requests. Wait a minute and try again") |
| + s.renderMessage(w, r, http.StatusTooManyRequests, "Refused", dpaRateLimitText) |
| return "", "", false |
| } |
| return addr, raw, true |