Skip to content

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

type issues

Danielacd8d35781d6
diff --git a/backend/src/server/routes/v1/secret-validation-rule-router.ts b/backend/src/server/routes/v1/secret-validation-rule-router.ts
index 4076311e6c..ea77a7fb2a 100644
--- a/backend/src/server/routes/v1/secret-validation-rule-router.ts
+++ b/backend/src/server/routes/v1/secret-validation-rule-router.ts
@@ -6,11 +6,8 @@ import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
import {
- dynamicSecretsInputsSchema,
- secretRotationsInputsSchema,
SecretValidationRuleInputSchema,
- SecretValidationRuleResponseSchema,
- staticSecretsInputsSchema
+ SecretValidationRuleResponseSchema
} from "@app/services/secret-validation-rule/secret-validation-rule-schemas";
import { SecretValidationRuleType } from "@app/services/secret-validation-rule/secret-validation-rule-types";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
@@ -129,9 +126,12 @@ export const registerSecretValidationRuleRouter = async (server: FastifyZodProvi
environmentSlug: z.string().trim().min(1).nullable().optional(),
secretPath: z.string().trim().min(1).optional(),
type: z.nativeEnum(SecretValidationRuleType).optional(),
- inputs: z
- .union([staticSecretsInputsSchema, dynamicSecretsInputsSchema, secretRotationsInputsSchema])
- .optional(),
+ // Inputs are validated strictly in the service against the resolved
+ // rule type via `parseSecretValidationRuleInputs`. We can't pick the
+ // right schema here because `type` and `inputs` are sibling fields,
+ // so a union over the per-type input schemas would silently strip
+ // fields (e.g. `providers`) whenever a sibling member also matched.
+ inputs: z.object({}).passthrough().optional(),
isActive: z.boolean().optional()
}),
response: {
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
index 0770de6511..2d7451ff33 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
@@ -29,6 +29,7 @@ import {
TDynamicSecretsInputs,
TListSecretValidationRulesDTO,
TSecretRotationsInputs,
+ TSecretValidationRuleRecord,
TUpdateSecretValidationRuleDTO
} from "./secret-validation-rule-types";
@@ -77,14 +78,17 @@ export const secretValidationRuleServiceFactory = ({
projectId
});
- const finalRules = (rules || []).map((rule) => ({
- ...rule,
- type: rule.type as SecretValidationRuleType,
- inputs: parseSecretValidationRuleInputs(
- rule.type,
- JSON.parse(ruleInputsDecryptor({ cipherTextBlob: rule.encryptedInputs }).toString()) as unknown
- )
- }));
+ const finalRules = (rules || []).map(
+ (rule) =>
+ ({
+ ...rule,
+ type: rule.type as SecretValidationRuleType,
+ inputs: parseSecretValidationRuleInputs(
+ rule.type,
+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: rule.encryptedInputs }).toString()) as unknown
+ )
+ }) as TSecretValidationRuleRecord
+ );
return finalRules;
};
@@ -173,7 +177,11 @@ export const secretValidationRuleServiceFactory = ({
encryptedInputs: encryptedRuleInputs
});
- return { ...rule, type: rule.type as SecretValidationRuleType, inputs: parsedInputs };
+ return {
+ ...rule,
+ type: rule.type as SecretValidationRuleType,
+ inputs: parsedInputs
+ } as TSecretValidationRuleRecord;
};
const updateRule = async ({
@@ -282,7 +290,7 @@ export const secretValidationRuleServiceFactory = ({
updatedRule.type,
JSON.parse(ruleInputsDecryptor({ cipherTextBlob: updatedRule.encryptedInputs }).toString()) as unknown
)
- };
+ } as TSecretValidationRuleRecord;
};
const deleteRule = async ({
@@ -321,7 +329,7 @@ export const secretValidationRuleServiceFactory = ({
existingRule.type,
JSON.parse(ruleInputsDecryptor({ cipherTextBlob: existingRule.encryptedInputs }).toString()) as unknown
)
- };
+ } as TSecretValidationRuleRecord;
};
/**
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts
index 2a4c37025c..7df4cf975c 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-types.ts
@@ -1,3 +1,4 @@
+import { TSecretValidationRules } from "@app/db/schemas";
import { TProjectPermission } from "@app/lib/types";
export enum SecretValidationRuleType {
@@ -57,13 +58,29 @@ export type TSecretRotationsInputs = {
export type TSecretValidationRuleInputs = TStaticSecretsInputs | TDynamicSecretsInputs | TSecretRotationsInputs;
+// Discriminated rule shape returned by the service. The `type` field narrows
+// the matching `inputs` shape so the response schema (which is a
+// discriminated union over `type`) is satisfied without manual casts at
+// each handler.
+type TRuleCommonFields = Omit<TSecretValidationRules, "type">;
+
+export type TSecretValidationRuleRecord =
+ | (TRuleCommonFields & { type: SecretValidationRuleType.StaticSecrets; inputs: TStaticSecretsInputs })
+ | (TRuleCommonFields & { type: SecretValidationRuleType.DynamicSecrets; inputs: TDynamicSecretsInputs })
+ | (TRuleCommonFields & { type: SecretValidationRuleType.SecretRotations; inputs: TSecretRotationsInputs });
+
+// `inputs` is validated server-side by `parseSecretValidationRuleInputs` against
+// the resolved rule type, so the DTO accepts `unknown` rather than a structured
+// union. The shape can't be known at the route boundary because `type` and
+// `inputs` are sibling fields and a per-type Zod union would silently strip
+// fields when sibling members happen to also match.
export type TCreateSecretValidationRuleDTO = {
name: string;
description?: string | null;
environmentSlug?: string;
secretPath: string;
type: SecretValidationRuleType;
- inputs: TSecretValidationRuleInputs;
+ inputs: unknown;
} & TProjectPermission;
export type TUpdateSecretValidationRuleDTO = {
@@ -73,7 +90,7 @@ export type TUpdateSecretValidationRuleDTO = {
environmentSlug?: string | null;
secretPath?: string;
type?: SecretValidationRuleType;
- inputs?: TSecretValidationRuleInputs;
+ inputs?: unknown;
isActive?: boolean;
} & TProjectPermission;