console: kept link never revives past demo end; empty token is broken
Opus review nits: exchange now requires the source expiry in every phase, so a lapsed link can't come back when a late abort finishes; an empty #k= shows the broken-link message; the accepted trade-offs (cookie replacement, cross-site reveal spend) and the census's literal match are written down.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/claim_authority_census_test.go+3 −0internal/console/demo_claim_kept.go+11 −3internal/console/demo_claim_kept_test.go+6 −6internal/console/static/demo_claim.js+1 −1
CI failed — run details
Intent
<paseo-system version="1" kind="agent-message" source-agent-id="d99e59f2-a713-4207-8f01-81ad52ed095b" message-id="ea4f4349-a185-40a8-a405-fb368ee2195c" source-agent-title="Release v0.34.15 dev console-only (demo CSP)"> console done: dev console on v0.34.23 (main d675f240, console arm64 da78f4bb). healthz 'ok v0.34.23' from 21:40:19Z. Claim check 21:39:54Z right before the restart: 0 open demo_claim_ops rows. One restart 21:40:15Z, NRestarts 0, 0 ERROR; probe 1174 x 200; ha_pools [hapair], CARLOS_DEMO_CLAIM=1, all 18 drop-ins byte-identical (console was v0.34.21 before). READINESS: before the roll the journal had 'refusing: box-layout:sophie-knitting,seed-region' at 21:19:47Z and 'ready' at 21:31:22Z (both the old console process). After the restart, the new process has logged no readiness line in 4.7 min; the console logs on change, so it is ready from its first check. The refusal had already cleared before the roll, so the restart did not mask it. Published Latest + tap #113; apt v0.34.23-1 HELD until you say. FLAGSHIP: NOT ROLLED. </paseo-system>
<task-notification> <task-id>afcfa7f81a516cb3f</task-id> <tool-use-id>toolu_01GHw4arszRpNrRJQx2t7THN</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/afcfa7f81a516cb3f.output</output-file> <status>completed</status> <summary>Agent "Opus security review kept link" 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>**Verdict: APPROVE WITH NITS.** I found nothing at P1 or P2. The merge resolution is correct. **Tests:** 13 of the 14 targeted tests passed (both censuses and all eleven server-side kept tests). `TestDemoClaimKeptHeadless` failed with `read ECONNRESET`: the browser it launches died at startup, which I attribute to my sandbox rather than the code. I did not retry it outside the sandbox. The report says it passed in the implementer's run. I created no scratch files. **What each point came to** 1. **Authority:** the kept credential reads one operation's status and result page and nothing else. - The browser-flow lookups require `operation_id=''`, so kept rows never resolve to a flow (`demo_claim_browser_store.go:47`, `demo_claim_status_page.go:28`). That blocks prove and select, and the gate's mutation check. - Select also refuses kept cookies before its sign-in redirect (`demo_claim_page.go:455`). - The result page sets only the app name, demo name and address, the public URL and the end time. The claimant's address and account name are never set. - There is no session write and nothing that mints a CLI credential. 2. **Token handling:** sound. - The token comes from `randomToken` and is decoded strictly, with exactly 32 bytes and a canonical re-encode check (`demo_claim_kept.go:79`). - Only its SHA-256 is stored, under a unique index, and the comparison is constant time. - `demoTx` takes the writer lock, and the `UPDATE … WHERE kept_hash=?` checks that it changed one row, so only one exchange can win. - A replayed or retried create loads the existing operation with `keptToken` empty, so `kept_url` is never sent again (`demo_claim_target.go:115`). - The fragment is cleared before the POST, and every token failure returns the same 401 `{"reason":"invalid"}`. 3. **Gates:** origin and admission checks, a nonce bound to the cookie and session, session CSRF, SameSite=Lax, the shared submit limiter (invalid tokens count against it), `claimGated`, the serving switch and the host-claim refusal are all present. 4. **Lifetimes:** these hold. The extra 24 h for an aborted operation's cookie is still capped by the JOIN, so pruning the operation kills the cookie. The reveal marker only replays an animation. 5. **Census:** done. The hash appears only in the allowlisted migration, reservation and exchange code; whole-row reads of the operations table are banned; `demoClaimOpColumns` excludes the hash. The claims-mode reasons now cover the three new columns. 6. **API alias test:** the relaxation is narrow. It allows the console hostname only on the verify path, only on a 202, only with the exact `/demo/claim/kept#k=` prefix and a 43-character token. The rest of the response is still checked for the console hostname. 7. **Merge:** `e5b5b5de` has main's page-wide `submitted` guard, the `pageshow` reset and the aborted `failureHeading`, alongside the kept path. The JS fragment handling, the manual-redirect fetch and the `data-reveal` attribute are all intact. **Nits (P3)** - **N1. An unused link can come back to life** (`demo_claim_kept.go:88`). The check `source_expires_at>? OR phase='aborted'` means a link whose operation was still `aborting` at source expiry starts working again once the operation reaches `aborted`. It only reveals the aborted state, but validity should not come back once lost. Fix: on expiry, clear `kept_hash` for operations that are not aborted (for example in the prune pass), or record whether the link was live at expiry. - **N2. Opening a link replaces the browser's existing claim cookie** (`demo_claim_kept.go:60`). Scenario: someone sends a person a kept link for the sender's own operation. If that person is partway through proving their own claim in the same browser, they lose that progress. It is a nuisance, not an escalation. Fix: refuse the exchange while a live proof cookie is present, or accept the trade-off and document it. - **N3. The reveal marker can be spent before the person sees it** (`demo_claim_page.go:141`). Any top-level GET to `/demo/claim` uses it up, including a cross-site navigation, because Lax cookies are sent on those. This affects the animation only. Fix: optionally require `Sec-Fetch-Site: same-origin` before using the marker. - **N4. An empty `#k=` shows the wrong state** (`demo_claim.js:5`). The token becomes an empty string, so the page shows the "missing" state instead of the broken-link message. Fix: map an empty token to `"invalid"`. - **N5. The hash census only searches for the literal text `kept_hash`.** That is acceptable for now; a comment saying so would help the next editor.</result> <usage><subagent_tokens>99243</subagent_tokens><tool_uses>17</tool_uses><duration_ms>181756</duration_ms></usage> </task-notification>
Attributed to this commit: 21.0 g CO₂e (2,602,313 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on claim-ux-kept-link, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/claim_authority_census_test.go b/internal/console/claim_authority_census_test.go| index 4799f63dd..6a295d3f0 100644 |
| --- a/internal/console/claim_authority_census_test.go |
| +++ b/internal/console/claim_authority_census_test.go |
| @@ -134,6 +134,9 @@ func TestClaimAuthoritySourceCensus(t *testing.T) { |
| // Keep the exchange secret out of general operation loaders, JSON responses, |
| // status polls and exports. Only migration, creation and exchange may name it. |
| +// It matches the literal column name kept_hash, so a query that reaches the |
| +// column another way (a renamed alias, a SELECT * the wildcard rule misses) |
| +// must be added here by hand. |
| func TestClaimKeptHashReadCensus(t *testing.T) { |
| readsAll := regexp.MustCompile(`(?i)\bselect\s+(?:[a-z_][a-z0-9_]*\.)?\*`) |
| allowed := map[string]bool{ |
diff --git a/internal/console/demo_claim_kept.go b/internal/console/demo_claim_kept.go| index d8f8a0b5f..48a830ec4 100644 |
| --- a/internal/console/demo_claim_kept.go |
| +++ b/internal/console/demo_claim_kept.go |
| @@ -9,6 +9,12 @@ import ( |
| ) |
| // This shell never renders the previous cookie's operation or proof flow. |
| +// |
| +// Accepted trade-offs (Opus review, 2026-11-07): exchanging a kept link |
| +// replaces this browser's claim cookie, so opening someone else's kept link |
| +// mid-proof loses that proof's progress (a nuisance, never more authority); |
| +// and any top-level GET of /demo/claim spends the one-shot reveal marker, |
| +// including a cross-site navigation, which costs only the animation. |
| func (s *Server) handleDemoClaimKeptPage(w http.ResponseWriter, r *http.Request) { |
| if s.cfg.HostClaim || s.store.claimGated() { |
| s.demoClaimBrowserError(w, 503, demoClaimUnavailable) |
| @@ -85,7 +91,7 @@ func (s *Store) exchangeDemoClaimKept(ctx context.Context, token string, now tim |
| } |
| var id, stored, phase string |
| var expiry int64 |
| - err = tx.QueryRowContext(ctx, `SELECT id,kept_hash,phase,source_expires_at FROM demo_claim_ops WHERE kept_hash=? AND (source_expires_at>? OR phase='aborted')`, hash, now.Unix()).Scan(&id, &stored, &phase, &expiry) |
| + err = tx.QueryRowContext(ctx, `SELECT id,kept_hash,phase,source_expires_at FROM demo_claim_ops WHERE kept_hash=? AND source_expires_at>?`, hash, now.Unix()).Scan(&id, &stored, &phase, &expiry) |
| if err != nil || subtle.ConstantTimeCompare([]byte(hash), []byte(stored)) != 1 { |
| return invalid() |
| } |
| @@ -93,8 +99,10 @@ func (s *Store) exchangeDemoClaimKept(ctx context.Context, token string, now tim |
| if err != nil { |
| return invalid() |
| } |
| - // An aborted result contains no live app authority and remains readable only |
| - // while its operation exists. The cookie itself has the normal 24h window. |
| + // A link works only until the demo's original end, whatever the phase, so |
| + // one that has lapsed can never come back when a late abort finishes. An |
| + // aborted result holds no live app authority; its cookie gets the normal |
| + // 24h window and still dies with the operation when it is pruned. |
| if phase == "aborted" { |
| expiry = now.Add(24 * time.Hour).Unix() |
| } |
diff --git a/internal/console/demo_claim_kept_test.go b/internal/console/demo_claim_kept_test.go| index df5a45756..b385271d7 100644 |
| --- a/internal/console/demo_claim_kept_test.go |
| +++ b/internal/console/demo_claim_kept_test.go |
| @@ -171,16 +171,16 @@ func TestDemoClaimKeptRefusals(t *testing.T) { |
| if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET source_expires_at=1,phase=? WHERE id=?`, phase, op.ID); err != nil { |
| t.Fatal(err) |
| } |
| - if phase != "aborted" { |
| - w := b.post("/demo/claim/kept", url.Values{"keptToken": {token}}) |
| - if w.Code != 401 || w.Body.String() != baseline { |
| - t.Fatal("expiry refusal") |
| - } |
| + // Past the source expiry no phase revives the link, not even an |
| + // abort that finishes late. |
| + w := b.post("/demo/claim/kept", url.Values{"keptToken": {token}}) |
| + if w.Code != 401 || w.Body.String() != baseline { |
| + t.Fatalf("expiry refusal (%s)", phase) |
| } |
| } |
| // Flow cleanup must not break the aborted result or accidentally bind it to |
| // another operation whose expired flow hash is also empty. |
| - if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET flow_hash='' WHERE id=?`, op.ID); err != nil { |
| + if _, err := s.store.db.Exec(`UPDATE demo_claim_ops SET flow_hash='',phase='aborted',source_expires_at=? WHERE id=?`, time.Now().Add(time.Hour).Unix(), op.ID); err != nil { |
| t.Fatal(err) |
| } |
| if w := b.post("/demo/claim/kept", url.Values{"keptToken": {token}}); w.Code != 303 { |
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js| index 4c64f6951..111f0cdc3 100644 |
| --- a/internal/console/static/demo_claim.js |
| +++ b/internal/console/static/demo_claim.js |
| @@ -2,7 +2,7 @@ |
| "use strict"; |
| const kept = location.pathname === "/demo/claim/kept"; |
| let token = location.hash.slice(1); |
| - if (kept) token = token.startsWith("k=") ? token.slice(2) : "invalid"; |
| + if (kept) token = token.startsWith("k=") && token.length > 2 ? token.slice(2) : "invalid"; |
| history.replaceState(null, "", "/demo/claim"); |
| const claim = document.getElementById("claim"); |
| const minimum = 650; |