From 4bb013494e496e03dfd2acb037a4760cf982a345 Mon Sep 17 00:00:00 2001 From: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:47:46 -0300 Subject: [PATCH] test(security): compare the Bedrock cache key with the fingerprint helper Hashing the test API key inline opened a CodeQL insufficient-password-hash alert in the test; compare against opaqueTokenFingerprint() instead. --- tests/unit/bedrock-client-reuse.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/unit/bedrock-client-reuse.test.ts b/tests/unit/bedrock-client-reuse.test.ts index 2e9798041f4..6ee9ec9d989 100644 --- a/tests/unit/bedrock-client-reuse.test.ts +++ b/tests/unit/bedrock-client-reuse.test.ts @@ -3,11 +3,11 @@ import assert from "node:assert/strict"; import { mkdtempSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { createHash } from "node:crypto"; process.env.DATA_DIR = mkdtempSync(join(tmpdir(), "or9r-bedrock-cache-")); const { BedrockExecutor } = await import("../../open-sse/executors/bedrock.ts"); +const { opaqueTokenFingerprint } = await import("../../open-sse/utils/opaqueTokenFingerprint.ts"); function credentials(apiKey = "key-a", region = "eu-west-2", customUserAgent?: string) { return { @@ -62,7 +62,10 @@ test("the client cache key holds a fingerprint of the API key, never the key its const keys = [...(executor as unknown as { clients: Map }).clients.keys()]; assert.equal(keys.length, 1); assert.ok(!keys[0].includes(apiKey), "the raw API key must not be part of the cache key"); - // Same digest as before the helper, so the cache keeps its existing entries' meaning. - const sha256 = createHash("sha256").update(apiKey).digest("hex"); - assert.ok(keys[0].includes(sha256), "the cache key carries the sha256 fingerprint"); + // The helper's plain mode is the historical sha256 hex (covered by its own tests), so the + // cache keeps the meaning of its existing entries. + assert.ok( + keys[0].includes(opaqueTokenFingerprint(apiKey)), + "the cache key carries the key fingerprint" + ); });