fix(auth): T3 Connect tolerates a host clock a few seconds behind #19640
main fromrefs/pull/19640/head·merged by juliusmarminge View on GitHubT3 Connect rejects DPoP proofs signed more than five seconds ahead of the environment or relay clock. Accept proof timestamps up to 300 seconds in either direction and retain relay replay records through the proof’s final accepted second. Environment replay markers keep their existing one-day lifetime.
Original implementation by evolveperformance, retained in #19640 after independent assessment. Related reports: #5332 and #19830. This is limited to timestamp tolerance and matching replay retention.
Verification on head ecc93ac319:
- Tests reduced from 14 to 13 in the two existing shared/relay files. Exact ±300-second offsets pass; ±301 fail. After simulated expiry cleanup, proof reuse is rejected at elapsed 301 and 600.999 seconds, then fails its time window at 601 seconds. Both regressions fail with the relevant main production file restored independently.
- Six relevant suites pass, 22 tests total: shared DPoP, relay verify/consume and persistence, environment DPoP/replay markers, and auth HTTP. Scoped shared, relay, and server typechecks, targeted lint, and formatting pass.
- Real Linux loopback HTTP exercised production token-exchange and authenticated-session routes with isolated SQLite and disk replay markers. A signed timestamp 43 seconds ahead changes main’s
401/time_windowto a DPoP token exchange and session response of200; proof reuse remains401/replay. ±299 seconds succeeds, ±343 seconds fails.
main: iat_offset=43s exchange=401/time_window
head: iat_offset=43s exchange=200 session=200 authenticated=true replay=401/replay
head: iat_offset=299s exchange=200 session=200 authenticated=true replay=401/replay
head: iat_offset=-299s exchange=200 session=200 authenticated=true replay=401/replay
head: iat_offset=343s exchange=401/time_window
head: iat_offset=-343s exchange=401/time_window
Skew was simulated by signed timestamps; the host clock was unchanged. The main comparison substitutes only main’s shared verifier in otherwise identical auth routes. Actual relay PostgreSQL/maintenance-worker integration, Clerk accounts, macOS, Windows, iOS, Android, and Electron desktop were not verified. Screenshots do not apply to this nonvisual authentication change.
One full independent review round (Claude Opus 5.5 and GPT-6-Sol) found no code blockers. Historical GitHub findings were rechecked against this revision. Leave unmerged for human review of the authentication default change.
Tests: GPT-6-Astra; implementation: GPT-6.1-Sol; adversarial reviews: Claude Opus 5.5 and GPT-6-Sol. T3 Code using the Codex and Claude harnesses.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- infra/relay/src/auth/DpopProofs.ts line 136OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -129,4 +133,4 @@129133 thumbprint: result.thumbprint,130134 jti: result.jti,131135 iat: result.iat,132- expiresAt: DateTime.add(input.now, { minutes: 5 }),136+ expiresAt: DateTime.add(input.now, { seconds: DPOP_REPLAY_WINDOW_SECONDS }),
🟠 High
auth/DpopProofs.ts:136A proof can be accepted again after
pruneExpireddeletes its marker during the final second of the verification window. Verification floorsnow.epochMillisecondsand accepts the inclusive 300-second boundary, while this expiry gives the marker no extra second; retain it through the end of that last accepted second.🤖 Copy this AI Prompt to have your agent fix this:
In file @infra/relay/src/auth/DpopProofs.ts around line 136: A proof can be accepted again after `pruneExpired` deletes its marker during the final second of the verification window. Verification floors `now.epochMilliseconds` and accepts the inclusive 300-second boundary, while this expiry gives the marker no extra second; retain it through the end of that last accepted second.Confirmed. The time check floors to whole seconds and accepts
iatup to 300s old inclusive, so a proof passes until the end of secondiat + 300, whichnow + 600scould miss by up to a second. Fixed in 4458dcd: the marker now expires at(iat + 300 + 1) * 1000, derived from the proof itself, and the test asserts it.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Verified on the takeover head: relay expiry remains (iat + 300 + 1) * 1000, retaining the proof throughout its last accepted second. The focused regression prunes expired records and rejects replay at elapsed 600999 ms, then rejects the timestamp at 601000 ms. Both independent full-diff reviews found no blocker.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR changes default production DPoP authentication behavior across the environment server and relay, including the replay-retention window. An unresolved high-severity finding also identifies a possible replay at the final accepted time boundary, so human review is warranted.
Not approved because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 12 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9f88e2a6-6119-46f9-8538-9496f04293f3
📥 Commits
-
Reviewing files that changed from the base of the PR and between 4458dcdf699f92414625fab746a4c8eb56cbfe78 and e0b747462d3b333ebc6f25a119e45304eb8226af.
📒 Files selected for processing: 5
-
apps/server/src/auth/replayMarkers.tsinfra/relay/src/auth/DpopProofs.tsinfra/relay/src/auth/DpopProofs.verifyAndConsume.test.tspackages/shared/src/dpop.test.tspackages/shared/src/dpop.ts
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
03e20552-caa3-4d93-bd1d-9406b6512de6
📥 Commits
-
Reviewing files that changed from the base of the PR and between 348f217a853dd4a23d7fa4834dedb05f545c2075 and 4458dcdf699f92414625fab746a4c8eb56cbfe78.
📒 Files selected for processing: 5
-
apps/server/src/auth/replayMarkers.tsinfra/relay/src/auth/DpopProofs.tsinfra/relay/src/auth/DpopProofs.verifyAndConsume.test.tspackages/shared/src/dpop.test.tspackages/shared/src/dpop.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
The shared DPoP verifier now applies a symmetric 300-second limit to proof issue times. The relay calculates replay-record expiry from the proof issue time and that limit. Tests cover time-window boundaries and persisted expiry.
Changes: DPoP time-window alignment
Layer / File(s) Summary Define and verify the DPoP time window
packages/shared/src/dpop.ts,packages/shared/src/dpop.test.tsThe shared module exports a 300-second clock-skew limit. verifyDpopProofrejects proofs when the absolute difference between the verifier clock andiatexceeds the limit. Tests cover accepted offsets of ±200 seconds and rejected offsets of ±301 seconds.Apply the replay window to consumed proofs
infra/relay/src/auth/DpopProofs.ts,infra/relay/src/auth/DpopProofs.verifyAndConsume.test.ts,apps/server/src/auth/replayMarkers.tsThe relay sets replay-record expiry to iat + DPOP_MAX_CLOCK_SKEW_SECONDS + 1seconds. A test checks the persisted expiry for a proof issued 300 seconds in the future. A comment changes the documented approximate DPoP time-check window from 5 to 10 minutes.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
4458d-
This change lets DPoP proofs tolerate clock skew of up to 300 seconds in either direction and keeps replay protection for the full accepted window. No merge-blocking risk was identified.
Security architecture risk: 🔵 Low · up to
4458d-
The wider clock tolerance preserves independent credential checks and request binding. Relay replay retention is extended to cover future-dated proofs. No introduced authorization bypass was established, but deployed clock consistency and replay-state recovery guarantees remain unverified.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The affected authority is proof authentication for relay and environment operations. The proof timestamp does not select the authenticated user, bootstrap grant, environment, or granted scopes; those remain derived from independently checked credentials and authorization context.
Security Findings and Attack Paths
- inferred — An eligible, unconsumed future-dated proof can become usable up to 295 seconds earlier than before. An attacker still needs a valid signed proof and the independently required credential; altering its timestamp invalidates the signature. The wider freshness allowance did not establish an identity or scope bypass, and relay retention now covers the expanded same-clock acceptance window.
Trust Boundaries and Controls
- observed — Protected callers retain independently authenticated token context, applicable scope checks, expected proof-key thumbprints, and access-token hash binding. Shared verification retains method, URL, signature, and freshness checks.
- observed — Not every proof is already token-bound: token-establishment endpoints verify a proof without an expected access token or existing thumbprint. Relay issuance separately verifies the Clerk credential, while environment issuance consumes a bootstrap credential and limits requested scopes to its grant. This distinction predates the PR.
Resilience and Maintainability Implications
- observed — Relay reservation uses an atomic insert protected by the thumbprint/JTI primary key and rejects persistence failures. Environment reservation uses exclusive file creation, writes and syncs the marker before returning success, and maps duplicate creation to replay rejection. A reservation can remain consumed after later failure or interruption; the inspected paths do not remove it to authorize a retry.
- inferred — Single-use enforcement still depends on replay state surviving recovery and on cleanup not running ahead of a verifier that can accept the proof. Independent clock divergence or clock rollback can violate that assumption in both versions. The base already allowed proofs to outlive fixed relay retention; the new formula corrects the nominal same-clock gap. Live clock bounds and database restore guarantees remain unknown, rather than verified new vulnerabilities.
-
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the authentication fix and the clock-skew tolerance change. Description check The description explains the problem, the implementation, scope, linked reports, focused verification, observed results, and unverified environments. It does not use the template headings, but it prov… Full details: Description check
-
Explanation
The description explains the problem, the implementation, scope, linked reports, focused verification, observed results, and unverified environments. It does not use the template headings, but it provides the required information in a complete form.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge assignedjuliusmarminge
Taking over this one. I’m retaining @evolveperformance’s focused fix and original commits, merging main, tightening the skew/replay boundary tests, and publishing headless verification with independent reviews. I will leave it unmerged for authentication review.
CI follow-up on ecc93ac319: all auth/relay suites, lint, build/typecheck, server shards, web and release smoke passed. The generic Test job failed in main’s unchanged SSH test at the immediate SIGKILL-to-ps assertion (expected zombie Z, observed running R). The test assumes the signal has already taken effect; this PR does not change SSH code. Retrying failed jobs once on the same head; no validation is disabled. Authentication approval remains for a human.
Takeover complete at ecc93ac319. Current-head build, lint, and test jobs pass; skipped jobs remain skipped. No unresolved inline findings. One full independent review round with Claude Opus 5.5 and GPT-6-Sol found no code blockers. The PR body contains the current focused tests, headless proof, original-author credit, and platform limits.
The unchanged-head rerun passed after the existing SSH zombie-process fixture race. The replay-boundary finding is verified and resolved; human approval of the authentication defaults remains required. Leaving unmerged.
juliusmarminge merged this475e019
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed