carlos / platform Public

console: refuse an oversize step-up form before any side effect

Astra P2: with billing on, an account deletion without a fresh proof
ran the retirement gate, which can expire an open checkout, before the
stash refused a form over 1 MiB. The encoded size is now checked first:
at the start of the step-up gate (before Keymail, email or stash), and
in retireForDeletion before the billing hold and retirement mark, the
one caller that mutates before reaching the gate. Same stash-failed
message; StashPendingAction's check stays as the backstop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1a54f5d102b2e1262615f93234ef27e4516c9333 parent b905638
3 files changed, +80 −9
  • internal/console/billingretire.go +6 −0
  • internal/console/billingretire_test.go +31 −0
  • internal/console/stepup.go +43 −9

Intent

Human

<task-notification> <task-id>bvgpqxyd4</task-id> <tool-use-id>toolu_01ChSZmmpC7V7T1qns1hLg9t</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/bvgpqxyd4.output</output-file> <status>completed</status> <summary>Background command "Run Astra review of the follow-ups" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a0ae9f14336e67c40</task-id> <tool-use-id>toolu_01VzAFg5iWSzwtyEBgEiWxuS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/a0ae9f14336e67c40.output</output-file> <status>completed</status> <summary>Agent "Release v0.43.8 and roll dev" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>The build and Luna's review are both running in the background. I'll pick up when they report.</result> <usage><subagent_tokens>226302</subagent_tokens><tool_uses>63</tool_uses><duration_ms>598269</duration_ms></usage> </task-notification>

diff --git a/internal/console/billingretire.go b/internal/console/billingretire.go
index ce5d86159..d5fd4b0dd 100644
--- a/internal/console/billingretire.go
+++ b/internal/console/billingretire.go
@@ -224,6 +224,12 @@ func (s *Server) retireForDeletion(w http.ResponseWriter, r *http.Request, addr,
}
ctx := s.billingClock(r.Context())
fresh := s.store.FreshStepUp(raw, addr, time.Now(), StepUpWindow)
+ // Without a fresh proof this request is parked for a step-up after the
+ // retirement gate below, which can expire an open checkout. A form too
+ // large to park is refused first, so that refusal changes nothing.
+ if !fresh && !s.pendingFormFits(w, r) {
+ return nil, false
+ }
now := time.Now()
h, release, err := s.holdBilling(acct)
if err != nil {
diff --git a/internal/console/billingretire_test.go b/internal/console/billingretire_test.go
index 78f1da290..c52b3bc05 100644
--- a/internal/console/billingretire_test.go
+++ b/internal/console/billingretire_test.go
@@ -562,3 +562,34 @@ func TestReplayWithExpiredProofNeedsRetirement(t *testing.T) {
t.Fatalf("%d pending actions parked by a refused replay", stashed)
}
}
+
+// An account deletion whose form is too large to park for the step-up is
+// refused before the retirement gate runs: the open checkout is not expired,
+// nothing is parked and the account is not marked retiring.
+func TestDeleteOversizeFormRefusedBeforeRetirement(t *testing.T) {
+ o := newCheckoutFixture(t, true)
+ o.deletable(t)
+ wantSession(t, o.checkout(t, "plan", "personal", "currency", "usd"))
+ old := o.intent(t)
+ before := o.session(old.Session).State
+ o.reset()
+ status, loc, body := postForm(t, o.owner, o.ts.URL+"/a/"+o.acct.Sqid+"/delete", url.Values{"csrf": {o.csrf},
+ "confirm": {o.acct.Name}, "pad": {strings.Repeat("a", pendingFormMax)}})
+ if status != http.StatusInternalServerError || strings.HasPrefix(loc, o.fk.srv.URL) ||
+ !strings.Contains(html.UnescapeString(body), stepUpHoldFailed) {
+ t.Fatalf("oversize delete = %d %q, want the stash-failed refusal\n%s", status, loc, body)
+ }
+ if ci := o.intent(t); ci.ID != old.ID || ci.State != intentOpen || ci.ExpirePrepared != nil {
+ t.Fatalf("intent = %+v, want the open checkout untouched", ci)
+ }
+ if got := o.session(old.Session).State; got != before {
+ t.Fatalf("checkout session %v, was %v", got, before)
+ }
+ wantCounts(t, o.counts(), map[string]int{})
+ var stashed int
+ o.st.db.QueryRow(`SELECT COUNT(*) FROM pending_actions`).Scan(&stashed)
+ if stashed != 0 {
+ t.Fatalf("%d pending actions parked", stashed)
+ }
+ o.wantKept(t)
+}
diff --git a/internal/console/stepup.go b/internal/console/stepup.go
index 9256c5771..336dcb25d 100644
--- a/internal/console/stepup.go
+++ b/internal/console/stepup.go
@@ -297,6 +297,11 @@ func (s *Server) stepUpGate(w http.ResponseWriter, r *http.Request, addr, raw st
if s.store.FreshStepUp(raw, addr, now, StepUpWindow) {
return true, false
}
+ // A form too large to park is refused before anything else on the way to
+ // a stash: no Keymail call, no email, nothing parked.
+ if !s.pendingFormFits(w, r) {
+ return false, false
+ }
// A session that signed in by email re-confirms by email (spec 6). Only
// that method does: a Keymail session, or one whose method cannot be
// read, takes the passkey path below and never an email instead.
@@ -341,11 +346,46 @@ func (s *Server) stepUpGate(w http.ResponseWriter, r *http.Request, addr, raw st
// and returns the token that redeems it. On false it has already written the
// response.
func (s *Server) stashRequest(w http.ResponseWriter, r *http.Request, addr, raw string, now time.Time) (string, bool) {
+ form, err := pendingForm(r)
+ if err != nil {
+ s.renderMessage(w, r, http.StatusBadRequest, "Refused", "That request could not be read.")
+ return "", false
+ }
+ pending, err := s.store.StashPendingAction(raw, addr, r.Method, r.URL.Path, form, now)
+ if err != nil {
+ log.Printf("console: stash pending action: %v", err)
+ s.renderMessage(w, r, http.StatusInternalServerError, "Error", stepUpHoldFailed)
+ return "", false
+ }
+ return pending, true
+}
+
+// pendingFormFits is false, with the stash-failed answer written, when r's
+// form is too large to park (pendingFormMax, measured as pendingForm encodes
+// it). The step-up gate asks it before starting a step-up, and a caller with
+// side effects of its own before the gate (retireForDeletion) asks it before
+// those, so an oversize form is refused with nothing applied.
+// StashPendingAction's own check stays as the backstop.
+func (s *Server) pendingFormFits(w http.ResponseWriter, r *http.Request) bool {
+ form, err := pendingForm(r)
+ if err != nil {
+ // stashRequest answers an unreadable form.
+ return true
+ }
+ if len(form) > pendingFormMax {
+ log.Printf("console: pending action form for %s is %d bytes, over %d; not parked", r.URL.Path, len(form), pendingFormMax)
+ s.renderMessage(w, r, http.StatusInternalServerError, "Error", stepUpHoldFailed)
+ return false
+ }
+ return true
+}
+
+// pendingForm is r's form as a stash stores it: URL-encoded, without csrf.
+func pendingForm(r *http.Request) (string, error) {
// The handler has already read fields off this request, so PostForm is
// parsed and cached; Encode gives back exactly what it will be re-fed.
if err := r.ParseForm(); err != nil {
- s.renderMessage(w, r, http.StatusBadRequest, "Refused", "That request could not be read.")
- return "", false
+ return "", err
}
// The csrf field is deliberately NOT stored. It is derived from the session
// (csrf.go) and, from a page rendered before csrf-v1, may be the raw session
@@ -360,13 +400,7 @@ func (s *Server) stashRequest(w http.ResponseWriter, r *http.Request, addr, raw
form[k] = v
}
}
- pending, err := s.store.StashPendingAction(raw, addr, r.Method, r.URL.Path, form.Encode(), now)
- if err != nil {
- log.Printf("console: stash pending action: %v", err)
- s.renderMessage(w, r, http.StatusInternalServerError, "Error", stepUpHoldFailed)
- return "", false
- }
- return pending, true
+ return form.Encode(), nil
}
// handleStepUpCallback is where a re-authentication lands. It trusts nothing