fix(auth): use timing-safe compares for sidecar token checks#3461
Merged
BunsDev merged 2 commits intoJul 19, 2026
Conversation
added 2 commits
July 19, 2026 03:31
…origin Use timingSafeEqualString for COVEN_CAVE_AUTH_TOKEN checks so REST proxy and isLocalOrigin match the PTY upgrade path's constant-time compares. Signed-off-by: Tyler Thompson <eijastnt@TNT-3.local>
Prefer early returns so TypeScript proves string types without as-casts, matching server.ts style. Signed-off-by: Tyler Thompson <eijastnt@TNT-3.local>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens sidecar token equality checks by switching REST proxy and isLocalOrigin comparisons to timingSafeEqualString, aligning token verification behavior with other constant-time auth checks in the codebase.
Changes:
- Added a shared
sidecarTokenMatches()helper insrc/proxy.tsand used it for both header-CSRF trust and sidecar authentication comparisons. - Updated
isLocalOriginto usetimingSafeEqualStringfor packaged sidecar header checks. - Adjusted tests to assert the timing-safe matcher is used in both locations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/proxy.ts | Replaces direct === token checks with a shared sidecarTokenMatches() helper that uses timingSafeEqualString. |
| src/middleware.test.ts | Updates source-level assertions to ensure the proxy uses the timing-safe matcher and shared helper. |
| src/lib/server/local-origin.ts | Switches sidecar header validation to timingSafeEqualString for packaged/local-route gating. |
| src/lib/server/local-origin.test.ts | Adds a source-level assertion that the timing-safe compare is present in isLocalOrigin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Use
timingSafeEqualStringforCOVEN_CAVE_AUTH_TOKENchecks in the REST proxy andisLocalOrigin, matching the PTY upgrade path's constant-time compares.Why
Sidecar token equality used plain
===/!==while mobile and PTY auth already use timing-safe compares. This keeps auth checks consistent across surfaces and slightly harder to probe by timing.Changes
src/proxy.ts: sharedsidecarTokenMatcheshelper (early returns +timingSafeEqualString) for header CSRF trust and sidecar authenticationsrc/lib/server/local-origin.ts: timing-safe packaged sidecar header checkmiddleware.test.tsandlocal-origin.test.tsVerification
Codex review on the fork PR: no major issues (
chatgpt-codex-connector[bot]ona35fa211fa).Risk + rollout notes
Low risk, behavior-preserving. Token accept/reject outcomes are unchanged for correct and incorrect secrets. No migration or release-note requirement.