Skip to content

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

fix: adress PR comment

IgorHorta57410f4d8053
diff --git a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
index 81c277dba5..7da0d2bc63 100644
--- a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
@@ -25,8 +25,19 @@ export enum OpenRouterLimitReset {
Monthly = "monthly"
}
+/** Max length for OpenRouter API key name. OpenRouter docs only require >=1 char; we cap at 255 for sanity checks. */
+export const OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH = 255;
+
const OpenRouterApiKeyRotationParametersSchema = z.object({
- name: z.string().trim().min(1, "Key name required").describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.name),
+ name: z
+ .string()
+ .trim()
+ .min(1, "Key name required")
+ .max(
+ OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH,
+ `Key name must be ${OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH} characters or fewer`
+ )
+ .describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.name),
limit: z.number().positive().optional().nullable().describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.limit),
limitReset: z
.nativeEnum(OpenRouterLimitReset)
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
index ed6659e264..f6dd401d0d 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
@@ -7,6 +7,9 @@ import { OpenRouterLimitReset } from "@app/hooks/api/secretRotationsV2/types/ope
const NO_RESET_VALUE = "none";
+/** Max length for OpenRouter API key name (matches backend schema). */
+const OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH = 255;
+
const LIMIT_RESET_OPTIONS = [
{ label: "No Reset", value: NO_RESET_VALUE },
{ label: "Daily", value: OpenRouterLimitReset.Daily },
@@ -35,7 +38,12 @@ export const OpenRouterApiKeyRotationParametersFields = () => {
label="Key Name"
tooltipText="A descriptive name for the generated API key"
>
- <Input value={value} onChange={onChange} placeholder="My Rotated API Key" />
+ <Input
+ value={value}
+ onChange={onChange}
+ placeholder="My Rotated API Key"
+ maxLength={OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH}
+ />
</FormControl>
)}
/>
diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
index 2a86f492d7..38a37dfc81 100644
--- a/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
@@ -4,11 +4,21 @@ import { BaseSecretRotationSchema } from "@app/components/secret-rotations-v2/fo
import { SecretRotation } from "@app/hooks/api/secretRotationsV2";
import { OpenRouterLimitReset } from "@app/hooks/api/secretRotationsV2/types/open-router-api-key-rotation";
+/** Max length for OpenRouter API key name (sanity check; OpenRouter docs only require >=1 char). */
+const OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH = 255;
+
export const OpenRouterApiKeyRotationSchema = z
.object({
type: z.literal(SecretRotation.OpenRouterApiKey),
parameters: z.object({
- name: z.string().trim().min(1, "Key name required"),
+ name: z
+ .string()
+ .trim()
+ .min(1, "Key name required")
+ .max(
+ OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH,
+ `Key name must be ${OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH} characters or fewer`
+ ),
limit: z.number().positive().optional().nullable(),
limitReset: z.nativeEnum(OpenRouterLimitReset).optional().nullable(),
includeByokInLimit: z.boolean().optional().nullable()