Skip to content

Commit 61acec1

Browse files
committed
Merge branch 'main' of github.com:cossistantcom/cossistant
2 parents 3b7fba3 + a1bfd19 commit 61acec1

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apps/api/src/lib/auth-validation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
type ApiKeyWithWebsiteAndOrganization,
44
getApiKeyByKey,
55
} from "@api/db/queries/api-keys";
6+
import { env } from "@api/env";
67
import {
8+
hashApiKey,
79
isValidPublicApiKeyFormat,
810
isValidSecretApiKeyFormat,
911
} from "@api/utils/api-keys";
@@ -313,7 +315,9 @@ export async function authenticateWithPrivateKey(
313315
throw new AuthValidationError(401, "Invalid private API key format");
314316
}
315317

316-
return await getApiKeyFromRedis(privateKey, db);
318+
// Private keys are HMAC-hashed before storage, so hash before lookup
319+
const hashedKey = hashApiKey(privateKey, env.API_KEY_SECRET);
320+
return await getApiKeyFromRedis(hashedKey, db);
317321
}
318322

319323
/**

0 commit comments

Comments
 (0)