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
add guard against duplicate create operations
Matheus Nogueirafdffb8dca40c
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 2d1e288d6b..a2c676eb46 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@@ -1882,8 +1882,15 @@ export const secretApprovalRequestServiceFactory = ({}if (updateMode === SecretUpdateMode.Upsert) {+ const createdKeys = new Set(commits.filter((c) => c.op === SecretOperations.Create).map((c) => c.key));++ // Make sure secrets in the update list are not present in the create list as well+ // This prevents a commit from having the same secret being created twice and causing+ // conflicts.+ const upsertSecrets = missingSecrets.filter((s) => !createdKeys.has(s.secretKey));+commits.push(- ...missingSecrets.map((secret) => ({+ ...upsertSecrets.map((secret) => ({op: SecretOperations.Create as const,version: 1,encryptedComment: setKnexStringValue(@@ -1907,7 +1914,7 @@ export const secretApprovalRequestServiceFactory = ({type: SecretType.Shared})));- missingSecrets.forEach(({ tagIds, secretKey }) => {+ upsertSecrets.forEach(({ tagIds, secretKey }) => {if (tagIds?.length) commitTagIds[secretKey] = tagIds;});}