Skip to content

fix(auth): compare configured API keys in constant time (#287) - #301

Merged
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
ghzhost:fix/constant-time-api-key-comparison-287
Sep 6, 2026
Merged

fix(auth): compare configured API keys in constant time (#287)#301
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
ghzhost:fix/constant-time-api-key-comparison-287

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #287

Summary of Changes

  • Replaced the direct string equality comparison (providedKey !== securityConfig.authApiKey) with a constant-time comparison helper safeCompareKey in src/common/http/api-key-auth.middleware.ts.
  • safeCompareKey converts strings to utf8 buffers, rejects unequal lengths immediately, and uses crypto.timingSafeEqual to prevent timing side-channel attacks on API key validation.
  • Extended tests/api-key-auth.test.ts with test cases verifying rejection of near-miss keys (same length, single character difference) and keys of different lengths (short/long).

Validation

  • Ran Vitest suite on tests/api-key-auth.test.ts: all 8 tests passing cleanly.
  • ESLint passed on modified files.

@David-patrick-chuks-02
David-patrick-chuks-02 merged commit 46f0fd4 into Lilly-Protocol:main Sep 6, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty: $75] Compare configured API keys in constant time

3 participants