Skip to content

Commit 23d8001

Browse files
authored
Auth cache key fix (#5949)
1 parent 815f47c commit 23d8001

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/service-utils/src/core/authorize/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { authorizeClient } from "./client.js";
77
import { authorizeService } from "./service.js";
88
import type { AuthorizationResult } from "./types.js";
9+
import { hashKey } from "./utils.js";
910

1011
export type AuthorizationInput = {
1112
secretKey: string | null;
@@ -41,7 +42,9 @@ export async function authorize(
4142
cacheOptions?: CacheOptions,
4243
): Promise<AuthorizationResult> {
4344
let teamAndProjectResponse: TeamAndProjectResponse | null = null;
44-
const cacheKey = `key_v2_${authData.clientId ?? authData.secretKeyHash ?? authData.hashedJWT}`;
45+
const cacheKey = hashKey(
46+
`key_v2_:${authData.secretKeyHash}:${authData.hashedJWT}:${authData.clientId}`,
47+
);
4548
// TODO if we have cache options we want to check the cache first
4649
if (cacheOptions) {
4750
try {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import crypto from "node:crypto";
2+
3+
export const hashKey = (str: string): string => {
4+
return crypto.createHash("sha256").update(str, "utf8").digest("hex");
5+
};

0 commit comments

Comments
 (0)