Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(desktop): the renderer's bootstrap token rotates every 12 hours #16275

Mergedjuliusmarmingemerged 3 commits intot3/desktop-bootstrap-1-stop-retrying fromrefs/pull/16275/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Stack 2/2, on top of #16273.

Problem

The desktop handed the renderer one admin-scoped bootstrap token for its whole lifetime, and backends accepted it for 24h. A leaked token could mint sessions for a day, and once it expired a desktop left running could not connect a backend that restarted, since it had no valid token to hand out.

Fix

  • The desktop generates a 32-byte secret per desktop process and sends it to every backend in the bootstrap envelope (desktopBootstrapSecret, over fd3/stdin like the token). The renderer never sees it.
  • Both sides derive the token for the current 12-hour window with HMAC-SHA256 (@t3tools/shared/desktopBootstrapToken). A backend accepts the current and previous window's token, compared in constant time.
  • getLocalEnvironmentBootstraps always hands the renderer the current window's token, so any token works for at most 24 hours and a running desktop never ends up holding an expired one.
  • A backend launched with a secret no longer accepts the fixed launch token on its own. Backends launched by an older desktop, without the secret, keep the previous fixed-token behaviour. Every backend the desktop launches (primary, staged or mounted WSL runtime) is the server build bundled with that desktop, so a new desktop never hands rotating tokens to an older server.
  • The desktop main process (DesktopLocalEnvironmentAuth) also derives the current window's token, so its first exchange works even if it runs long after launch (e.g. after a suspend).

An earlier version of this stack also added a session-renewal endpoint (#16274). Adversarial review showed it let a stolen desktop session renew itself forever, and rotation alone keeps a long-running desktop connected, so it was dropped.

Tests: shared desktopBootstrapToken.test.ts (rotation and window acceptance), server PairingGrantStore.test.ts (accepts current-window tokens after 5 days, rejects stale ones and the bare launch token), desktop DesktopBackendConfiguration.test.ts, window.test.ts and DesktopLocalEnvironmentAuth.test.ts (secret in the envelope, current token over IPC, delayed first exchange uses the current token).

Not verified in a running desktop with WSL; that needs a Windows machine.

Claude Opus 5.5 via Claude Code

🤖 Generated with Claude Code

    1. juliusmarminge added labelsmacroscope-review

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR changes the default desktop authentication path by introducing shared secrets and rotating administrative bootstrap tokens across the renderer, desktop backends, WSL, and server auth. The authentication-sensitive runtime impact and unresolved error-handling review concern warrant human review.

      Notes:

      • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

      No code changes detected at 480a2cb. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.9 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.2 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: 480a2cb · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 1686a7c2-54f0-4434-b232-cd1155068ba3
      📥 Commits

      Reviewing files that changed from the base of the PR and between 4858df14af1d41855e4be12321be5e5da91522af and 90e4d10d8a8c3486c037d32408cf520e4a029cf1.

      📒 Files selected for processing (3)
      • apps/desktop/src/backend/DesktopBackendPool.test.ts
      • apps/desktop/src/wsl/DesktopWslBackend.test.ts
      • apps/server/src/auth/PairingGrantStore.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.


      📝 Walkthrough

      Walkthrough

      Desktop backends now receive a shared bootstrap secret and derive time-windowed tokens from it. The desktop publishes the current token in bootstrap results and uses it for local-environment authentication. The server validates rotating tokens and issues desktop-bootstrap grants.

      Changes

      Desktop bootstrap token rotation

      Layer / File(s)Summary
      Token contract and derivation
      packages/contracts/src/desktopBootstrap.ts, packages/shared/src/desktopBootstrapToken.ts, packages/shared/src/desktopBootstrapToken.test.ts, packages/shared/package.json
      The bootstrap contract adds an optional secret. Shared utilities derive HMAC-SHA256 tokens for 12-hour windows and validate tokens from the previous, current, or next window. Tests cover rotation, validity boundaries, clock skew, and invalid inputs.
      Desktop secret and token distribution
      apps/desktop/src/backend/DesktopBackendConfiguration.ts, apps/desktop/src/ipc/methods/window.ts, apps/desktop/src/backend/DesktopBackendConfiguration.test.ts, apps/desktop/src/ipc/methods/window.test.ts, apps/desktop/src/backend/DesktopBackendPool.test.ts, apps/desktop/src/wsl/DesktopWslBackend.test.ts
      The desktop caches a 32-byte secret and passes it to Windows and WSL bootstrap payloads. It derives the current token and uses it in bootstrap results when the backend has a secret. Tests cover token derivation and bootstrap results, and update configuration stubs.
      Desktop local-environment authentication
      apps/desktop/src/backend/DesktopLocalEnvironmentAuth.ts, apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts
      When a backend has a bootstrap secret, local-environment authentication derives the exchange credential from the secret and current time. Otherwise, it uses the configured launch token. The test checks the submitted token after the launch token window has elapsed.
      Server secret propagation and token validation
      apps/server/src/config.ts, apps/server/src/cli/config.ts, apps/server/src/auth/PairingGrantStore.ts, apps/server/src/auth/PairingGrantStore.test.ts
      Server configuration carries the optional secret. PairingGrantStore validates rotating tokens and issues a desktop-bootstrap grant. Tests cover acceptance of a current-window token and rejection of an older token and the configured launch token.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Feature

      Suggested reviewers: t3dotgg

      Sequence Diagram(s)

      sequenceDiagram
        participant DesktopBackendConfiguration
        participant currentDesktopBootstrapToken
        participant getLocalEnvironmentBootstraps
        participant Renderer
        DesktopBackendConfiguration->>currentDesktopBootstrapToken: derive token from secret and current time
        getLocalEnvironmentBootstraps->>DesktopBackendConfiguration: request current token
        DesktopBackendConfiguration-->>getLocalEnvironmentBootstraps: return current token
        getLocalEnvironmentBootstraps-->>Renderer: include token in bootstrap result

      Merge Risk: ⚪ Minimal · up to 90e4d

      The reviewed changes show no actionable issue preventing merge after normal checks.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 15 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the main change: 12-hour rotation of the desktop renderer’s bootstrap token.
      Description check✅ PassedThe description explains the problem, the fix across components, and the focused tests and verification limits. It gives stack context, but does not include a distinct Scope and approval section or st…
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches 💡 2
      📝 Generate docstrings 💡
      • Commit to this branch
      • Create a new PR
      🛠️ Fix failing CI checks 💡
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    6. juliusmarminge merged this5afe18e

    7. juliusmarminge closed this

Sign in to join this conversation.