oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

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