From 54449ee1359cc8534739c8f7819c43d74b4dcba7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:53:22 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL/H?= =?UTF-8?q?IGH]=20Fix=20timing=20attack=20vulnerability=20in=20auth=20toke?= =?UTF-8?q?n=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/sentinel.md | 4 ++++ src/cli/commands/serve.ts | 7 +++---- tests/integration/prompt_templates.test.ts | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .jules/sentinel.md diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 00000000..e5839898 --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2025-02-23 - Timing attack vulnerability in Auth Token validation +**Vulnerability:** The token length was compared before performing the comparison with `timingSafeEqual`, which leaks the secret token length via an early return timing difference. +**Learning:** `timingSafeEqual` throws an error if buffer lengths are different, which leads to developers creating a short-circuit fast path that leaks the secret's length. +**Prevention:** Instead of checking buffer lengths, always hash both the user input and the stored secret using SHA-256 (or another secure hash algorithm) before using `timingSafeEqual`. This ensures that both values are a fixed length, avoiding timing differences. \ No newline at end of file diff --git a/src/cli/commands/serve.ts b/src/cli/commands/serve.ts index 2c37293e..891cf2e7 100644 --- a/src/cli/commands/serve.ts +++ b/src/cli/commands/serve.ts @@ -349,10 +349,9 @@ export async function handleServeCommand(_options: unknown, command: Command) { const tokenBuffer = Buffer.from(token); for (const authToken of authTokens) { const authTokenBuffer = Buffer.from(authToken); - if ( - tokenBuffer.length === authTokenBuffer.length && - crypto.timingSafeEqual(tokenBuffer, authTokenBuffer) - ) { + const hash1 = crypto.createHash('sha256').update(tokenBuffer).digest(); + const hash2 = crypto.createHash('sha256').update(authTokenBuffer).digest(); + if (crypto.timingSafeEqual(hash1, hash2)) { isAuthenticated = true; break; } diff --git a/tests/integration/prompt_templates.test.ts b/tests/integration/prompt_templates.test.ts index 21905259..f1360d78 100644 --- a/tests/integration/prompt_templates.test.ts +++ b/tests/integration/prompt_templates.test.ts @@ -36,7 +36,9 @@ describe('Prompt templates', () => { expect(planSystem).toContain('You are SalmonLoop.'); expect(patchSystem).toContain('You are PATCH, a phase-native diff compiler.'); - expect(autopilotSystem).toContain('You are a senior software engineer running in "autopilot" mode.'); + expect(autopilotSystem).toContain( + 'You are a senior software engineer running in "autopilot" mode.', + ); expect(answerSystem).toContain('You are a coding assistant in "answer" mode.'); expect(researchSystem).toContain('You are a research assistant.'); });