Skip to content

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

fix: move to encrypted inputs

Daniel Hougaarddedd9e067fcd
diff --git a/backend/src/db/migrations/20260319204352_secret-validation-rules.ts b/backend/src/db/migrations/20260319204352_secret-validation-rules.ts
index 85f97d0d47..4446b1aa21 100644
--- a/backend/src/db/migrations/20260319204352_secret-validation-rules.ts
+++ b/backend/src/db/migrations/20260319204352_secret-validation-rules.ts
@@ -11,15 +11,21 @@ export async function up(knex: Knex): Promise<void> {
tb.string("description").nullable();
tb.string("projectId").notNullable();
tb.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
+
+ // null = not scoped to a specific env
tb.uuid("envId").nullable();
tb.foreign("envId").references("id").inTable(TableName.Environment).onDelete("CASCADE");
- tb.string("secretPath").notNullable().defaultTo("/");
+
+ // we store it as a string because it's a glob pattern that we need to evaluate against at a later stage, not a specific folder
+ tb.string("secretPath").notNullable();
tb.string("type").notNullable();
- tb.jsonb("inputs").notNullable();
+ tb.binary("encryptedInputs").notNullable();
tb.boolean("isActive").notNullable().defaultTo(true);
+
tb.index("projectId");
tb.index("envId");
tb.index("secretPath");
+
tb.timestamps(true, true, true);
});
diff --git a/backend/src/db/schemas/secret-validation-rules.ts b/backend/src/db/schemas/secret-validation-rules.ts
index 65f68a33e4..cb4abd104c 100644
--- a/backend/src/db/schemas/secret-validation-rules.ts
+++ b/backend/src/db/schemas/secret-validation-rules.ts
@@ -5,6 +5,8 @@
import { z } from "zod";
+import { zodBuffer } from "@app/lib/zod";
+
import { TImmutableDBKeys } from "./models";
export const SecretValidationRulesSchema = z.object({
@@ -13,9 +15,9 @@ export const SecretValidationRulesSchema = z.object({
description: z.string().nullable().optional(),
projectId: z.string(),
envId: z.string().uuid().nullable().optional(),
- secretPath: z.string().default("/"),
+ secretPath: z.string(),
type: z.string(),
- inputs: z.unknown(),
+ encryptedInputs: zodBuffer,
isActive: z.boolean().default(true),
createdAt: z.date(),
updatedAt: z.date()
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 27973349cb..4551f2506d 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1570,7 +1570,8 @@ export const registerRoutes = async (
const secretValidationRuleService = secretValidationRuleServiceFactory({
secretValidationRuleDAL,
projectEnvDAL,
- permissionService
+ permissionService,
+ kmsService
});
const folderService = secretFolderServiceFactory({
permissionService,
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
index d708d89bbd..47c081f9f9 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
@@ -153,8 +153,7 @@ type TValidationRule = {
envId?: string | null;
secretPath: string;
type: string;
- inputs?: unknown;
- isActive: boolean;
+ inputs: unknown;
};
type TValidationViolation = {
@@ -165,11 +164,11 @@ type TValidationViolation = {
};
const CONSTRAINT_LABELS: Record<ConstraintType, string> = {
- [ConstraintType.MinLength]: "minimum length",
- [ConstraintType.MaxLength]: "maximum length",
- [ConstraintType.RegexPattern]: "regex pattern",
- [ConstraintType.RequiredPrefix]: "required prefix",
- [ConstraintType.RequiredSuffix]: "required suffix"
+ [ConstraintType.MinLength]: "Minimum length",
+ [ConstraintType.MaxLength]: "Maximum length",
+ [ConstraintType.RegexPattern]: "Regex pattern",
+ [ConstraintType.RequiredPrefix]: "Required prefix",
+ [ConstraintType.RequiredSuffix]: "Required suffix"
};
const TARGET_LABELS: Record<ConstraintTarget, string> = {
@@ -285,11 +284,6 @@ export const enforceSecretValidationRules = ({
const matchingRulesByType = new Map<SecretValidationRuleType, TValidationRule[]>();
for (const rule of projectRules) {
- if (!rule.isActive) {
- // eslint-disable-next-line no-continue
- continue;
- }
-
// Check environment match (null envId on rule = all environments)
if (rule.envId && rule.envId !== envId) {
// eslint-disable-next-line no-continue
@@ -327,7 +321,7 @@ export const enforceSecretValidationRules = ({
);
throw new BadRequestError({
- message: `Secret validation failed:\n${details.join("\n")}`
+ message: `Secret validation failed:\n${details.join("\n\n")}`
});
}
};
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts
index 007438e48f..b69d9a843b 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-schemas.ts
@@ -39,5 +39,5 @@ export const parseSecretValidationRuleInputs = (type: string, inputs: unknown) =
export const SecretValidationRuleResponseSchema = SecretValidationRulesSchema.omit({
type: true,
- inputs: true
+ encryptedInputs: true
}).and(SecretValidationRuleInputSchema);
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 4a559a6b5e..7a2248faba 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
@@ -6,6 +6,8 @@ import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services
import { NotFoundError } from "@app/lib/errors";
import { TProjectEnvDALFactory } from "@app/services/project-env/project-env-dal";
+import { TKmsServiceFactory } from "../kms/kms-service";
+import { KmsDataKey } from "../kms/kms-types";
import { TSecretValidationRuleDALFactory } from "./secret-validation-rule-dal";
import { checkForOverlappingRules, enforceSecretValidationRules } from "./secret-validation-rule-fns";
import { parseSecretValidationRuleInputs } from "./secret-validation-rule-schemas";
@@ -21,6 +23,7 @@ type TSecretValidationRuleServiceFactoryDep = {
secretValidationRuleDAL: TSecretValidationRuleDALFactory;
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
+ kmsService: TKmsServiceFactory;
};
export type TSecretValidationRuleServiceFactory = ReturnType<typeof secretValidationRuleServiceFactory>;
@@ -28,7 +31,8 @@ export type TSecretValidationRuleServiceFactory = ReturnType<typeof secretValida
export const secretValidationRuleServiceFactory = ({
secretValidationRuleDAL,
projectEnvDAL,
- permissionService
+ permissionService,
+ kmsService
}: TSecretValidationRuleServiceFactoryDep) => {
const listByProjectId = async ({
actor,
@@ -49,11 +53,21 @@ export const secretValidationRuleServiceFactory = ({
const rules = await secretValidationRuleDAL.find({ projectId });
- return (rules || []).map((rule) => ({
+ const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
+ const finalRules = (rules || []).map((rule) => ({
...rule,
type: rule.type as SecretValidationRuleType,
- inputs: parseSecretValidationRuleInputs(rule.type, rule.inputs)
+ inputs: parseSecretValidationRuleInputs(
+ rule.type,
+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: rule.encryptedInputs }).toString()) as unknown
+ )
}));
+
+ return finalRules;
};
const createRule = async ({
@@ -99,6 +113,15 @@ export const secretValidationRuleServiceFactory = ({
existingRules
});
+ const { encryptor: ruleInputsEncryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
+ const { cipherTextBlob: encryptedRuleInputs } = ruleInputsEncryptor({
+ plainText: Buffer.from(JSON.stringify(parsedInputs))
+ });
+
const rule = await secretValidationRuleDAL.create({
name,
description,
@@ -106,7 +129,7 @@ export const secretValidationRuleServiceFactory = ({
envId,
secretPath,
type,
- inputs: parsedInputs
+ encryptedInputs: encryptedRuleInputs
});
return { ...rule, type: rule.type as SecretValidationRuleType, inputs: parsedInputs };
@@ -151,8 +174,17 @@ export const secretValidationRuleServiceFactory = ({
}
}
+ const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
+ const decryptedExistingRuleInputs = ruleInputsDecryptor({
+ cipherTextBlob: existingRule.encryptedInputs
+ });
+
const ruleType = dto.type ?? existingRule.type;
- const ruleInputs = inputs ?? existingRule.inputs;
+ const ruleInputs = inputs ?? (JSON.parse(decryptedExistingRuleInputs.toString()) as unknown);
const parsedInputs = parseSecretValidationRuleInputs(ruleType, ruleInputs);
const finalEnvId = envId !== undefined ? envId : (existingRule.envId as string | null);
@@ -168,16 +200,33 @@ export const secretValidationRuleServiceFactory = ({
excludeRuleId: ruleId
});
+ let updatedRuleInputs: Buffer | undefined;
+
+ if (inputs) {
+ const { encryptor: ruleInputsEncryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
+ const { cipherTextBlob: encryptedRuleInputs } = ruleInputsEncryptor({
+ plainText: Buffer.from(JSON.stringify(parsedInputs))
+ });
+ updatedRuleInputs = encryptedRuleInputs;
+ }
+
const updatedRule = await secretValidationRuleDAL.updateById(ruleId, {
...(envId !== undefined && { envId }),
- ...(Boolean(inputs) && { inputs: parsedInputs }),
+ ...(Boolean(updatedRuleInputs) && { encryptedInputs: updatedRuleInputs }),
...dto
});
return {
...updatedRule,
type: updatedRule.type as SecretValidationRuleType,
- inputs: parseSecretValidationRuleInputs(updatedRule.type, updatedRule.inputs)
+ inputs: parseSecretValidationRuleInputs(
+ updatedRule.type,
+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: updatedRule.encryptedInputs }).toString()) as unknown
+ )
};
};
@@ -204,11 +253,19 @@ export const secretValidationRuleServiceFactory = ({
throw new NotFoundError({ message: `Secret validation rule with ID ${ruleId} not found` });
}
+ const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
await secretValidationRuleDAL.deleteById(ruleId);
return {
...existingRule,
type: existingRule.type as SecretValidationRuleType,
- inputs: parseSecretValidationRuleInputs(existingRule.type, existingRule.inputs)
+ inputs: parseSecretValidationRuleInputs(
+ existingRule.type,
+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: existingRule.encryptedInputs }).toString()) as unknown
+ )
};
};
@@ -229,13 +286,21 @@ export const secretValidationRuleServiceFactory = ({
}) => {
if (!secrets.length) return;
- const rules = await secretValidationRuleDAL.find({ projectId });
+ const rules = await secretValidationRuleDAL.find({ projectId, isActive: true });
if (!rules.length) return;
+ const { decryptor: ruleInputsDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId
+ });
+
enforceSecretValidationRules({
projectRules: rules.map((r) => ({
...r,
- isActive: r.isActive ?? true
+ inputs: parseSecretValidationRuleInputs(
+ r.type,
+ JSON.parse(ruleInputsDecryptor({ cipherTextBlob: r.encryptedInputs }).toString()) as unknown
+ )
})),
envId,
secretPath,
diff --git a/frontend/src/components/notifications/Notifications.tsx b/frontend/src/components/notifications/Notifications.tsx
index 2727880382..1639cc5cf6 100644
--- a/frontend/src/components/notifications/Notifications.tsx
+++ b/frontend/src/components/notifications/Notifications.tsx
@@ -23,7 +23,9 @@ export const NotificationContent = ({
return (
<div className="msg-container">
{title && <div className="text-md mb-1 font-medium">{title}</div>}
- <div className={title ? "text-sm text-neutral-400" : "text-md"}>{text}</div>
+ <div className={title ? "text-sm whitespace-pre-line text-neutral-400" : "text-md whitespace-pre-line"}>
+ {text}
+ </div>
{children && <div className="mt-2">{children}</div>}
{(callToAction || copyActions) && (
<div