| 1 | # Device preview pass |
| 2 | |
| 3 | Approved by the controller, 2026-11-26. Branch `preview/pass`, main `7c113ac8`. |
| 4 | No implementation changes precede this note. |
| 5 | |
| 6 | ## Contract and binding |
| 7 | |
| 8 | A tap on Preview calls bearer-authenticated |
| 9 | `POST /api/v1/tasks/{id}/preview-pass` with the candidate SHA the person saw. |
| 10 | Use the same current-person and task-read authority as `GET /tasks/{id}`, |
| 11 | including team visibility. Recheck the active roster and originating device |
| 12 | credential inside the write transaction. Refuse a stale candidate or a preview |
| 13 | that the existing wrapper would refuse. Do not mint authority to approve an |
| 14 | unsafe preview; an already approved preview keeps the wrapper's warning. |
| 15 | |
| 16 | Return an opaque, cryptographically random 32-byte base64url pass and an |
| 17 | RFC 3339 UTC expiry and bounded whole-second lifetimes from mint time, never a raw preview address. Native subtracts elapsed request time and uses only these lifetimes for its local deadlines, independent of server/device clock skew. Store only its SHA-256 hash, |
| 18 | with a separate non-secret audit ID. Bind the record to this instance, person, |
| 19 | device credential and session epoch, task ID, candidate SHA, Preview step ID |
| 20 | and attempt, and a fingerprint of that deployment (URL, digest, expiry and |
| 21 | unsafe flag). The fingerprint prevents a redeployment of the same candidate |
| 22 | from silently changing what the pass opens. The pass expires after 60 seconds, |
| 23 | or earlier if the device credential or preview expires. Use the injected |
| 24 | server clock throughout. A pass is a bearer capability; its person binding |
| 25 | comes from minting, not a second sign-in or a submitted address at exchange. |
| 26 | |
| 27 | ## Exchange and browser session |
| 28 | |
| 29 | The native web view POSTs the pass to the fixed same-origin path |
| 30 | `/native/preview/exchange`. No pass in a URL, fragment, redirect, HTML or logs. |
| 31 | The request has a bounded form body and the configured Origin; it passes the |
| 32 | existing same-origin CSRF checks. There is no wildcard CSRF exemption and no |
| 33 | GET exchange. Reject conflicting Origin/Referer/fetch-site headers, unexpected |
| 34 | fields, and any device Authorization header here. A browser session cookie |
| 35 | alone cannot mint or exchange a pass. |
| 36 | |
| 37 | In one transaction, hash and find the pass, conditionally consume it once, |
| 38 | recheck membership/device/session epoch and the full preview binding, create a |
| 39 | fresh random browser grant, and append the audit event. Concurrent exchanges |
| 40 | have one winner. A known expired or stale pass is terminal, with no grant. |
| 41 | DB or audit failures cannot issue a cookie. A lost exchange response requires |
| 42 | a new pass; replay does not reproduce a grant. |
| 43 | |
| 44 | Success sets a host-only `__Host-equipo-preview-{taskID}` cookie, Secure, HttpOnly, |
| 45 | SameSite=Strict, with Path `/`, and redirects with 303 to |
| 46 | that exact wrapper URL constructed by the server. No caller-provided redirect. |
| 47 | The cookie contains a fresh opaque secret, stored hashed. Its lifetime is at |
| 48 | most 15 minutes, capped by the device and preview expiries, without sliding |
| 49 | renewal. All exchange/wrapper responses use no-store and no-referrer. |
| 50 | |
| 51 | This is an ordinary cookie-based browser session with restricted authority, |
| 52 | implemented as an app-owned preview grant. It must not create a general |
| 53 | Rastrillo/Oficina ID sign-in session. The host prefix prevents sibling-domain cookie planting: |
| 54 | server checks permit exactly GET of the bound task's wrapper. No task |
| 55 | page, API, event stream, attachment, other task, unsafe-preview POST or other |
| 56 | mutation accepts it. General session authentication never recognizes this |
| 57 | cookie. Keep normal browser sign-in behavior for requests without a preview |
| 58 | grant. Only a well-formed grant secret under this task’s cookie name selects the restricted lane; junk and other tasks’ cookies are ignored. Once selected, an invalid or expired grant cannot fall through to a broader signed-in session. |
| 59 | |
| 60 | ## Wrapper, expiry and candidate changes |
| 61 | |
| 62 | Share the existing `previewWrapper` renderer and preview eligibility checks. |
| 63 | Keep its CSP, iframe sandbox (`allow-scripts allow-same-origin`), origin |
| 64 | validation, header warnings and referrer policy. Never load the raw origin as |
| 65 | the top-level document. Each wrapper request rechecks the originating device, |
| 66 | current roster, task visibility, expiry and exact deployment binding. It does |
| 67 | not switch to a newer candidate. Candidate changes return 409 with the reviewed |
| 68 | `evidence.candidate_changed` words; expired passes/grants/previews show the |
| 69 | reviewed `question.expired` label. Other failures use existing reviewed words. |
| 70 | |
| 71 | Native drops the web view at expiry, sign-out or a task update that changes the |
| 72 | binding, and revalidates when returning to the foreground. A new tap can mint |
| 73 | a new pass. Server expiry prevents further wrapper reads; it cannot retract |
| 74 | HTML already delivered to a browser or revoke the preview origin itself. |
| 75 | |
| 76 | ## Native choice |
| 77 | |
| 78 | Use a dedicated WKWebView sheet on both platforms with a fresh |
| 79 | `WKWebsiteDataStore.nonPersistent()` per presentation. WKWebView accepts a |
| 80 | URLRequest, allowing the POST-body exchange, and isolates this cookie from |
| 81 | ordinary browser sign-ins. Load the actual server response, not an HTML string |
| 82 | or a native proxy, so the wrapper's response headers and iframe remain intact. |
| 83 | SFSafariViewController's URL initializer is less suitable for this exchange. |
| 84 | |
| 85 | Extend the allowlisted opener with a typed preview destination: exact session |
| 86 | origin plus the fixed exchange and wrapper paths for a validated task ID. |
| 87 | Allow only those top-level navigations; reject unexpected redirects, popups, |
| 88 | downloads and custom schemes. Keep the preview within its sandboxed child |
| 89 | frame. No injected scripts, native script-message bridge, relaxed TLS, device |
| 90 | bearer in WebKit, or automatic opening of blocked links. Test subframe loading |
| 91 | separately so the navigation policy does not accidentally block the preview. |
| 92 | |
| 93 | Apple references: [WKWebView request loading](https://developer.apple.com/documentation/webkit/wkwebview/load(_:)-5siv6), |
| 94 | [nonpersistent storage](https://developer.apple.com/documentation/webkit/wkwebsitedatastore/nonpersistent()), |
| 95 | [Safari view controller](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/). |
| 96 | |
| 97 | ## Storage, audit and proof |
| 98 | |
| 99 | Add app-owned pass/grant tables via additive migration and register them in |
| 100 | Models/Schema; do not modify framework session tables. Bound issuance per |
| 101 | person/device/task, rate-limit exchange, and prune expired records. Audit mint, |
| 102 | exchange and identifiable refusals with actor/task/non-secret grant ID and |
| 103 | reason, transactionally; never include secrets, cookies, preview URLs or body |
| 104 | contents. Unknown-token refusals remain generic and rate-limited. |
| 105 | |
| 106 | Test first and mutate: task visibility, revoked member/device/backing native |
| 107 | session, person/instance/task/candidate/deployment binding, exact expiry, |
| 108 | concurrent single use and replay, failed-audit rollback, cookie attributes, |
| 109 | GET-only route isolation, CSRF/redirect refusal, wrapper sandbox/CSP and raw |
| 110 | origin refusal. Native fake-server tests cover request/expiry, stale candidate, |
| 111 | allowlist, redirects, foreground revalidation and sign-out. Browser tests cover |
| 112 | the real exchange-to-wrapper flow. Add OpenAPI contracts and a perf-budget |
| 113 | record for any new GET, then native and Go gates and Linux CI. No runner |
| 114 | protocol change is needed. |
| 115 | |
| 116 | ## Approved refinements |
| 117 | |
| 118 | Pass and grant lookups are indexed exact hash matches. Unknown, consumed and |
| 119 | wrong-binding requests share the same generic refusal; stale/expired copy is |
| 120 | available only after the capability's identity and submitted context validate. |
| 121 | Device and IP limits apply separately. A well-formed secret in this task’s Host-prefixed cookie selects the restricted lane, even if unknown or expired alongside a general session. Junk cannot select the lane. |
| 122 | Host-only scope and a different iframe cookie host are tested in a real browser. |
| 123 | Dismissal, expiry, sign-out and account replacement drop both native resources. |
| 124 | |
| 125 | ## Security review refinements, 2026-11-26 |
| 126 | |
| 127 | The server returns expires_in (1–60) and grant_expires_in (1–900), rounded down |
| 128 | from the mint clock. Absolute timestamps are audit/display metadata. Native |
| 129 | subtracts the full elapsed request duration before starting either local |
| 130 | lifetime; it never adds transit time or renews a grant. |
| 131 | |
| 132 | A terminal known pass is consumed and a refused grant is deleted in the same |
| 133 | transaction as its one refusal audit. Replays do not add refusal audits. Expired |
| 134 | rows are pruned after exchange and read too, allowing a first bound expired |
| 135 | request to receive its reviewed words. Both tables have composite device/task |
| 136 | indexes in additive migration 0110. |
| 137 | |
| 138 | Child frames may navigate to about:blank, about:srcdoc, blob: and data: inside |
| 139 | the wrapper sandbox. These schemes remain forbidden for the main frame. Link |
| 140 | previews are disabled. A real nested-frame fixture checks srcdoc and blob |
| 141 | loading through the wrapper in the browser lane and the iPhone simulator. |
| 142 | |