gunk-dev/the-valley
the-valley:oc-7b1d909outcomedone

A reader redeems a link once and sees only what they may read

State
done
Created
2026-10-29 by contributor
Progress
3 of 3 done
Blocked by
Blocks
Children

Body

Phase 2a, slice 3 of 4.
- **Redemption:** `/-/redeem` clears the fragment and posts only after one click. It swaps the secret for a host-only, Secure, HttpOnly session cookie that renews on use, and sends the browser to a clean URL.
- **Single use:** the edge records consumption and sessions durably.
- **Isolation:** every view is built from the projects that reader may read. Private responses carry no-store cache headers.
- **Logout:** a logout POST ends the session.
- **Emergency stop:** an edge-side credential-generation reset, pending operator acceptance.

Comments

  1. contributor2026-10-29 12:38 UTC
    Decided by the operator: no edge-local emergency stop. The edge's only access state is what the host signs. When the host cannot reach the edge, the deployment's emergency stop is to stop the edge itself.
    
    Recovery from a lost edge volume stays host-side: the host revokes the old credentials and issues new links.
  2. contributor2026-10-30 14:16 UTC
    Design for slice 3 (part 2 of 4: change 2, browser state, locks, dispatch).
    
    ---
    
    5. Change 2: browser state and initialization
    
    Add `web/readerstate/`. The browser process owns `<stateDir>/browser/state`, a versioned document containing permanent consumed-ID records. Each record holds the original binding tuple and an optional session-token hash. Removing the hash logs out the session; it never removes consumption.
    
    Do not add receiver binding history, markers, or preparation commands. `Store.Authorize` remains independent of browser-state health and capacity, so revocations continue to arrive.
    
    The directory is provisioned by deployment configuration:
    
    - NixOS tmpfiles creates `<stateDir>/browser/` as `valley-web:valley-web`, mode 0700, before the browser service starts.
    - The image’s fake-root step creates it with the browser UID and shared GID, mode 0700.
    - Existing bind mounts require the same ownership supplied by their deployment configuration.
    
    Neither unprivileged process creates or changes the ownership of this directory. The parent remains receiver-owned, mode 0750; it never becomes group-writable.
    
    The browser unit mounts receiver storage read-only and permits writes only to `browser/`. The receiver unit cannot write inside that subtree. Update `nix/web-receiver.nix`, `nix/packages.nix`, module checks, image checks, and container instructions together.
    
    State, temporary files, and lock files are mode 0600. Reject symlinks and unexpected file types.
    
    An absent state file initializes only under a successfully read, valid stored authorization containing zero bindings. Missing, unreadable, or malformed authorization does not mean zero bindings.
    
    Initialization takes the same locks and durable-write path as a mutation. It rechecks authorization while holding the shared serving lock, so a binding-bearing authorization cannot race the empty-state decision.
    
    Initialization is retried when later requests observe a new authorization. It needs no process restart after the host delivers an empty binding set.
    
    The startup cases are:
    
    - Browser starts before the receiver creates its descriptor: `OpenReadOnly` fails and service restart retries.
    - Receiver storage exists but no authorization is stored: the browser creates no state. Reader routes can render; redemption is unavailable.
    - First authorization has bindings and state is absent: no initialization occurs. Redemption and requests carrying a session cookie receive 503. Anonymous reads continue.
    - First authorization has no bindings: the browser durably creates empty state. Later issued links work normally.
    - The browser starts after authorization arrives: the same binding test applies.
    - A crash before initialization commits leaves state absent or a complete empty file. Recovery ignores temporary files and rechecks authorization before any absent-state initialization.
    - A crash after durable initialization preserves empty state. A later binding-bearing authorization can use it.
    - A binding-bearing authorization arrives after an empty authorization but before initialization acquires the serving lock: initialization refuses.
    - Initialization acquires that lock first: it commits before the receiver can store bindings.
    
    Startup validates an existing canonical state and establishes its durability before publishing it as usable. It never promotes an abandoned temporary file.
    
    After total volume loss, no authorization means no initialization. The host’s first authorization carrying existing bindings therefore leaves redemption closed. Already-used links do not become redeemable.
    
    The same rule affects links issued before the edge first runs. If the first authorization already contains them, they cannot be redeemed. The guide requires `valley-web-publish link revoke --all`, delivery of an authorization with no bindings, successful state initialization, and then issuance of replacement links.
    
    Missing state uses that recovery path. Corrupt state is never silently replaced; recovery first delivers the empty binding set, then removes the corrupt browser state while the browser is stopped, and restarts it.
    
    A coherent restoration of old browser state is not detected. Host backup restoration retains its accepted semantics. No edge-local emergency stop or credential-generation reset is introduced.
    
    6. Change 2: snapshots, locks, and transactions
    
    One `valley-web` process owns each browser-state directory. Enforce this with a lifetime ownership flock on `browser/owner.lock`; a second process refuses startup. This is necessary because separate processes cannot safely maintain independent cached snapshots.
    
    Hold the decoded browser state in memory under a `sync.RWMutex`. Reads use `RLock`; they take no transaction flock and perform no whole-file decode.
    
    Use this single order:
    
    1. Browser-state RWMutex: read mode for reads, write mode for mutations.
    2. Transaction flock on `browser/lock`, for mutations only.
    3. Shared receiver serving lock.
    
    Release in reverse order. Never acquire browser-state locks while holding a serving lock or cache lock.
    
    At startup and request checks, detect a missing or externally replaced canonical state file. Do not continue serving sessions from a cached snapshot after detected state loss. Online external edits are unsupported; replacement or corruption produces a state fault, not an automatic reload. Anonymous reads remain available.
    
    Redemption and logout take the write lock and transaction flock. They then take the shared serving lock, re-read authorization, and validate the operation.
    
    A mutation writes the complete next state to an exclusive temporary file, fsyncs it, renames it over `state`, and fsyncs `browser/`. Only after durable success does it publish the new in-memory snapshot. Success headers follow that publication.
    
    An uncertain write or fsync failure makes browser state unavailable until restart and successful recovery. Do not resume from the old cached snapshot.
    
    Consumption and session creation are one transaction. Two concurrent valid redemptions have exactly one successful commit. A crash before commit permits retry if the old state survives. A crash after commit leaves the ID consumed even if no cookie reaches the browser.
    
    Bound the state document at 32 MiB. Capacity exhaustion refuses new redemption without consumption. Logout remains possible without increasing its size. Permanent consumed IDs are never pruned to reclaim capacity.
    
    An authorization cannot reset consumption. A consumed ID refuses redemption regardless of its new tuple. A session requires an exact match of credential ID, principal, and verifier. Reusing an ID therefore cannot transfer an existing session to another principal. An unconsumed ID has no existing session to hijack.
    
    7. Change 2: dispatch and response checks
    
    Add `web/server/reader.go`, `web/server/assets/reader.js`, and redemption/logout templates.
    
    At the start of `ServeHTTP`, create the existing request timeout context and classify the route. Apply common headers and its route CSP.
    
    Dispatch exact `POST /-/redeem` and `POST /-/logout` here, before the rendering retry loop. These handlers execute once. They use the same request deadline, bounded body reading, common headers, and transaction rules. They never enter `q.serve()` or its content-generation gates.
    
    GET and HEAD stay inside the rendering retry loop. In `q.serve`, dispatch exact reader pages after method validation but before the authorization and export gates. They require no content generation and render even when nothing is published.
    
    Reader pages use only the reader script hash, the stylesheet hash, and `connect-src 'self'`. Their errors retain this policy. Content pages never admit the reader script.
    
    An active session adds a “Sign out” link to navigation independently of whether an export exists. Cached indexes contain no session-specific navigation.
    
    For ordinary responses and reader-page GET/HEAD responses, the final check takes the browser read lock, then shared serving lock. It rechecks authorization and session resolution. If the effective reader context or authorization changes, discard the response and retry within the existing three-render limit.
    
    Only after that check does the server add session renewal and write headers. Release both locks before writing the body. A timeout or state fault never renews an unverified session.
    
    Revocation applies to responses not yet admitted at this boundary. It cannot retract a download whose headers already began.
    
    HEAD returns GET status and headers, including valid renewal, without a body. It never consumes or logs out. Unsupported methods return 405. OPTIONS enables no CORS.
  3. contributor2026-10-30 14:16 UTC
    Design for slice 3 (part 1 of 4: change 1, isolation), as revised after a cross-family critique, at main fe48b06a. Two changes: isolation first, then redemption and sessions.
    
    One coordinator simplification applies to §2: reserve the anonymous index, which named views never evict, and one of the two loaders for anonymous work. Drop the separate quota on waiting places; named views share the rest of the existing bounds.
    
    ---
    
    Slice 3 has two changes: isolation first, then redemption and sessions. Slice 4, knot `oc-465153d`, remains responsible for publishing projects readable only by named principals.
    
    The design targets HEAD `fe48b06af1c99d884cbac3e12664a31800b7bb0f`. New mechanisms below are **not built**. The claim checklists distinguish existing guarantees from proposed implementation and deployment configuration. No additional operator decision is required.
    
    1. Change 1: isolate every view before enabling sessions
    
    The server builds each response from one reader’s visible projects. Visibility is the union of projects authorized for `anyone` and projects authorized for the reader’s principal. Both checks use the project’s publication identity.
    
    Keep `visible` in `web/server/plan.go` as the single project filter. `Authorization.Allows` continues to test one principal exactly; `visible` performs the union. Add `viewFor` in `web/server/server.go` to obtain a decoded export and its reader-specific index.
    
    Production requests still resolve to `anyone` in this change. Internal tests supply named reader contexts. Signed test fixtures exercise private projects already present on the edge; the production publisher’s selection remains unchanged until slice 4.
    
    Add `web/server/projection.go` with `projectForReader`. It creates immutable projected copies of visible projects and knots before `newIndex` builds plan structures. It never modifies the shared decoded export.
    
    The projection handles cross-project information as follows:
    
    - `WaitingOn` contains only references to visible projects.
    - `WaitingOnHidden` combines the export’s opaque summary for omitted projects with hidden references removed from `WaitingOn`.
    - `ClearedByEnding`, `Dangling`, and `Unresolved` exclude references to invisible projects.
    - An edge into an invisible project becomes `EdgeHidden`. Its resolved title, status, and other target metadata are discarded, regardless of its export-time state.
    - Structured references such as `BlockedBy`, `Target`, `GraduatedInto`, and change links render through the index’s visibility-aware helpers. Internal reference identifiers never become fallback labels for hidden targets.
    - References into visible projects retain their exported classification. An already hidden edge supplies no information to reconstruct.
    
    Do not infer waiting from `BlockedBy`. A blocker can be done. The export’s `WaitingOnHidden` is needed because a project omitted from the export cannot be reconstructed at the edge. It is an opaque aggregate, not authority to reveal any target.
    
    Keep the knot’s own derived `State` and `Ready` values. Project hiding does not recalculate the host’s plan state. It removes disclosures about foreign targets.
    
    The required regression fixture contains a visible knot whose only blocker is a done knot in a hidden project. Build one export without that project and another containing it. For a reader unable to see the blocker, projected fields and rendered plan and knot pages are identical. Neither view invents a hidden waiting indication. Repeat with an unfinished blocker: both views show the same single neutral unavailable-dependency indication.
    
    All index consumers use projected data:
    
    - Routing: `route`, `projectRoute`, `moved`, `home`, and `project`.
    - Plan construction: `plan`, `planPage`, `inFlight`, `readyChanges`, `paths`, `milestones`, `descendants`, `tree`, and `row`.
    - Knot references: `knot`, `reference`, `named`, `change`, and `waitsOn`.
    - Navigation: `page`.
    - Source: `source`, `dir`, `file`, `log`, `markdown`, and `archive`.
    
    A group with no visible projects has no alias. Hidden projects contribute no navigation, former names, aliases, redirects, structured target metadata, or source access.
    
    Authored prose and absolute links remain published content. The filter cannot remove private information explicitly written into a visible document. Documentation states this boundary rather than promising content redaction.
    
    2. Change 1: request order and index caching
    
    Resolve authorization and the reader view before taking a git slot.
    
    Refactor `request.serve` into these stages:
    
    1. Validate the method and resolve the request’s authorization and reader context.
    2. Obtain the decoded export and projected index.
    3. Resolve the route through that index.
    4. Answer missing resources and redirects without taking a git slot.
    5. For an authorized source operation requiring git, take a slot and open the matching generation.
    6. Render the complete response.
    7. Release generation and index references.
    8. Perform the final authorization check and write headers.
    
    Do not hold a generation while waiting for an index or git slot. If the active generation changes before the matching generation opens, release admission and restart view resolution within the request deadline.
    
    Replace URL-shape admission through `runsGit` with admission after indexed route resolution. Hidden and nonexistent projects take no git slot. Alias redirects and `main.tar.gz` redirects take none either.
    
    The request deadline remains 15 seconds. The five-second git deadline starts when the git slot is acquired. Index construction and waiting therefore consume the request deadline without occupying `MaxGit`.
    
    Separate decoded exports from projected indexes. An index key contains:
    
    - Content generation.
    - Exact authorization revision.
    - A canonical sorted set of visible project identities.
    
    Different principals with the same visible set share an index. Session identity remains request-local and never enters cached navigation or templates.
    
    Reserve the anonymous index independently of named-view capacity. Maintain two anonymous slots: the current index and a retiring or replacement index. Named readers cannot evict them. A named reader whose view equals the public view shares the anonymous index.
    
    Maintain at most eight additional indexes, including entries being built or pinned by requests. Evict only unpinned entries. If all slots are occupied, requests wait within a bounded queue and their existing deadline, then receive 503. Retired entries remain counted until released. Pins end after rendering, before response transmission.
    
    Keep export decoding under `MaxLoads = 2`. Index construction uses separate workers: one reserved anonymous worker and at most two additional-view workers. An index build starts only after decoding finishes and releases its loader slot. No worker holds a loader slot while waiting for an index slot.
    
    Reserve anonymous admission within load waiting and decoding: named-only loads occupy at most one loader, and named waiters occupy at most 48 of the existing 64 waiting places. Anonymous work can use the remaining capacity. Coalesced work needed by anonymous requests receives anonymous admission. These reservations prevent named-view contention from exhausting anonymous index or loading capacity; they do not promise immunity from shared CPU or git contention.
    
    All existing rendering and response limits remain shared across readers:
    
    - MaxGit: 8.
    - MaxRendering: 2.
    - MaxBuffered: 64 MiB.
    - MaxLarge: 48 MiB.
    - MaxResponse: 8 MiB per response.
    
    Archive input and entry limits remain unchanged. Adding principals does not multiply these budgets.
    
    3. Change 1: routes, headers, and same-origin behavior
    
    Align with knot `oc-eb22364`: the plan page is `/-/knots`. `/` redirects to the first visible project’s source tree, using index order. With no visible project it redirects to `/-/knots`.
    
    This redirect is reader-specific. It uses the same cache policy and final authorization check as a rendered page. Successful redemption in change 2 navigates to `/`.
    
    Set these headers on every response, including anonymous responses, redirects, errors, HEAD, and archives:
    
    `Cache-Control: private, no-store`
    
    `Vary: Cookie`
    
    Emit no ETags or 304 responses. Update existing header assertions in the same change.
    
    Replace the single CSP value with route policies in `web/server/render.go`. `setHeaders` accepts the route policy selected from the parsed request path.
    
    - `/-/knots` admits only the plan script’s hash and uses `connect-src 'none'`.
    - Other content routes admit no script and use `connect-src 'none'`.
    - Change 2 supplies the reader-route policy.
    
    Retain the stylesheet hash, `object-src 'none'`, `base-uri 'none'`, `form-action 'none'`, and framing restrictions. Error responses retain their route’s policy.
    
    Retain `Referrer-Policy: no-referrer`. External Markdown links need no additional `rel=noreferrer`; the response policy suppresses the Referer. No new renderer attributes or link targets are required.
    
    Rendered Markdown remains suitable for a session-bearing origin. It emits a fixed element and attribute set, escapes repository text, and constrains links. It emits no project scripts, forms, images, or style attributes.
    
    Archives remain gzip attachments with `nosniff`. They never serve repository files inline. Both archive routes pass through project authorization before repository access, use the existing buffer limits, and receive the final authorization check before headers.
    
    A future feature serving active project content requires another origin that receives no reader cookie. A different path is insufficient.
    
    Keep `Checked`, freshness age, and the stale chip. They describe publication freshness; they never determine access. The response uses the authorization revision that passes its final check.
    
    4. Change 1: tests, acceptance, and slice 4 boundary
    
    Extend `web-server-unit`, cost class `quick`, with:
    
    - Anonymous and two named views over signed fixtures.
    - Public-plus-principal union and publication-identity matching.
    - All routes, aliases, root redirects, structured references, Markdown, and archives.
    - The hidden done-blocker equivalence test described above.
    - Projection immutability and the filtering of all five cross-project derived fields.
    - Shared indexes for identical visible sets.
    - Anonymous capacity surviving named-view saturation.
    - Cancellation, bounded waiting, and absence of nested loader/index waits.
    - Hidden and nonexistent source paths taking no git slot.
    - Existing freshness-age and stale-chip behavior.
    - Uniform missing/forbidden responses and updated response headers.
    - Revocation during rendering, including Markdown and archives.
    
    Extend `web-push-e2e`, also `quick`, for route alignment and header behavior using real packaged binaries.
    
    Slice 4 changes the production data path explicitly:
    
    - `publisher.selects` and collection consider placed projects selected by any effective principal, rather than `anyone` alone.
    - Consent reading computes `grants.Readers(consent)`.
    - `checkPolicy` emits those effective reader lists in `AuthorizedProject.Readers`.
    - `collect` and `read` obtain knots, source tips, and bundles for the union of projects with nonempty effective readers.
    - The existing policy-read failure path retains only previously authorized readers still covered by current registry grants and the previous publication identity. It does not introduce a new reader without a successful consent read.
    - `export.Build` receives that union in `Inputs.Identities`. Its `exported` set means “present on this edge,” not “public.”
    - Export-time projection remains a storage-boundary projection: references to projects outside that union remain hidden. References within it retain the information needed by the server’s reader projection. No per-principal exports are produced.
    
    Thus slice 3 tests the server’s readiness for private exports without claiming that its production publisher already sends them.
  4. contributor2026-10-30 14:16 UTC
    Design for slice 3 (part 4 of 4: documentation and claim checklists).
    
    ---
    
    11. Documentation and claim-to-code checklists
    
    Change 1 documents filtered views, projection, cache bounds, request admission, headers, and source safety. Change 2 documents session workflows, state authority, initialization, recovery, request formats, and bearer limitations.
    
    Place procedures in `docs/guide.md`; routes, flags, formats, and limits in `docs/reference.md`; execution and locking in `docs/architecture.md`; and trust boundaries and recovery consequences in `docs/security.md`. Configuration remains labelled **deployment choice**. Keep slice 4 work in the plan graph and its brief. The archive remains unchanged.
    
    These checklists belong in the briefs and change descriptions, not the prose docs. Citations refer to verified HEAD anchors; proposed functions have no existing line citation.
    
    Change 1 checklist:
    
    - **Implemented:** exact-principal authorization lookup — `web/export/authorization.go:163`, `Authorization.Allows`. Union filtering is **not built**.
    - **Implemented:** common visibility and index construction — `web/server/plan.go:60`, `visible`; `web/server/plan.go:71`, `newIndex`; `web/server/plan.go:111`, `place`.
    - **Implemented:** export-time cross-project projection — `web/export/project.go:308`; derived fields at `web/export/project.go:337`; hidden edges at `web/export/project.go:350`. Reader projection is **not built**.
    - **Implemented:** reference rendering — `web/server/knot.go:149`, `reference`; `web/server/knot.go:175`, `named`; `web/server/knot.go:201`, `change`; `web/server/knot.go:219`, `waitsOn`.
    - **Implemented:** current admission and loading — `web/server/server.go:528`, `serve`; `web/server/server.go:592`, `runsGit`; `web/server/server.go:647`, `open`; `web/server/server.go:795`, `read`. Proposed ordering and cache reservations are **not built**.
    - **Implemented:** source gate and Markdown resolution — `web/server/source.go:56`, `source`; `web/server/source.go:421`, `markdown`; `web/server/source.go:457`, `resolver`.
    - **Implemented:** archive buffering and attachment disposition — `web/server/archive.go:67`, `archive`.
    - **Implemented:** Markdown output restrictions — `web/markdown/markdown.go:1`; destination handling at `web/markdown/markdown.go:1511`.
    - **Implemented:** response policy and freshness — `web/server/server.go:1108`, `setHeaders`; `web/server/render.go:32`, CSP; `web/server/render.go:290`, `freshnessOf`.
    - **Implemented:** publication remains public-only — `web/cmd/valley-web-publish/valley.go:61`, `collect`; `web/cmd/valley-web-publish/valley.go:153`, `read`; `web/cmd/valley-web-publish/valley.go:242`, `selects`; `web/cmd/valley-web-publish/policy.go:244`, policy selection.
    - **Implemented:** effective-reader evaluator for slice 4 — `readaccess/access.go:103`, `Grants.Readers`.
    - **Not built at this HEAD:** `/-/knots` and reader-specific root redirect; current routing anchor is `web/server/server.go:907`, `route`.
    
    Change 2 checklist:
    
    - **Implemented:** link format, entropy, and verifier — `web/cmd/valley-web-publish/link.go:673`, `issueLink`.
    - **Implemented:** stored bindings and parsing — `web/export/authorization.go:79`, `Binding`; `web/export/authorization.go:292`, `ParseAuthorization`.
    - **Implemented:** authorization replacement remains independent — `web/export/authorize.go:120`, `Authorize`.
    - **Implemented:** shared serving lock and final response boundary — `web/export/authorize.go:159`, `HoldServing`; `web/server/server.go:470`, `ServeHTTP`. Session checks are **not built**.
    - **Implemented:** browser storage opens read-only — `web/export/store.go:325`, `OpenReadOnly`; command wiring at `web/cmd/valley-web/main.go:68`, `run`.
    - **Implemented:** durable-write precedent — `web/export/store.go:1451`, `writeDurablyHeld`. Private browser transactions and snapshots are **not built**.
    - **Deployment choice:** distinct users, receiver ownership, and browser read-only mount — `nix/web-receiver.nix:260`, `nix/web-receiver.nix:279`, `nix/web-receiver.nix:303`.
    - **Deployment choice:** image users and volume ownership — `nix/packages.nix:641`. Browser subtree provisioning is **not built**.
    - **Implemented:** navigation construction — `web/server/render.go:85`, `page`. Session navigation and reader policies are **not built**.
    - **Implemented:** race-test anchors — `web/server/server_test.go:3314` and `web/server/server_test.go:3356`; hostile-content test at `web/server/server_test.go:1408`.
    - **Implemented:** existing check assembly — `nix/checks/web.nix:1`, `nix/checks/web-push-e2e.nix:1`. New crash and browser checks are **not built**.
    - **Deployment choice:** existing broad web check requirements — `policy/project/policy.cue:246`; cost declarations at `policy/project/policy.cue:96`. The narrower browser class is **not built**.
    - **Recorded operator decision:** bearer scope, expiry, restore, and emergency-stop boundary — `docs/security.md:588`. Freshness display remains independent of these access decisions.
  5. contributor2026-10-30 14:16 UTC
    Design for slice 3 (part 3 of 4: change 2, redemption, cookies, checks).
    
    ---
    
    8. Change 2: redemption, switching, and logout
    
    The issued fragment remains `<credential-id>.<secret>`. The ID is `lk-` plus 16 lowercase hexadecimal digits. The secret is canonical unpadded base64url for 32 bytes. Compare SHA-256 of decoded secret bytes with the current binding verifier in constant time.
    
    The reader script’s first action copies the fragment into a closure and clears it with `history.replaceState`, before parsing or installing handlers. The secret never enters the DOM, storage, URL queries, or logs.
    
    Without a valid session, the page shows “Continue as reader.” Loading, executing, focusing, or restoring the page sends no POST. One click starts one request and disables the button while it is pending.
    
    With a valid session, the page instead offers “Sign out and continue with this link.” Clicking explicitly performs logout, then redemption, retaining the link secret in memory. It does not navigate through the logout page.
    
    If logout fails or its result is uncertain, retain the secret and offer an explicit retry of the sequence. Logout is idempotent. If another session becomes active before redemption, the server returns 409 and the page again offers explicit switching.
    
    `POST /-/redeem` accepts exactly `{"credential":"<id>.<secret>"}`. Logout accepts exactly `{}`. A shared `checkReaderPost` requires:
    
    - Exactly one Origin equal to the configured public HTTPS origin.
    - JSON media type, optionally UTF-8 charset.
    - Exactly one `X-Valley-Reader: 1`.
    - At most 1 KiB of body.
    - One strict JSON object, with no duplicate or unknown keys or trailing document.
    - No query parameters or content encoding.
    
    Add `--origin` to `valley-web` and the module’s configuration. It is required for reader support and contains only an HTTPS scheme and authority. Neither Host nor forwarded headers determine the accepted origin. No CORS headers are emitted.
    
    Malformed, unknown, revoked, wrong-secret, and consumed credentials receive the same fixed 403 response: “This link cannot be used. Request another link.” Request-contract refusals also use generic 403. State failures use generic 503.
    
    A valid existing session causes 409 before consumption. The server never silently replaces it, even with a link for the same principal.
    
    Successful redemption returns 204 with the cookie after durable commit. The script clears its secret and navigates to `/`.
    
    A failed or uncertain POST retains the secret for explicit retry. No automatic redemption retry occurs. If commit succeeded but the cookie was lost, retry refuses the consumed link; another link is required.
    
    Logout durably removes the current token hash and clears the cookie. It preserves consumption and affects no other credential. A logout request with no valid session succeeds idempotently.
    
    9. Change 2: tokens and cookies
    
    The session token is `<credential-id>.<random>`, with 32 fresh cryptographically random bytes encoded as canonical unpadded base64url. Persist only SHA-256 of the complete token.
    
    Use:
    
    `__Host-valley-reader=<token>; Secure; HttpOnly; Path=/; SameSite=Lax; Max-Age=2592000`
    
    Omit Domain and Expires. Lax supports ordinary external navigation into a private page; POST checks protect mutations.
    
    Count every matching cookie across all Cookie headers and semicolon-separated pairs. Do not use a first-match lookup. More than one is unauthenticated.
    
    Against readable state, an unknown, malformed, duplicate, revoked, or logged-out cookie falls back to anonymous and receives no renewal. Missing or unreadable browser state causes 503 for requests carrying the session cookie. Cookie-free anonymous requests continue.
    
    Renew the same token only after the final check, on every authenticated GET/HEAD response, including 404 and ordinary error responses. Hidden and nonexistent resources therefore receive identical renewal behavior. Do not renew responses whose final validation fails.
    
    Renewal changes only browser retention. It writes no timestamp and creates no server expiry. A copied token remains valid while its persisted hash and exact current binding remain valid.
    
    Losing all personal grants leaves a valid session with public visibility. Restored grants work through it. Binding withdrawal invalidates it; a later identical binding may restore it under accepted host-restore semantics. Logout permanently removes that hash.
    
    10. Change 2: checks and acceptance
    
    Extend `web-server-unit`, `quick`, with strict request parsing, cookie multiplicity, anonymous fallback, switching, route-specific CSP, empty-export reader pages, 404 renewal, state faults, capacity behavior, and session rechecks.
    
    Use deterministic barriers for revocation and logout during page, Markdown, redirect, and archive preparation. Assert that no forbidden response begins after the corresponding completed mutation.
    
    Extend `web-push-e2e`, `quick`, with real packaged binaries for:
    
    - Host-issued link redemption and host-side revocation.
    - Concurrent redemption with one winner.
    - Browser and receiver restarts.
    - Initialization orderings and lost-volume recovery.
    - Logout and exact-tuple session checks.
    - Archive headers, downloads, and unchanged resource limits.
    - Logs containing neither tested secrets nor tokens.
    
    For named-private isolation before slice 4, use a clearly identified signed fixture phase through the real receiver. Do not attribute those private exports to the production publisher.
    
    Add `web-reader-state-crash`, `quick`, using subprocess termination and transaction fault injection around writes, syncs, rename, snapshot publication, and response issuance. Every acknowledged consumption survives restart. Unacknowledged outcomes may be consumed or retryable, but never produce two successful redemptions.
    
    Add `web-reader-browser-e2e`, `slow`, as a Nix sandbox check, without a VM. Run packaged `valley-web` behind a local TLS proxy and headless Chromium with a temporary profile and locally trusted test CA.
    
    Use only necessary flags: headless mode, a temporary profile, and a local automation endpoint. If the Nix sandbox cannot support Chromium’s nested sandbox, use `--no-sandbox` only within this isolated test. Use `--disable-dev-shm-usage` only where the sandbox’s shared-memory allocation requires it. Do not disable certificate verification or browser security features.
    
    Budget 2 GiB of available memory for this single-browser check and run one browser instance. Its closure includes Chromium; its cost is therefore `slow` even though it avoids VM startup.
    
    Its acceptance scope is limited to browser-engine behavior:
    
    - Loading the page clears the fragment and sends no redemption POST.
    - CSP admits the reader script and its fetch.
    - CSP blocks injected scripts.
    - One click redeems once, stores the host cookie over HTTPS, and navigates to `/`.
    
    HTTP contracts, isolation, hostile-content output, archives, revocation, logs, and permissions remain in unit, binary, module, and image checks.
    
    Register a separate reader-browser policy class. Require the slow check for reader script/templates, shared layout and rendering policy, `server.go` dispatch/header handling, reader handlers, browser command setup, and the browser check’s own files. Include packaging changes that alter the tested binary or assets. Do not attach it to the broad `web/**` class; publisher-only, export-only, archive, and graph-projection changes do not automatically require Chromium.
  6. contributor2026-11-08 22:29 UTC
    Done: redemption, single use, isolation and logout are built in oc-c430d70 (1391837a), oc-eef75aa and oc-75d81ae.