carlos / platform Public

fix: let a claimed browser open another demo's claim

Use the newly posted claim token for intent and rotate its browser cookie. Keep reserved cookies status-only for proof and selection; cover two demos in one browser.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 3d9043a8554d9d1f6a6628c163bcad274063450a parent 1a413e6
3 files changed, +43 −3
  • internal/console/demo_claim_page.go +3 −2
  • internal/console/demo_claim_page_test.go +39 −0
  • internal/console/demo_claim_review_test.go +1 −1

Intent

Human

<task-notification> <task-id>a64056782803ab85e</task-id> <tool-use-id>toolu_01U3bLQrE9K3je1YfuaLYmBm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/a64056782803ab85e.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 7 fix round 1" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>The fix round resolves all six findings, but it adds one functional regression of its own (a P2). I found no new security breakage. HEAD is now 77df0163; the only commit after bcec1b4d is a copy brief, so the line numbers below hold for both. ## Findings | # | Verdict | Where | |---|---|---| | P2-1 | ADDRESSED | `internal/console/static/demo_claim.js:12-17`: the `referrerPolicy` override is gone. The strict `demoClaimOrigin` check is unchanged, now called through `demoClaimBrowserAdmission` (`demo_claim_page.go` around line 184). The fragment is cleared by `replaceState` at js:4, before the request. | | P3-1 | ADDRESSED | `demo_claim_store.go:211-213` changes live browser rows to the `demo-claim-status` purpose when the reservation is made. `demo_claim_browser_store.go:42-50` only accepts a status row while that flow's operation exists and the demo's expiry plus 24 hours has not passed. The cookie is set at `demo_claim_page.go:432` and `:100`. | | P3-2 | ADDRESSED | `demo_claim_page.go:33` (`demoClaimBrowserError`) keeps the status codes; the template shows the message at `templates/demo_claim.html:12`. The membership 404 and the JSON `demoError` on the fetch-driven intent call are left as they were, as intended. | | P3-3 | ADDRESSED | `demo_claim_page.go:305-320` and `demo_claim_browser_store.go:65-105`. | | P3-4 | ADDRESSED | `demo_claim_page.go:134-142` (render filter, plus the `no_accounts` state, which shows no form), `:471` (`demoClaimCanCreate`), and the same predicate in select. The `len(accounts)==0` check still uses the unfiltered list, so a member with only non-creating roles who posts `create=1` gets a 404. | | P3-5 | ADDRESSED | `server.go:3845-3848` uses the neutral sign-in error at 500. The claim wrapper is `continueDemoClaimKeymail` at `demo_claim_page.go:498`, which keeps the claim error at 503. | ## New finding **P2: the long-lived status cookie blocks claiming any other demo in the same browser.** This is the same family as P3-1 (browser credential lifecycle), and it is new in this fix. - `demoClaimBrowserGate` (`demo_claim_page.go:172-181`) refuses every browser POST with 401 once the cookie's flow has an operation. That includes `/demo/claim/intent`. - Before this fix, intent ignored the old cookie and issued a fresh one ("Rotate instead of rebinding", around line 222). Now the refusal holds until demo A's expiry plus 24 hours. - What the user sees: they claim demo A, then open demo B's claim link. The page shows A's "now a permanent app" result, and the background exchange fails with the generic error. The only way out is clearing cookies or using a private window. - `TestDemoClaimBrowserResultLifetime` (`demo_claim_review_test.go:92-97`) asserts that intent returns 401, but only with the same demo's token. The case of a different demo is not tested. - There is no security reason for the intent refusal. Intent takes its authority from the posted claim token and swaps in a fresh cookie, so it never uses the old flow. Prove and select should keep the refusal. - Fix: exempt intent from the reserved-cookie refusal, or move that check into prove and select only. Add a test that claims demo A and then exchanges a token for demo B in the same browser. ## Security checks (no new breakage) **What the status row or cookie can do.** Only three call sites read the browser cookie (`demo_claim_page.go:97`, `:173`, `:198`). - Prove, select and intent are refused by the gate. - Prove would also fail on its own: after a reservation the flow already has a person, and `proveDemoClaim` checks for that (`demo_claim_auth.go:258`). - Page render takes the operation branch, which shows that operation's result and never lists accounts. - Agent endpoints never read `demo_claim_browsers`. The test confirms 401 at `/api/demo/claims/select`. - Counting status rows as "came from a browser" in `isDemoClaimBrowser` grants nothing new. Both of its callers run only after a proof that requires `person=''`. **Lifetime and erasure.** - Server side, a status row is bounded by the demo's expiry plus 24 hours and by the operation existing. - Every non-status cookie still gets at most 15 minutes, because flows are capped at 15 minutes (`demo_claim_store.go:126`) and render uses now + 15 minutes. That still holds even though the 900-second cookie cap was removed. - Expired rows are only deleted when the next browser attaches. They are inert in the meantime, and the implementer already listed this as a known limit. **Restarting email proof on the same intent.** - The new flow copies `demo_id`, lifetime, generation and `expires_at` from the old one, so the intent cannot move to another demo and its life cannot be extended. - The replacement is refused if the flow has a person or an operation, or if no live browser row points at it. A reserved operation therefore cannot be replaced. - The old challenge and the old flow are deleted in the same transaction, so old codes and links fail. - The send, submission and guess limits stay keyed by address and IP, so a correction does not reset them. - Locks are always taken flow first, then demo, which matches `proveDemoClaim`. A proof already running against the old flow fails when it re-reads the flow. **Removing `no-referrer`.** The token is cleared from the URL before the fetch, travels only in the POST body, and the page referrer policy is origin-only. Nothing leaks. **Error page escaping.** The page uses `html/template` (`demo_claim_page.go:8`), and messages are constants or `ref.Msg`, all escaped as text. The page shows no identity or account data. Verdict: READY AFTER FIXES</result> <usage><subagent_tokens>84363</subagent_tokens><tool_uses>13</tool_uses><duration_ms>150570</duration_ms></usage> </task-notification>

diff --git a/internal/console/demo_claim_page.go b/internal/console/demo_claim_page.go
index bb1ce03b8..1ad62d695 100644
--- a/internal/console/demo_claim_page.go
+++ b/internal/console/demo_claim_page.go
@@ -169,9 +169,10 @@ func (s *Server) demoClaimBrowserGate(w http.ResponseWriter, r *http.Request) bo
demoClaimBrowserError(w, 403, demoClaimWrongSite)
return false
}
- // A reserved cookie is a capability for this operation's status only.
+ // Intent uses the posted demo token and rotates the cookie. Other actions
+ // cannot mutate through a reserved status capability.
hash, err := s.store.demoClaimBrowserHash(r.Context(), cookie, time.Now())
- if err == nil {
+ if err == nil && r.URL.Path != "/demo/claim/intent" {
if _, err = s.store.demoClaimOpForFlow(r.Context(), hash); err == nil {
demoClaimBrowserError(w, 401, demoClaimIntentExpired)
return false
diff --git a/internal/console/demo_claim_page_test.go b/internal/console/demo_claim_page_test.go
index 40d021888..31d7bb194 100644
--- a/internal/console/demo_claim_page_test.go
+++ b/internal/console/demo_claim_page_test.go
@@ -198,3 +198,42 @@ func TestDemoClaimBrowserHeadless(t *testing.T) {
t.Fatal("keyboard discovery claimed")
}
}
+
+func TestDemoClaimBrowserNextDemo(t *testing.T) {
+ s, _, token := claimTestServer(t)
+ b := newClaimBrowser(t, s, token)
+ b.login("shop@example.com", MethodEmail, true)
+ if w := b.post("/demo/claim/select", url.Values{"create": {"1"}}); w.Code != 303 {
+ t.Fatalf("reserve: %d %s", w.Code, w.Body)
+ }
+ old := *b
+ for _, path := range []string{"prove", "select"} {
+ if w := old.post("/demo/claim/"+path, url.Values{"email": {"shop@example.com"}, "create": {"1"}}); w.Code != 401 {
+ t.Fatalf("reserved %s: %d", path, w.Code)
+ }
+ }
+ in := demoTestAdmission(t, s.cfg.Demo)
+ d, err := s.store.ReserveDemo(t.Context(), in)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if w := b.post("/demo/claim/intent", url.Values{"claimToken": {in.Identity.Token}}); w.Code != 303 {
+ t.Fatalf("next intent: %d %s", w.Code, w.Body)
+ }
+ if b.cookie == old.cookie {
+ t.Fatal("cookie not rotated")
+ }
+ hash, err := s.store.demoClaimBrowserHash(t.Context(), b.cookie, time.Now())
+ if err != nil {
+ t.Fatal(err)
+ }
+ f, err := s.store.demoClaimFlowByHash(t.Context(), hash, time.Now())
+ if err != nil || f.DemoID != d.ID {
+ t.Fatalf("next flow: %+v %v", f, err)
+ }
+ for _, path := range []string{"prove", "select"} {
+ if w := old.post("/demo/claim/"+path, nil); w.Code != 401 {
+ t.Fatalf("old status cookie %s: %d", path, w.Code)
+ }
+ }
+}
diff --git a/internal/console/demo_claim_review_test.go b/internal/console/demo_claim_review_test.go
index 48fa5a2ef..e0649f8d4 100644
--- a/internal/console/demo_claim_review_test.go
+++ b/internal/console/demo_claim_review_test.go
@@ -89,7 +89,7 @@ func TestDemoClaimBrowserResultLifetime(t *testing.T) {
if !found {
t.Error("reservation did not extend browser cookie")
}
- for _, path := range []string{"prove", "select", "intent"} {
+ for _, path := range []string{"prove", "select"} {
w = b.post("/demo/claim/"+path, url.Values{"email": {"shop@example.com"}, "create": {"1"}, "claimToken": {token}})
if w.Code != 401 {
t.Errorf("status cookie used for %s: %d", path, w.Code)