Skip to content

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

fix greptile reviews

Thiago Araujo da Silva0535abb90b7b
diff --git a/backend/src/server/routes/v1/oauth-router.ts b/backend/src/server/routes/v1/oauth-router.ts
index 75023ade2c..329bca51cf 100644
--- a/backend/src/server/routes/v1/oauth-router.ts
+++ b/backend/src/server/routes/v1/oauth-router.ts
@@ -391,6 +391,7 @@ export const registerOAuthRouter = async (server: FastifyZodProvider) => {
const clientSecret = basicAuth?.clientSecret ?? req.body.client_secret;
void res.header("Cache-Control", "no-store");
+ void res.header("Pragma", "no-cache");
if (req.body.grant_type === "authorization_code") {
if (!req.body.code) throw new BadRequestError({ message: "Missing authorization code" });
diff --git a/backend/src/services/oauth-client/oauth-client-fns.test.ts b/backend/src/services/oauth-client/oauth-client-fns.test.ts
index 217b776ed8..cec4f2ea09 100644
--- a/backend/src/services/oauth-client/oauth-client-fns.test.ts
+++ b/backend/src/services/oauth-client/oauth-client-fns.test.ts
@@ -78,6 +78,7 @@ describe("isAllowedRedirectUri", () => {
test("rejects non-http(s) schemes", () => {
expect(isAllowedRedirectUri("ftp://localhost/callback")).toBe(false);
+ // eslint-disable-next-line no-script-url
expect(isAllowedRedirectUri("javascript:alert(1)")).toBe(false);
});
diff --git a/backend/src/services/oauth-client/oauth-client-fns.ts b/backend/src/services/oauth-client/oauth-client-fns.ts
index acb0400df8..bcf44ca230 100644
--- a/backend/src/services/oauth-client/oauth-client-fns.ts
+++ b/backend/src/services/oauth-client/oauth-client-fns.ts
@@ -28,6 +28,11 @@ export const parseBasicAuthHeader = (
}
};
+// RFC 7636 §4.1: the code_verifier is 43-128 characters from the unreserved set
+// [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~". Enforcing this guarantees the verifier
+// carries enough entropy that the challenge cannot be brute-forced against the token endpoint.
+export const PKCE_CODE_VERIFIER_REGEX = /^[A-Za-z0-9\-._~]{43,128}$/;
+
export const computePkceChallenge = (codeVerifier: string) => {
const sha256 = crypto.createHash("sha256").update(codeVerifier).digest();
return Buffer.from(sha256).toString("base64url");
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.ts
index 789c4196a0..e5a9461821 100644
--- a/backend/src/services/oauth-client/oauth-client-service.ts
+++ b/backend/src/services/oauth-client/oauth-client-service.ts
@@ -15,7 +15,7 @@ import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-se
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TOauthClientDALFactory } from "./oauth-client-dal";
-import { computePkceChallenge, isRegisteredRedirectUri } from "./oauth-client-fns";
+import { computePkceChallenge, isRegisteredRedirectUri, PKCE_CODE_VERIFIER_REGEX } from "./oauth-client-fns";
import {
OauthAuthorizationCodePayloadSchema,
TCreateOauthClientDTO,
@@ -238,7 +238,7 @@ export const oauthClientServiceFactory = ({
const tokenSession = await tokenService.getUserTokenSession({
userId: dto.userId,
ip: dto.ip,
- userAgent: `Infisical OAuth - ${client.name}`
+ userAgent: `Infisical OAuth - ${client.clientId}`
});
if (!tokenSession) throw new BadRequestError({ message: "Failed to create user token session" });
@@ -321,6 +321,11 @@ export const oauthClientServiceFactory = ({
if (codePayload.codeChallenge) {
if (!dto.codeVerifier) throw new BadRequestError({ message: "Missing PKCE code_verifier" });
+ if (!PKCE_CODE_VERIFIER_REGEX.test(dto.codeVerifier)) {
+ throw new BadRequestError({
+ message: "Invalid PKCE code_verifier: must be 43-128 characters using only [A-Za-z0-9-._~]"
+ });
+ }
if (computePkceChallenge(dto.codeVerifier) !== codePayload.codeChallenge) {
throw new BadRequestError({ message: "PKCE challenge mismatch" });
}