You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use timingSafeEqual for ADMIN_API_KEY comparison #4209
server/src/middleware/auth.ts:644-652 (hasValidAdminApiKey) compares the request-supplied admin API key to process.env.ADMIN_API_KEY using ===. Surfaced by security-reviewer in PR #4207.
Risk
Low. The key is high-entropy and remote timing-attack signal across the public internet is very weak. But:
It's a one-line hardening.
Removes a category of question for any future security review.
Proposal
Swap the === for crypto.timingSafeEqual over equal-length Buffers. Length-mismatch handling needs to compare a dummy buffer of the correct length to keep the comparison constant-time.
```ts
import { timingSafeEqual } from 'node:crypto';
function constantTimeEqual(a: string, b: string): boolean {
const aBuf = Buffer.from(a);
const bBuf = Buffer.from(b);
if (aBuf.length !== bBuf.length) {
// Compare against a same-length dummy to keep the timing constant.
timingSafeEqual(aBuf, Buffer.alloc(aBuf.length));
return false;
}
return timingSafeEqual(aBuf, bBuf);
}
```
security-reviewer: Implementation correct — constantTimeEqual with dummy-call-on-length-mismatch matches the existing verifyDevSession pattern (line 547); timingSafeEqual is already imported at line 2 so the diff is minimal. One suggestion: use Buffer.from(a, 'latin1') instead of the default UTF-8 to make the ASCII-only assumption on ADMIN_API_KEY explicit rather than implicit.
My take: Security-sensitive bucket means no auto-PR. The proposal is clean and self-contained; @bokelley, your call to greenlight — proceed as-is or fold in the 'latin1' encoding suggestion.
Activity
bokelley commentedon May 8, 2026
Triage
Classification: Bug (security hardening)
Bucket(s): security-sensitive
Status: ready-for-human
What the experts said:
constantTimeEqualwith dummy-call-on-length-mismatch matches the existingverifyDevSessionpattern (line 547);timingSafeEqualis already imported at line 2 so the diff is minimal. One suggestion: useBuffer.from(a, 'latin1')instead of the default UTF-8 to make the ASCII-only assumption on ADMIN_API_KEY explicit rather than implicit.My take: Security-sensitive bucket means no auto-PR. The proposal is clean and self-contained; @bokelley, your call to greenlight — proceed as-is or fold in the
'latin1'encoding suggestion.Triaged by Claude Code. Session: https://claude.ai/code/cse_01VsmRH2QwA5denNndQGKHAy
Generated by Claude Code
fix(test): stub @workos-inc/node in auth-constant-time-equal test (#4209
fix(test): stub @workos-inc/node in auth-constant-time-equal test (#4209
fix(security): use timingSafeEqual for ADMIN_API_KEY comparison (adco…