Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: validate secret exists when changing source env/folder
Daniel Hougaarda5aa46735fa1
diff --git a/backend/src/services/secret-sync/azure-entra-id-scim/azure-entra-id-scim-sync-fns.ts b/backend/src/services/secret-sync/azure-entra-id-scim/azure-entra-id-scim-sync-fns.tsindex 6c806f1201..2bb61e0399 100644--- a/backend/src/services/secret-sync/azure-entra-id-scim/azure-entra-id-scim-sync-fns.ts+++ b/backend/src/services/secret-sync/azure-entra-id-scim/azure-entra-id-scim-sync-fns.ts@@ -64,21 +64,37 @@ export const AzureEntraIdScimSyncFns = {}};-// Resolves secretKey (name) to secretId (UUID) before saving+// Resolves secret key to secret ID before saving.+// On update, if the source folder changed but no new secretKey was provided, will validate that the existing secret still exists in the new folder.export const azureEntraIdScimPreSaveTransformSyncOptions: TPreSaveTransformSyncOptionsFn = async (- { syncOptions, folderId },+ { syncOptions, existingSyncOptions, folderId },{ secretV2BridgeDAL }) => {- if (!syncOptions || !("secretKey" in syncOptions)) return syncOptions;-- const { secretKey, ...rest } = syncOptions;- const secret = await secretV2BridgeDAL.findOne({ key: secretKey as string, folderId });- if (!secret) {- throw new BadRequestError({- message: `Secret with key "${secretKey as string}" not found in the specified source folder`- });+ // If a new secretKey is provided, resolve it to a secretId+ if (syncOptions && "secretKey" in syncOptions) {+ const { secretKey, ...rest } = syncOptions;+ const secret = await secretV2BridgeDAL.findOne({ key: secretKey as string, folderId });+ if (!secret) {+ throw new BadRequestError({+ message: `Secret with key "${secretKey as string}" not found in the specified source folder`+ });+ }+ return { ...rest, secretId: secret.id };}- return { ...rest, secretId: secret.id };++ // If no new secretKey provided but there's an existing secretId, validate it still exists in the (possibly new) folder+ const existingSecretId = existingSyncOptions?.secretId as string | undefined;+ if (existingSecretId) {+ const secret = await secretV2BridgeDAL.findOne({ id: existingSecretId, folderId });+ if (!secret) {+ throw new BadRequestError({+ message:+ "The previously configured secret no longer exists in the source folder. Please re-specify syncOptions.secretKey."+ });+ }+ }++ return syncOptions;};// Fetches service principal display name from Azure Graph API and stores it in destinationConfigdiff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.tsindex 4a99138f2b..17a7062550 100644--- a/backend/src/services/secret-sync/secret-sync-service.ts+++ b/backend/src/services/secret-sync/secret-sync-service.ts@@ -566,7 +566,11 @@ export const secretSyncServiceFactory = ({const resolvedSyncOptions = folderId? await preSaveTransformSyncOptions(destination,- { syncOptions: params.syncOptions as Record<string, unknown> | undefined, folderId },+ {+ syncOptions: params.syncOptions as Record<string, unknown> | undefined,+ existingSyncOptions: secretSync.syncOptions as Record<string, unknown> | undefined,+ folderId+ },preSaveTransformDeps): (params.syncOptions as Record<string, unknown> | undefined);diff --git a/backend/src/services/secret-sync/secret-sync-types.ts b/backend/src/services/secret-sync/secret-sync-types.tsindex ef04fd41aa..cbad1c9117 100644--- a/backend/src/services/secret-sync/secret-sync-types.ts+++ b/backend/src/services/secret-sync/secret-sync-types.ts@@ -490,6 +490,7 @@ export type TPreSaveTransformDeps = {export type TPreSaveTransformSyncOptionsParams = {syncOptions: Record<string, unknown> | undefined;+ existingSyncOptions?: Record<string, unknown>;folderId: string;};