Skip to content

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

fix(kms-service): ensure correct transaction handling for org and project data key retrieval

Victor Santos5d43a9681fb2
diff --git a/backend/src/services/kms/kms-service.ts b/backend/src/services/kms/kms-service.ts
index 61af04f0ed..ec1a498db7 100644
--- a/backend/src/services/kms/kms-service.ts
+++ b/backend/src/services/kms/kms-service.ts
@@ -634,6 +634,9 @@ export const kmsServiceFactory = ({
if (orgDataKey) {
return orgDataKey;
}
+
+ // Key was created by another transaction; re-fetch org to get the encrypted data key
+ org = await orgDAL.findById(orgId, trx);
} else {
// Standalone Redis mode - use Redis lock
const lock = await keyStore
@@ -733,7 +736,7 @@ export const kmsServiceFactory = ({
delay: 500
});
- project = await projectDAL.findById(projectId);
+ project = await projectDAL.findById(projectId, trx);
} else {
const kmsKeyId = await (trx || projectDAL).transaction(async (tx) => {
const createdKeyId = await $createProjectKmsKey(projectId, tx);
@@ -790,6 +793,9 @@ export const kmsServiceFactory = ({
if (projectDataKey) {
return projectDataKey;
}
+
+ // Key was created by another transaction; re-fetch project to get the encrypted data key
+ project = await projectDAL.findById(projectId, trx);
} else {
// Standalone Redis mode - use Redis lock
const lock = await keyStore