Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: keep JWKS URL credentials out of the JWT auth error log

Claudefc26d00e7fbb
diff --git a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
index 38d14a2ae2..b32b3191a6 100644
--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts
@@ -20,7 +20,7 @@ import { getConfig } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto";
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";
-import { logger } from "@app/lib/logger";
+import { logger, sanitizeUrlForLog } from "@app/lib/logger";
import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { RequestContextKey } from "@app/lib/request-context/request-context-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
@@ -181,8 +181,17 @@ export const identityJwtAuthServiceFactory = ({
}
// The fetch error can carry network details or the endpoint's response body, and this
// route is unauthenticated, so the caller gets a fixed message and the detail is logged.
+ // The JWKS URL can carry credentials in its path or query, so it is logged sanitized and
+ // the error as name, message and code rather than an object that may hold the request.
logger.error(
- { error, identityId: identity.id, jwksUrl: identityJwtAuth.jwksUrl, kid },
+ {
+ errorName: error instanceof Error ? error.name : undefined,
+ errorMessage: error instanceof Error ? error.message : String(error),
+ errorCode: (error as NodeJS.ErrnoException)?.code,
+ identityId: identity.id,
+ jwksUrl: sanitizeUrlForLog(identityJwtAuth.jwksUrl),
+ kid
+ },
`JWT auth signing key retrieval failed [identityId=${identity.id}] [kid=${kid}]`
);
throw new UnauthorizedError({