Skip to content

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

refactor(validation): improve comments and validation logic for secret moves

Dimitris Staratzis7ce3c3fd68e6
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
index a78874f798..7862834d06 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts
@@ -1813,9 +1813,9 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes
}
}
- // a move writes these secrets at the destination, directly or through a change request, so they are held to
- // the destination's validation rules. the source copies still exist in this transaction, so they are left out
- // of the duplicate lookup rather than reported as duplicates of the secrets being moved.
+ // validate the moved secrets against the destination's validation rules before writing anything, whether the
+ // move is applied directly or through a change request. the source secrets still exist at this point, so they
+ // are excluded from the duplicate check; otherwise each moved secret would be reported as a duplicate of itself.
await validateSecrets(
{
projectId,
@@ -1824,7 +1824,7 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes
secretPath: destinationFolder.path,
secrets: secretsToApplyAtDestination.map((secret) => ({
key: secret.key,
- // an empty value is stored without ciphertext, but the moved secret is still held to the rules as empty
+ // empty values are stored without an encrypted value, so treat a missing value as an empty string
value: secret.value ?? "",
secretId: destinationSecretsGroupedByKey[secret.key]?.[0]?.id
})),
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts
index d8daccc921..08df24b1d5 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts
@@ -316,7 +316,7 @@ export type TFnSecretMove = {
secretQueueService: Pick<TSecretQueueFactory, "syncSecrets">;
reminderDAL: Pick<TReminderDALFactory, "findSecretReminders" | "delete">;
reminderService: Pick<TReminderServiceFactory, "batchCreateReminders">;
- // the secret service's rule check, which also words the failure for what the actor may read
+ // validates secrets against the project's validation rules; the error only names locations the actor can read
validateSecrets: (
dto: TValidateSecretsDTO,
permission: MongoAbility<ProjectPermissionSet>,
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 1001e5d59c..c0304b733e 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
@@ -130,8 +130,8 @@ export type TValidateSecretsDTO = {
secretPath: string;
secrets: TSecretToValidate[];
/**
- * Secrets left out of the duplicate lookup without being the ones written, such as the source copies
- * a move is about to remove. Unlike `secretId`, they bring no version history into the check.
+ * IDs of secrets to ignore when checking for duplicate values, e.g. the source copies of secrets being moved.
+ * Unlike `secretId`, these are only skipped in the duplicate check; their version history is not checked.
*/
excludedSecretIds?: string[];
};