Skip to content

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

feat: introduce safeJWTSchema for identity token validation

Victor Santos3aa2de22e2b3
diff --git a/frontend/src/lib/schemas/index.ts b/frontend/src/lib/schemas/index.ts
index 15d10151a9..9dc427769a 100644
--- a/frontend/src/lib/schemas/index.ts
+++ b/frontend/src/lib/schemas/index.ts
@@ -18,3 +18,12 @@ export const SecretNameSchema = BaseSecretNameSchema.refine(
(el) => !el.includes(" "),
"Secret name cannot contain spaces."
).refine((el) => !el.includes(":"), "Secret name cannot contain colon.");
+
+export const safeJWTSchema = z
+ .string()
+ .trim()
+ .min(1, { message: "Token is required" })
+ .regex(
+ /^[a-zA-Z0-9._-]+$/,
+ "Token contains invalid characters. Only letters, numbers, dots, hyphens, and underscores are allowed."
+ );
diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliDeploymentMethod.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliDeploymentMethod.tsx
index 8ea1807cb4..4a654dc9d3 100644
--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliDeploymentMethod.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliDeploymentMethod.tsx
@@ -30,7 +30,7 @@ import {
useGetIdentityTokenAuth,
useGetRelays
} from "@app/hooks/api";
-import { slugSchema } from "@app/lib/schemas";
+import { safeJWTSchema, slugSchema } from "@app/lib/schemas";
import { RelayOption } from "./RelayOption";
@@ -62,7 +62,7 @@ const formSchemaWithIdentity = baseFormSchema.extend({
});
const formSchemaWithToken = baseFormSchema.extend({
- identityToken: z.string().min(1, "Token is required")
+ identityToken: safeJWTSchema
});
export const GatewayCliDeploymentMethod = () => {
diff --git a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliSystemdDeploymentMethod.tsx b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliSystemdDeploymentMethod.tsx
index 1603f3bdd9..3b0c458f96 100644
--- a/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliSystemdDeploymentMethod.tsx
+++ b/frontend/src/pages/organization/NetworkingPage/components/GatewayTab/components/GatewayCliSystemdDeploymentMethod.tsx
@@ -30,7 +30,7 @@ import {
useGetIdentityTokenAuth,
useGetRelays
} from "@app/hooks/api";
-import { slugSchema } from "@app/lib/schemas";
+import { safeJWTSchema, slugSchema } from "@app/lib/schemas";
import { RelayOption } from "./RelayOption";
@@ -62,7 +62,7 @@ const formSchemaWithIdentity = baseFormSchema.extend({
});
const formSchemaWithToken = baseFormSchema.extend({
- identityToken: z.string().min(1, "Token is required")
+ identityToken: safeJWTSchema
});
export const GatewayCliSystemdDeploymentMethod = () => {