Skip to content

fix(web): re-sign a dropped session admission with the server clock - #4939

Open
Dominion5254 wants to merge 5 commits into
masterfrom
fix/session-clock-skew
Open

Dominion5254 wants to merge 5 commits into
masterfrom
fix/session-clock-skew

Conversation

@Dominion5254

@Dominion5254 Dominion5254 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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

  • When an opened session socket fails before a complete answer record arrives (the server dropped the hello, the handshake timed out, or the reply was malformed), the browser sends one HEAD to the server origin and reads its Date header. 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.
  • The offset is remembered for that host, with the wall-clock and monotonic times it was measured at, only after an admission signed with it succeeds. A retry the server still drops is not remembered, so a Date the verifier disagrees with never outlives the connection that read it.
  • When the device clock has moved more than 15 s against the monotonic clock since that measurement, for example because the clock was stepped back to the right time, the browser measures again before opening the next socket. If that measurement fails, the connection fails without opening.
  • GUID continuations are never re-signed. RpcContinuations::get_ws_handler removes 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 one HEAD per redemption, only on a host whose Date this 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's openWebsocket$ has no caller); this keeps RpcSocketService.open and openSocket correct for the ones that do.
  • A socket that never opens, or a hello the server answers, never triggers the 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.
  • 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.
  • RequestSigner.sign takes an optional signing time. Every signer goes through commitmentSigner, 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

  • Signed HTTP. Its proofs bind only the host and body, not the method or path. A proof 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 (/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.
  • Native clients. start-cli and other Rust clients sign with the local clock, so a skewed CLI still sees a dropped connection. A follow-up could teach session::client::admit the same retry.

Related open PRs

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 check on a4de0a2 (all web type checks, i18n, rpc-clients): PASS. f6ed343 changes only session-websocket.ts internals, its tests and signed-session.md since then.
  • Prettier on every changed file: PASS. The changelog fragments are unchanged.
  • start-core jest (546), make start-core-test (1976), make -k generated-artifacts-check and make start-wrt-test passed on 5475696be. Since then this branch changes only TypeScript in shared, its tests, shared-libs/ts-modules/ARCHITECTURE.md and signed-session.md, which is included as start-core module documentation.
  • K1 bench, this head merged with fix(start-wrt): hand an outlasted update wait to the reconnect indicator #4940 and deployed (bench.sh deployed confirmed), browser clock shifted in the page:
    • Fresh sign-in at +120 s, an enrolled tab at −120 s: both work, each with one HEAD /. 0 s sends none.
    • Signed in at +120 s or −120 s, then the page's clock set back to the right time without a reload and the RPC socket dropped: the reconnect sends one HEAD / first, then admits on its first socket, and later pages load. The previous head's reconnect failed one socket, sent the HEAD, and admitted on a second socket.
    • bench.sh smoke: PASS.
    • No StartWRT, StartOS or StartTunnel page redeems a GUID continuation, so the continuation cases are covered by the transport tests only.

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 helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_HEAD

If 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-white and others added 4 commits November 25, 2026 10:06
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.
@Dominion5254

Copy link
Copy Markdown
Member Author
  • Stale offset spending a single-use continuation: adopted (d084b6d, cherry-picked unchanged). Two additions:
    • A continuation is never re-signed on a second connection, since its GUID is spent at upgrade (a4de0a2).
    • While an offset is remembered, a continuation measures Date before opening, whatever the clocks did (f6ed343). A clock slewed back by NTP moves performance.now() with it, and a server-side clock change moves neither, so the drift check alone would still spend the GUID in those cases. Tests cover both, plus an unreadable clock leaving the GUID unspent.
  • The "corrected device clock" test moving the server's Date: agreed. It is renamed "follows a corrected server clock", and the new tests move Date.now().
  • Benched on the K1 with the page's clock corrected mid-session. The reconnect now measures first and admits on its first socket.

Pushed c41793a..5e20ede (f6ed343 plus a docs-only master merge).

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • a4de0a29b stops re-signing a dropped continuation. RpcContinuations::get_ws_handler removes the GUID before WebSocketHandler::on_upgrade runs secure.accept, which drops a failed admission without replying (rpc_continuations.rs:188-225, 344-353). A second connection would only get 404. A measured Date that disagrees by more than 15 s also forgets the remembered offset. The get(host) === cached guard keeps an offset that another connection has just stored.
  • f6ed343ca makes a continuation measure before opening whenever an offset is remembered. This covers an NTP slew, which moves performance.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 reads Date. 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 generated SIGNATURE_PROFILE.timestampToleranceSecs. RequestSigner.sign in start-core's auth module takes an optional signing time. The SDK does not re-export auth, 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 → signTaggedRequest path. Every signer is built there: the anonymous and enrolled signers here, and #4841's passkey identity, which also goes through commitmentSigner.
  • The server's time comes from the HTTP Date header on the same origin, with no protocol or server change. The offset is Date + 500 ms + half the HEAD round trip − local time, because Date truncates to the second. The round trip is timed with performance.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 Date on 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 HEAD each. Once a page has adopted an offset for a host, every GUID redemption there costs one HEAD, even after the device clock is right again. No browser product redeems a GUID today.
  • Native clients still use the local clock. start-cli and Rust session::client::admit sign with it, so a skewed CLI still sees a dropped connection.

Neighbors

  • #4841 (passkeys): I compared git merge-tree results against master and against this head. This PR adds conflicts only in generate_bindings.rs, the generated signature-profile.ts and shared-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:shared passed on f6ed343ca (154 tests). The new continuation cases fail on c41793ad7 and a4de0a29b, 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.
  • npm run build:deps && npm run check passed on a4de0a29b; f6ed343ca changed only session-websocket.ts internals, its tests and signed-session.md since. Four checks passed on an earlier head, 5475696be: start-core jest (546), make start-core-test (1976), make -k generated-artifacts-check and make 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, no HEAD was sent.
    • With the page clock corrected mid-session, the reconnect measured first and admitted on its first socket.
    • bench.sh smoke passed.
  • 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants