Skip to content

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

fix(gateway): stop a preserved reviewer token being redirected via review mode

bernie-g0aa759a2bb0d
diff --git a/backend/src/ee/routes/v3/gateway-router.ts b/backend/src/ee/routes/v3/gateway-router.ts
index 42ef17c716..7f2ca0f758 100644
--- a/backend/src/ee/routes/v3/gateway-router.ts
+++ b/backend/src/ee/routes/v3/gateway-router.ts
@@ -98,6 +98,13 @@ const KubernetesAuthMethodInputSchema = z
"A gateway pool cannot perform the review, because its membership can change after this is saved. Select a specific gateway.",
path: ["gatewayPoolId"]
})
+ // The gateway calls its own API server in gateway review mode, so a host there is not merely
+ // unnecessary, it is unused: accepting one lets a host be parked and picked up by a later
+ // switch back to API mode.
+ .refine((data) => data.tokenReviewMode !== KubernetesTokenReviewMode.Gateway || !data.kubernetesHost, {
+ message: "A Kubernetes host does not apply when the gateway performs the review. Remove it.",
+ path: ["kubernetesHost"]
+ })
// Only gateway review mode can go without a host, because there the gateway calls its own
// API server rather than an address we supply.
.refine((data) => data.tokenReviewMode === KubernetesTokenReviewMode.Gateway || Boolean(data.kubernetesHost), {
diff --git a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
index 6d888634f4..25f3f5cff2 100644
--- a/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
+++ b/backend/src/ee/services/resource-auth-method/resource-auth-method-service.ts
@@ -763,6 +763,11 @@ export const resourceAuthMethodServiceFactory = ({
// host alone is not enough: routing it through a different gateway, trusting a different
// CA, or turning verification off all redirect it somewhere it was never validated against.
const destinationChanged =
+ // The review mode counts. Gateway mode is exempt from this guard, so without it an
+ // editor could park a new host under gateway mode, then switch back to API mode with
+ // that host already stored and have the preserved token sent there.
+ (stored?.tokenReviewMode ?? KubernetesTokenReviewMode.Api) !==
+ (authMethod.tokenReviewMode ?? KubernetesTokenReviewMode.Api) ||
stored?.kubernetesHost !== authMethod.kubernetesHost ||
(stored?.gatewayV2Id ?? null) !== (authMethod.gatewayV2Id ?? null) ||
(stored?.gatewayPoolId ?? null) !== (authMethod.gatewayPoolId ?? null) ||
@@ -776,7 +781,7 @@ export const resourceAuthMethodServiceFactory = ({
) {
throw new BadRequestError({
message:
- "Re-enter the token reviewer JWT when changing the Kubernetes host, the reviewing gateway, the CA certificate, or TLS verification. Reset it instead to remove it. The stored token is never sent to a destination it was not validated against."
+ "Re-enter the token reviewer JWT when changing the review mode, the Kubernetes host, the reviewing gateway, the CA certificate, or TLS verification. Reset it instead to remove it. The stored token is never sent to a destination it was not validated against."
});
}