Skip to content

Commit

Permalink
Auth cache key fix (#5949)
Browse files Browse the repository at this point in the history
  • Loading branch information
nischitpra authored Jan 14, 2025
1 parent 815f47c commit 23d8001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/service-utils/src/core/authorize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +42,9 @@ export async function authorize(
cacheOptions?: CacheOptions,
): Promise<AuthorizationResult> {
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 {
Expand Down
5 changes: 5 additions & 0 deletions packages/service-utils/src/core/authorize/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import crypto from "node:crypto";

export const hashKey = (str: string): string => {
return crypto.createHash("sha256").update(str, "utf8").digest("hex");
};

0 comments on commit 23d8001

Please sign in to comment.