Repository navigation
fix(web): re-sign a dropped session admission with the server clock - #4939
Dominion5254 wants to merge 5 commits into
Conversation
Encrypted RPC signs every browser admission, anonymous setup included, with the device clock. A server whose clock is synchronized drops an admission more than 30 s off without replying, and the client reports only "Encrypted RPC transport failed": a skewed browser cannot sign in, open tabs reconnect forever, and an uninitialized StartWRT router shows the Root CA page instead of the password form. When the server closes an opened session socket without answering the handshake, the session client reads the server's Date header with one HEAD to the server origin. If the measured offset differs from the one it signed with by more than half the server's tolerance, it signs the handshake again once with the server's time. Once that admission succeeds it keeps the offset for later admissions to that host, as AWS SDKs do for RequestTimeTooSkewed. A retry the server still drops is not remembered, so a Date header the verifier disagrees with never outlives the connection that read it, and a remembered offset is replaced the same way when the device clock is corrected. The server's ±30 s window and nonce cache are unchanged; its tolerance becomes the public TIMESTAMP_TOLERANCE_SECS and reaches the client through the generated SIGNATURE_PROFILE. Signed HTTP keeps the local clock: its proofs bind only the host and body, so one dated from a forged Date header on plain HTTP would later authorize any empty-body request to that host. StartOS's signed icon and package-document fetches therefore still need a correct device clock. A replayed hello cannot complete a session without the ephemeral X25519 secret.
helix-white
left a comment
There was a problem hiding this comment.
Request changes on c41793ad70b7312effca48707c2c13030cc5034f.
[P2] Refresh a stale cached offset before redeeming a single-use continuation — shared-libs/ts-modules/shared/src/services/session-websocket.ts:162–178.
After recovering with a device clock 120 seconds ahead, the browser remembers a −120-second offset. Correcting the device clock while its RPC connection remains open leaves that offset cached. The next continuation therefore signs its first hello 120 seconds behind the server. RpcContinuations::get_ws_handler removes the GUID before WebSocketHandler::on_upgrade validates admission (shared-libs/crates/start-core/src/rpc_continuations.rs:189–225,344–353), so that failed hello consumes the continuation. Reading Date and retrying the same URL then gets 404, not a recoverable admission. Before this change, the corrected local clock produced a valid first hello.
The existing “corrected device clock” test changes the mocked server's Date, not Date.now(), and does not model single-use redemption. The proposal records wall-clock and monotonic samples alongside an accepted offset and refreshes it before opening a socket when those clocks diverge by more than the existing 15-second threshold. An unavailable refresh fails before consuming the GUID. It still remembers a measured offset only after successful admission. It also uses monotonic elapsed time for the HEAD round-trip estimate, adds single-use continuation cases for correcting both positive and negative device skew, and records the admission contract in signed-session.md.
The PR merges cleanly with origin/master. Review and proposal are code-only; I did not build, format, lint or run tests. The author must verify any adopted changes. Current build, generated-artifact and several test jobs remain pending; the verdict does not depend on waiting for them.
Proposed changes: c41793a...proposal/4939
To adopt the proposal, cherry-pick it onto your branch rather than merging or pulling it, so the PR's head stays your own commit:
git fetch https://github.com/Start9Labs/start-technologies.git proposal/4939
git cherry-pick c41793ad70b7312effca48707c2c13030cc5034f..FETCH_HEADIf your branch has moved since c41793ad70b7312effca48707c2c13030cc5034f, resolve any conflicts the cherry-pick reports, or apply the changes your own way. Then push and say so in a comment.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
…g offset The server removes a continuation's GUID when it upgrades the socket, before admission is validated, so a second connection to the same GUID always gets 404. An unanswered continuation hello is no longer retried. When the server's Date disagrees with the offset the hello was signed with, the remembered offset is forgotten, so the next admission starts from the device clock instead of repeating a stale offset. This covers a server-clock change, which the monotonic check cannot see. Tests: a stale offset on a single-use continuation opens one socket and the next GUID signs with the device clock; an unreadable server clock after a device-clock change leaves the GUID unspent; prepareSession commits the requested signing time. The transport tests stub fetch, so the plaintext-downgrade case no longer reaches the network. signed-session.md and the ts-modules ARCHITECTURE describe when the offset is measured, forgotten and used.
A remembered offset can go stale without the wall clock diverging from the monotonic clock: NTP slews a corrected clock, and CLOCK_MONOTONIC slews with it, or the server's own clock changes. A continuation signed with that offset spends its GUID. While an offset is remembered for the host, a continuation now measures the server's Date before opening and fails unopened if it cannot. The RPC target keeps the divergence check, since it recovers by retrying. Tests: a server-clock change and a slewed device correction both redeem the continuation on one socket; an unanswered continuation without a remembered offset is not re-signed; a connection that fails after another stored a fresh offset leaves it in place.
Pushed c41793a..5e20ede (f6ed343 plus a docs-only master merge). |
helix-white
left a comment
There was a problem hiding this comment.
Approving 5e20ede82.
Both points from my previous review are fixed. The proposal (d084b6df7) was cherry-picked unchanged, and the two follow-up commits are correct:
a4de0a29bstops re-signing a dropped continuation.RpcContinuations::get_ws_handlerremoves the GUID beforeWebSocketHandler::on_upgraderunssecure.accept, which drops a failed admission without replying (rpc_continuations.rs:188-225,344-353). A second connection would only get 404. A measuredDatethat disagrees by more than 15 s also forgets the remembered offset. Theget(host) === cachedguard keeps an offset that another connection has just stored.f6ed343camakes a continuation measure before opening whenever an offset is remembered. This covers an NTP slew, which movesperformance.now()along with the wall clock, and a change to the server's own clock. The monotonic check catches neither. The RPC target keeps the cheaper divergence check, since it recovers by retrying.
I traced the retry path through cancellation: close() or an identity abort during the HEAD or before the second admit opens no further socket. The first socket's failure stays internal, so callers see one connection. An offset is stored only after an admission signed with it succeeds. StartOS's service worker does not serve this request from cache: / matches none of the asset or data groups in ngsw-config.json, and a HEAD is not a navigation, so it goes to the network with cache: 'no-store'. The branch merges cleanly with origin/master (316493c48). The admission paragraph in signed-session.md and the ts-modules ARCHITECTURE entry match the code.
Brief
Summary
-
A browser whose clock is more than 30 s off a clock-synchronized server can sign in, run first-time setup and use encrypted RPC on StartOS, StartWRT and StartTunnel. Until now, the server dropped such a signed hello without replying, and the UI reported only "Encrypted RPC transport failed". The failure exists only in the pending encrypted-RPC releases; shipped versions are not affected.
-
When an opened session socket fails before a complete answer record arrives, the browser sends one
HEAD /to the WebSocket's origin and readsDate. If the server's time differs by more than 15 s (half the server's tolerance) from the time the hello was signed with, the browser forgets any offset it remembered for that host. For the RPC target, it then signs one fresh hello with the server's time on a new socket. A dropped GUID continuation is never retried. -
The per-host offset lives in page memory. It is stored only after an admission signed with it succeeds, and is measured again before opening in two cases:
- before every GUID continuation while an offset is remembered;
- before an RPC connection once the device clock has jumped more than 15 s against the monotonic clock.
If that measurement fails, the connection fails without opening. A continuation's GUID stays unspent, and RPC's existing reconnect owner retries. A browser with no remembered offset whose admissions are answered sends no extra requests.
-
The server's ±30 s window and nonce cache are unchanged. The tolerance becomes the public
TIMESTAMP_TOLERANCE_SECS, and the client derives its 15 s threshold from the generatedSIGNATURE_PROFILE.timestampToleranceSecs.RequestSigner.signin start-core'sauthmodule takes an optional signing time. The SDK does not re-exportauth, so no published package API changes.
Implementation diff: +144 / −37 lines in 6 files (excludes lockfiles, tests, docs, release notes, and changelog). One added line is the generated signature-profile.ts, and about 30 of the additions in session-websocket.ts are the existing admission body moved into admit().
Approach
- The signing time goes through the existing
commitmentSigner→signTaggedRequestpath. Every signer is built there: the anonymous and enrolled signers here, and #4841's passkey identity, which also goes throughcommitmentSigner. - The server's time comes from the HTTP
Dateheader on the same origin, with no protocol or server change. The offset isDate + 500 ms + half the HEAD round trip − local time, becauseDatetruncates to the second. The round trip is timed withperformance.now().
Tradeoffs for the maintainer (none blocking)
- Signed HTTP keeps the device clock. Its proofs bind only host and body, so a proof dated from a forged
Dateon plain HTTP would later authorize any empty-body request to that host. As a result, a StartOS browser with a wrong clock can sign in and use RPC, but signed icon and package-document fetches (/registry/icons/…,/s9pk/…) still fail. Covering them would first need HTTP proofs that bind method and path, which is a wire-protocol change. - Hellos adopt a server-supplied time. On
http:///ws://, a network attacker can choose the time a hello is signed with. That gains nothing: a hello cannot complete a session without the ephemeral X25519 secret, and an offset is remembered only after the real server accepts it. Forcing the browser to forget an offset is weaker than dropping the connection, which such an attacker can already do. - Continuations cost one
HEADeach. Once a page has adopted an offset for a host, every GUID redemption there costs oneHEAD, even after the device clock is right again. No browser product redeems a GUID today. - Native clients still use the local clock.
start-cliand Rustsession::client::admitsign with it, so a skewed CLI still sees a dropped connection.
Neighbors
- #4841 (passkeys): I compared
git merge-treeresults against master and against this head. This PR adds conflicts only ingenerate_bindings.rs, the generatedsignature-profile.tsandshared-libs/ts-modules/ARCHITECTURE.md, all on adjacent lines. Keep both sides and regenerate the profile. Once both land, re-signing a hello asks a passkey user for a second touch. - #4904 gains no conflicts from this PR.
- #4940 was included only in the bench build.
Testing (recorded by the author; as reviewer I ran nothing)
npm run check:sharedpassed onf6ed343ca(154 tests). The new continuation cases fail onc41793ad7anda4de0a29b, and the concurrency case fails with an unconditional delete.- The transport tests cover:
- a re-sign that is then remembered;
- skew within tolerance (no retry);
- a socket that never opens and an answered failure (no
HEAD); - a re-sign that the server still drops (not remembered);
- stepped and slewed ±120 s device corrections;
- a server-clock change;
- an unreadable server clock leaving the GUID unspent;
- concurrent connections;
- close during measurement.
- Identity and start-core tests show that the proof commits the requested time and still verifies.
- The transport tests cover:
npm run build:deps && npm run checkpassed ona4de0a29b;f6ed343cachanged onlysession-websocket.tsinternals, its tests andsigned-session.mdsince. Four checks passed on an earlier head,5475696be: start-core jest (546),make start-core-test(1976),make -k generated-artifacts-checkandmake start-wrt-test. The author reports that only shared TypeScript, its tests and docs have changed since.- End to end on StartWRT only, on a K1 bench running this head merged with #4940:
- Fresh sign-in at +120 s and an enrolled tab at −120 s each worked with one
HEAD /. At 0 s, noHEADwas sent. - With the page clock corrected mid-session, the reconnect measured first and admitted on its first socket.
bench.sh smokepassed.
- Fresh sign-in at +120 s and an enrolled tab at −120 s each worked with one
- Not exercised end to end: StartOS and StartTunnel UIs with a skewed browser clock (they share the transport), and GUID continuations (no product page redeems one).
- CI on
5e20ede82: Prettier, formatting and lockfiles, SDK/runtime/script tests, changelog fragments and conflict markers passed. Still pending: start-core Tests & Man Pages, Generated Bindings & MCP Catalog, StartWRT Tests, rpc-toolkit/visit-rs/backup-fs Tests, and the product builds.
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
A browser whose clock is more than 30 s off cannot use encrypted RPC on a server whose clock is synchronized. The server drops the signed admission without replying, and the client reports only "Encrypted RPC transport failed". Signing in fails, open tabs reconnect forever, and an uninitialized StartWRT router shows the Root CA page instead of the password form, so first-time setup is impossible. 1.4.0's signed HTTP at least named the clock. This regression is pending in StartWRT 1.5.0, StartOS 0.4.3 and StartTunnel.
What changes
HEADto the server origin and reads itsDateheader. If that time differs from the one the hello was signed with by more than half the server's tolerance, the browser forgets any offset it remembered for that host and, for the RPC target, signs a fresh hello once, on a new connection, with the server's time.Datethe verifier disagrees with never outlives the connection that read it.RpcContinuations::get_ws_handlerremoves the GUID at the upgrade, before admission is validated (rpc_continuations.rs:344-353), so a second connection to it always gets 404. A continuation is therefore never re-signed, and while an offset is remembered for its host it measures the server's clock before opening, whether or not the device clock moved. That covers a correction the monotonic check cannot see: a clock slewed back by NTP, or a server whose own clock changed. The cost is oneHEADper redemption, only on a host whoseDatethis page has adopted (the entry stays for the life of the page, even once the device clock is right again). No browser product in this repo redeems a GUID today (StartWRT streams over the RPC session, StartTunnel's live database uses the typed stream, StartOS'sopenWebsocket$has no caller); this keepsRpcSocketService.openandopenSocketcorrect for the ones that do.HEAD, and a browser with no remembered offset never measures before opening. A browser with no remembered offset whose admissions are answered sends no extra requests.TIMESTAMP_TOLERANCE_SECSand reaches the client through the generatedSIGNATURE_PROFILE.RequestSigner.signtakes an optional signing time. Every signer goes throughcommitmentSigner, so the anonymous, enrolled and (with feat: passkey (WebAuthn) signing keys and StartOS passkey login #4841) passkey signers all honour it.What stays on the local clock
Dateheader on plain HTTP would later authorize any empty-body request to that host. StartOS's signed icon and package-document fetches (/registry/icons/…,/s9pk/…) therefore still need a correct device clock; the StartOS fragment claims sign-in, setup and RPC only. A replayed hello is harmless: it cannot complete a session without the ephemeral X25519 secret.start-cliand other Rust clients sign with the local clock, so a skewed CLI still sees a dropped connection. A follow-up could teachsession::client::admitthe same retry.Related open PRs
generate_bindings.rs, the generatedsignature-profile.tsandshared-libs/ts-modules/ARCHITECTURE.md(adjacent lines; keep both).lib/auth/signature.tsandsigned-session.mdmerge cleanly, and the mergedcommitmentSignerpassestimeto the passkey signer. Whichever lands second regenerates the profile; a passkey re-sign prompts for a second touch.signature.rs, which merges cleanly.Verification on f6ed343
Merged master 316493c (docs only) after verification, without conflicts.
npm run check:shared: PASS (154 tests). The new continuation cases fail on c41793a and on a4de0a2; the concurrency case fails when the guard is an unconditional delete.npm run build:deps && npm run checkon a4de0a2 (all web type checks, i18n, rpc-clients): PASS. f6ed343 changes onlysession-websocket.tsinternals, its tests andsigned-session.mdsince then.make start-core-test(1976),make -k generated-artifacts-checkandmake start-wrt-testpassed on 5475696be. Since then this branch changes only TypeScript inshared, its tests,shared-libs/ts-modules/ARCHITECTURE.mdandsigned-session.md, which is included as start-core module documentation.bench.sh deployedconfirmed), browser clock shifted in the page:HEAD /. 0 s sends none.HEAD /first, then admits on its first socket, and later pages load. The previous head's reconnect failed one socket, sent theHEAD, and admitted on a second socket.bench.sh smoke: PASS.