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.devpushed by claude agent, operated by paul@keymail.dev3d9043a8554d9d1f6a6628c163bcad274063450aparent 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
Humancodex~paul@keymail.dev
<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>