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
refac implementation
adilsond6637e31915d
diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.tsindex 9601f540a5..ee0e573054 100644--- a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts+++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts@@ -737,16 +737,13 @@ export const secretApprovalRequestServiceFactory = ({// el.secret is the commit's referenced secret in its current DB state (undefined if since deleted)const hasUpdateConflict = (el: (typeof secretUpdationCommits)[number]) => {if (!el.secretId || !el.secret) return true; // referenced secret was deleted (or recreated)+ // whoever currently holds the commit's key must be the referenced secret itselfconst secretWithSameKey = updationSecretsGroupByKey[el.key]?.[0];-- // a rename was requested if the commit's key differs from the secret version it was based on- const isRename = el.key !== (el.secretVersion?.key ?? el.secret.key);- if (isRename) {- // rename conflicts only if the new key is already taken by a different secret- return Boolean(secretWithSameKey) && secretWithSameKey.id !== el.secretId;- }- // plain update conflicts if the key no longer belongs to the referenced secret- return !secretWithSameKey || secretWithSameKey.id !== el.secretId;+ if (secretWithSameKey) return secretWithSameKey.id !== el.secretId;+ // the key is free: fine for a rename, a conflict for a plain update whose secret was renamed externally.+ // rename intent is inferred from the secret version the commit was based on (falls back to the live key if that version was pruned)+ const isRename = el.key !== el.secret.key;+ return !isRename;};secretUpdationCommits.filter(hasUpdateConflict).forEach((el) => {@@ -1928,7 +1925,9 @@ export const secretApprovalRequestServiceFactory = ({const actualSecretsToUpdate = secretsToUpdate.filter((el) => existingKeys.has(el.secretKey));- const secretsWithNewName = actualSecretsToUpdate.filter(({ newSecretName }) => Boolean(newSecretName));+ const secretsWithNewName = actualSecretsToUpdate.filter(+ ({ newSecretName, secretKey }) => Boolean(newSecretName) && newSecretName !== secretKey+ );if (secretsWithNewName.length) {const secrets = await secretV2BridgeDAL.findBySecretKeys(folderId,@@ -1943,8 +1942,7 @@ export const secretApprovalRequestServiceFactory = ({message: `Secret does not exist: ${secrets.map((el) => el.key).join(",")}`});- const renameSourcesGroupByKey = groupBy(secrets, (i) => i.key);- // check if the new name is already taken by a different secret in the folder+ // the new name must not already be taken by another secret in the folderconst existingSecretsWithNewName = await secretV2BridgeDAL.findBySecretKeys(folderId,secretsWithNewName.map((el) => ({@@ -1952,21 +1950,12 @@ export const secretApprovalRequestServiceFactory = ({type: SecretType.Shared})));- if (existingSecretsWithNewName.length) {- const existingSecretsGroupByKey = groupBy(existingSecretsWithNewName, (i) => i.key);- const conflictingNewNames = secretsWithNewName.filter((el) => {- const existingSecret = existingSecretsGroupByKey[el.newSecretName as string]?.[0];- if (!existingSecret) return false;- // renaming a secret to its own current name is a no-op, not a collision- return existingSecret.id !== renameSourcesGroupByKey[el.secretKey][0].id;+ if (existingSecretsWithNewName.length)+ throw new BadRequestError({+ message: `Secret with the new name already exists: ${existingSecretsWithNewName+ .map((el) => el.key)+ .join(", ")}`});- if (conflictingNewNames.length)- throw new BadRequestError({- message: `Secret with the new name already exists: ${conflictingNewNames- .map((el) => el.newSecretName)- .join(", ")}`- });- }}const updatingSecretsGroupByKey = groupBy(secretsToUpdateStoredInDB, (el) => el.key);