diff --git a/packages/service-utils/src/core/authorize/index.ts b/packages/service-utils/src/core/authorize/index.ts index f8b6fd68958..0cdcb77e0cd 100644 --- a/packages/service-utils/src/core/authorize/index.ts +++ b/packages/service-utils/src/core/authorize/index.ts @@ -6,6 +6,7 @@ import { import { authorizeClient } from "./client.js"; import { authorizeService } from "./service.js"; import type { AuthorizationResult } from "./types.js"; +import { hashKey } from "./utils.js"; export type AuthorizationInput = { secretKey: string | null; @@ -41,7 +42,9 @@ export async function authorize( cacheOptions?: CacheOptions, ): Promise { let teamAndProjectResponse: TeamAndProjectResponse | null = null; - const cacheKey = `key_v2_${authData.clientId ?? authData.secretKeyHash ?? authData.hashedJWT}`; + const cacheKey = hashKey( + `key_v2_:${authData.secretKeyHash}:${authData.hashedJWT}:${authData.clientId}`, + ); // TODO if we have cache options we want to check the cache first if (cacheOptions) { try { diff --git a/packages/service-utils/src/core/authorize/utils.ts b/packages/service-utils/src/core/authorize/utils.ts new file mode 100644 index 00000000000..da866ed3b70 --- /dev/null +++ b/packages/service-utils/src/core/authorize/utils.ts @@ -0,0 +1,5 @@ +import crypto from "node:crypto"; + +export const hashKey = (str: string): string => { + return crypto.createHash("sha256").update(str, "utf8").digest("hex"); +};