Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2026-07-22 - Fix Timing Attack Vulnerability in Token Comparison
**Vulnerability:** Checking buffer lengths before calling `crypto.timingSafeEqual` creates a short-circuit fast path that leaks the secret's length via timing differences.
**Learning:** `crypto.timingSafeEqual` throws an error if buffers have different lengths, so checking lengths first seems necessary, but it introduces a timing attack vulnerability.
**Prevention:** Always hash both secrets to a fixed length (e.g., using `crypto.createHash('sha256')`) before comparison to ensure true constant-time evaluation.
9 changes: 3 additions & 6 deletions src/cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,10 @@ export async function handleServeCommand(_options: unknown, command: Command) {

let isAuthenticated = false;
if (scheme?.toLowerCase() === 'bearer' && token) {
const tokenBuffer = Buffer.from(token);
const tokenHash = crypto.createHash('sha256').update(token).digest();
for (const authToken of authTokens) {
const authTokenBuffer = Buffer.from(authToken);
if (
tokenBuffer.length === authTokenBuffer.length &&
crypto.timingSafeEqual(tokenBuffer, authTokenBuffer)
) {
const expectedHash = crypto.createHash('sha256').update(authToken).digest();
if (crypto.timingSafeEqual(tokenHash, expectedHash)) {
isAuthenticated = true;
break;
}
Expand Down
Loading