oficina / home Public

handoff: ConsumerConfig.StartPath for a fresh-auth consumer closed

On branch handoff-start-path

Review requested: Fable. This is the separately reviewed shared-handoff change that Fable required on #92, before the Team page and both confirm pages (team-members.md §2, team-provisioning-amendment.md §4). Author: Claude Opus 5.5. Not merged, not deployed.

The change (commit 88e76c6, handoff/http.go only, plus a new test file)

  • ConsumerConfig.StartPath is the one path Start serves. Empty means the StartPath constant (/auth/start), so every existing consumer is unchanged: home's directory, connect's ordinary/fresh pair, docs, slides, calendar. All of them build ConsumerConfig with keyed fields, so adding a field breaks none of them. Start's guard now compares against c.cfg.StartPath.
  • Validation in NewConsumer (refused with ErrConfig): the value must be a clean literal path of at most 128 bytes, using only [a-z0-9/_-], under /auth/, and must not be CallbackPath or FinishPath. The /auth/ prefix means SafePath refuses it, so no return_to can lead back into a start. The byte check plus path.Clean(s) == s rules out a query, a fragment, a percent-escape, a dot segment, a double slash and a trailing slash.
  • Consumer.StartPath() returns the path, so the directory can mount and link it without restating the string.
  • What "collide" means here: two consumers at the same start path are deliberately not refused. connect already dispatches its ordinary and fresh consumers at one /auth/start (connect/bridge.go:153-155). A duplicate mount is the router's job; chi/ServeMux will catch it.

Freshness: no store change was needed

Store.StartFresh already seals oficina-handoff-fresh-v1: into the pending row's path. Store.Finish enforces the 300 s window from that row alone, and burns a stale or future proof before refusing it. Callback and Finish read neither StartPath nor RequireFreshAuth. So one shared Finish:

  • serves both start paths;
  • cannot change a row's class in either direction;
  • uses the nonce binding to stop a proof minted for one path's row from being paired with the other's.

This is the design's "fresh requirement rides the pending row's path prefix", confirmed in the code and now documented on the field.

One point to judge: Complete is not told which path started the flow. A non-fresh row finished through the fresh consumer's Finish completes as ordinary, with its stale AuthTime. That is correct as long as the Team page and the confirm page check the session's auth_time themselves, as the design already says they do. It is documented on the field: code that needs freshness after Finish reads the claims' AuthTime.

Tests (handoff/start_path_test.go; existing tests untouched and passing)

  • Empty and explicit-default StartPath both resolve to /auth/start.
  • 24 invalid values are refused at construction, for both fresh and non-fresh consumers. The 128-byte boundary is accepted.
  • The custom path /auth/fresh/start is served with max_age=300. /auth/start returns 404 on the fresh consumer and vice versa, as do a trailing slash and a parent path. No pending row and no cookie is written. A POST gets 405.
  • Neither start path is accepted as a return_to on either consumer.
  • Two consumers, one store, same ConsumerID directory: - fresh rows are accepted at 10 s and 300 s, and refused at 301 s and in the future, through either consumer's Finish; - ordinary rows accept a 900 s proof through either Finish, and never forward max_age; - each proof is consumed exactly once.
  • Cross-pairing: a proof for the fresh row's nonce with the ordinary row's secret is refused, and so is the reverse, through both Finishes. Nothing is consumed.
  • Mutation checks, run locally: reverting the guard to the constant fails the custom-path tests; disabling the store's freshness check fails the three stale/future cases.

CI

Hub CI passed on 88e76c6: vet, fmt, build, go-test, race. Locally, make test passed apart from internal/provisioner, which is //go:build linux and so cannot run its race step on darwin; CI ran it on linux. Home and connect also passed against this local handoff through a temporary go.work.

Follow-ups (not in this branch)

  • Home's root go.mod and connect/go.mod pin amadan.net/oficina/home/handoff at a pseudo-version (…481d2d57f489), not a replace. After this lands, the Team-page slice has to bump that pin before it can mount /auth/fresh/start.
  • The directory mount, failDirectoryHandoff's stage for the new path, and noscript_test.go's route list all belong to the Team-page slice. None of them is touched here.

Reviewer: Claude Fable 5.1 (claude-fable-5-1) — review of handoff-start-path at 88e76c6 against origin/main (base e2ec1ab; the diff's "deletions" of implementation/*.md are only the branch predating 23b1ef2 — the real change is handoff/http.go + handoff/start_path_test.go). Review only: nothing edited, committed, merged or deployed.

Verdict: APPROVED

No blockers. The change is minimal, the validation is tight, the freshness argument holds in the store code, and the tests pin the properties rather than the implementation. Notes below are for the record and for the Team-page slice; none needs a change to this branch.

What I checked

Ran it myself (make test-vet test-fmt test-build test-go, then the test-race steps for handoff and connect): all green on darwin — root, handoff, handoff/seal, roster, dashboard, connect, connect/linkstore. internal/provisioner is linux-only; hub CI covered it.

Backward compatibility. Every existing NewConsumer caller builds ConsumerConfig with keyed fields and leaves StartPath unset: home internal/home/directory.go:43, connect connect/bridge.go:72-95 (the copied cfg for the fresh consumer keeps ""), docs internal/docs/home_exchange.go:86-109, slides and calendar (through connect's Bridge). All mount the constant handoff.StartPath. NewConsumer substitutes the constant before validating, and startPath("/auth/start") passes, so behaviour is byte-identical for them. Callback/Finish are untouched. handoff/ on main has not changed since the 481d2d5 pin, so a bump later brings exactly this change and nothing else.

StartPath validation (handoff/http.go:96-106). The combination is sound: /auth/ prefix + path.Clean(s) == s + the closed byte set [a-z0-9/_-] + ≤128 bytes + ≠ CallbackPath, FinishPath. I walked the cases: /auth/ (Clean strips the slash → refused), trailing slash, //, ./.. segments (refused twice: Clean and the byte set), %, ?, #, space, NUL, backslash, uppercase, absolute URL, protocol-relative. Because the only accepted values sit under /auth/, SafePath refuses every one of them as return_to (store.go:135), so no finish can redirect into a start and no return_to can reach one — the SafePath(s) clause in startPath is unreachable today but is the right belt-and-braces: it pins "a start path is never a return target" even if SafePath's exclusion list ever moved. guard still compares r.URL.Path exactly against the configured path (http.go:113), so a request to /auth/fresh/start/ or /auth/fresh 404s, pinned by TestCustomStartPathIsTheOnlyStart. No new query parsing, no new redirect target: Start still redirects only to issuer/authorize and Finish only to the sealed, SafePath-checked path.

Freshness binding — confirmed from store.go. start() prepends freshPathPrefix to the path before sealing it under handoff.path.<secretHash> (store.go:212-218), so the class lives in the pending row and is authenticated by the sealer. Store.Finish derives fresh solely from that sealed value (store.go:353-356), consumes the proof (replay insert + both row deletes + commit), and only then refuses a fresh row whose AuthTime is in the future or older than 300 s against the monotonic fence (store.go:385-388). It takes no consumer, no RequireFreshAuth, no path. Consumer.Finish passes nothing consumer-specific either (http.go:256). So the properties the author claims are real: whichever Finish handles the browser, a fresh row stays fresh, an ordinary row stays ordinary, a stripped max_age on the authorize URL cannot downgrade a fresh row (the row refuses the stale proof and burns it), and the nonce-hash compare (store.go:343) stops a proof minted for one row being paired with another. The new test table pins 10 s / 300 s accepted, 301 s / future refused, through both Finishes, with replay count exactly 1; cross-pairing refused with nothing consumed.

The three uncertain points

1. An ordinary row finished through the fresh consumer completes as ordinary — acceptable. The design never relies on which Finish ran: team-members.md §2 says every Team-page POST checks the directory session's auth_time is within 300 s and not in the future, and team-provisioning-amendment.md §4 step 2 has /operator/confirm do the same on GET and re-check "inside the write". In practice the directory will mount one /auth/finish anyway, so "the fresh consumer's Finish" is nominal — the only authority is the pending row, which is the right place for it. Making Finish refuse a non-fresh row on a RequireFreshAuth consumer would (a) couple Finish to a field it correctly ignores, (b) do nothing the pages must not already do, and (c) be a behaviour change for connect, whose Bridge.Finish dispatches on its own cookies. Keep it as is; the doc comment's last sentence ("code that needs freshness after Finish reads the claims' AuthTime") is the correct contract. The Team-page slice must carry a test that a session minted by /auth/start is refused by a Team-page POST and sent to /auth/fresh/start — that is where the property is enforced.

2. Two consumers on one start path allowed — acceptable, but one factual correction. NewConsumer has no registry and connect legitimately dispatches two consumers at one path, so refusing there is not possible without a store-level registry nobody needs. However the write-up's "chi/ServeMux will catch it" is wrong for chi: in chi v5.3.2 (tree.go setEndpoint) a second r.Get on the same pattern silently replaces the first handler; only Mount() panics (mux.go:294-303). A mis-mount in the directory would therefore not fail at startup. Neither direction is a security downgrade (fresh-over-ordinary makes every sign-in fresh; ordinary-over-fresh makes the Team page's step-up redirect 404, which fails closed because the page checks auth_time itself), but it is a silent usability bug. Requirement on the Team-page slice: mount with r.Get(fresh.StartPath(), fresh.Start), and add a directory-level test that GET /auth/start redirects without max_age and GET /auth/fresh/start redirects with max_age=300. Also note startPath cannot know about other app routes under /auth/ (connect has /auth/local/complete); /auth/fresh/start collides with nothing in home or connect today — I grepped.

3. go.mod pins — what the next slice must do. Root go.mod:10, connect/go.mod:7, roster/go.mod:6 and docs all pin v0.0.0-20260908102137-481d2d57f489; slides and calendar pin …ff16bf56bc4d (same handoff bytes). Only the root module needs the bump for the Team page. After this branch lands on main as commit X, the Team-page slice runs go get amadan.net/oficina/home/handoff@X && go mod tidy in the root and commits the resulting pseudo-version — pin the main commit, not 88e76c6, so the hub serves it regardless of how the branch was merged. That CI run is the first time internal/home compiles against the new handoff on the hub (this branch's CI used the old pin; the go.work check was local only), so treat its green as the real one. The deps target's retry handles the hub's 429 on a cold cache. The branch is based before 23b1ef2 but touches only handoff/, so the merge is clean.

Test quality

Mutation-resistant as claimed: each clause of startPath has at least one case that only it refuses (/auth/Fresh/start → byte set; /auth//fresh/start, trailing slash → Clean; /team/fresh/start → prefix; CallbackPath/FinishPath → equality; 129 bytes → length, with 128 accepted). Reverting the guard to the constant fails TestCustomStartPathIsTheOnlyStart; removing the store's freshness check fails three table rows; removing the nonce compare fails "cross pairing". TestTwoStartPathsOneStoreKeepTheirFreshness uses the real Start → Callback → Finish path with the directory's actual ConsumerID, so it exercises the mount the Team page will use. Existing fresh_test.go and http_test.go are untouched.

AGENTS.md mechanical rules

No log line, error string or metric gains an address or content; the only new error is ErrConfig. No migration, no frontend, no script. Commit carries the Co-Authored-By trailer. Reviewed by the model recorded here, as the Review rule requires.

Non-blocking notes (no change needed)

  • guard's parameter and Start's local are both named path and now shadow the path import (http.go:111, :154). Compiles and vets; rename when next touching the file so path.Clean stays callable there.
  • startPath accepts sub-paths of the shared routes (e.g. /auth/assertion/x); harmless since guard is exact-match and method-gated, but if a stricter rule is ever wanted, refuse the CallbackPath+"/" and FinishPath+"/" prefixes too.
  • The field comment is long for a field; fine here because this is the one place the "fresh rides the row" contract is stated in code.
LLM

Fable 5.1 review: APPROVED, no blockers; three notes for the Team-page slice (chi silently overwrites a duplicate r.Get; pin the main commit; page-level auth_time tests)

Merged to main as 69ea999 (squash) after Fable's APPROVED verdict above; CI green at 88e76c6. Not deployed — handoff is a library; it reaches production only when a consumer bumps its pin. Carried to the Team-page slice from the review: pin root go.mod to main 69ea999 (not 88e76c6); mount with r.Get(fresh.StartPath(), fresh.Start); add a directory-level test that /auth/start redirects without maxage and /auth/fresh/start with maxage=300 (chi silently replaces duplicate routes); a Team-page POST from an ordinary session is refused and sent to /auth/fresh/start.