From a454e6610d021a2398ef6ba5a971d749babfa6f9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 20:55:29 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=20Fix=20timing=20attack=20vulnerability=20in=20auth=20token=20?= =?UTF-8?q?validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/sentinel.md | 4 ++++ src/cli/commands/serve.ts | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 .jules/sentinel.md diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 00000000..02434c99 --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2024-07-25 - Timing Attack Fast Path in Token Comparison +**Vulnerability:** The authentication validation used a short-circuit buffer length check (`tokenBuffer.length === authTokenBuffer.length`) before calling `crypto.timingSafeEqual()`. +**Learning:** Checking the length of secrets before a constant-time comparison creates a fast path that leaks the length of the expected secret via timing differences, rendering the constant-time check partially ineffective. +**Prevention:** Always hash both secrets to a fixed length (e.g., using `crypto.createHash('sha256')`) before comparison to ensure true constant-time evaluation and avoid short-circuiting logic based on length. \ No newline at end of file diff --git a/src/cli/commands/serve.ts b/src/cli/commands/serve.ts index 2c37293e..e20ec168 100644 --- a/src/cli/commands/serve.ts +++ b/src/cli/commands/serve.ts @@ -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 authTokenHash = crypto.createHash('sha256').update(authToken).digest(); + if (crypto.timingSafeEqual(tokenHash, authTokenHash)) { isAuthenticated = true; break; }