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: confirm approval request reads against the primary on a replica miss
InfisiCalvinadfb73fe7cd2
diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts b/backend/src/ee/services/access-approval-request/access-approval-request-dal.tsindex 877768df22..ef755d2226 100644--- a/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts+++ b/backend/src/ee/services/access-approval-request/access-approval-request-dal.ts@@ -720,8 +720,13 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalRconst findById: TAccessApprovalRequestDALFactory["findById"] = async (id, tx) => {try {- const sql = findQuery({ [`${TableName.AccessApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());- const docs = await sql;+ let docs = await findQuery({ [`${TableName.AccessApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());+ // A caller that just committed a write reads its own row here, and a replica may not have+ // replayed it yet. Confirm a miss against the primary so a lagging replica cannot make a+ // committed request look absent.+ if (!docs.length && !tx) {+ docs = await findQuery({ [`${TableName.AccessApprovalRequest}.id` as "id"]: id }, db.primaryNode());+ }const formattedDoc = sqlNestRelationships({data: docs,key: "id",@@ -862,6 +867,9 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalR}]});+ // A caller that just committed a write reads its own row here, and a replica may not have+ // replayed it yet. Confirm a miss against the primary so a lagging replica cannot make a+ // committed request look absent.if (!formattedDoc?.[0]) return;return {...formattedDoc[0],diff --git a/backend/src/ee/services/access-approval-request/access-approval-request-service.ts b/backend/src/ee/services/access-approval-request/access-approval-request-service.tsindex e2527131f2..7379e91cad 100644--- a/backend/src/ee/services/access-approval-request/access-approval-request-service.ts+++ b/backend/src/ee/services/access-approval-request/access-approval-request-service.ts@@ -228,7 +228,7 @@ export const accessApprovalRequestServiceFactory = ({{// The job id must differ per delivery. A stable id would let BullMQ deduplicate every// state change after the first on the same request and drop it without a trace.- jobId: `access-request-webhook-${accessApprovalRequest.id}-${action}-${Date.now()}`,+ jobId: `access-request-webhook-${accessApprovalRequest.id}-${action}-${Date.now()}-${alphaNumericNanoId(6)}`,removeOnFail: { count: 5 },removeOnComplete: true,delay: 1000,diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.tsindex 612d2e7aea..ff1006262a 100644--- a/backend/src/ee/services/license/license-fns.ts+++ b/backend/src/ee/services/license/license-fns.ts@@ -91,7 +91,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({status: null,trial_end: null,has_used_trial: true,- secretApproval: false,+ secretApproval: true,secretRotation: false,caCrl: false,instanceUserManagement: false,diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-dal.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-dal.tsindex ef8cb83710..1eccc74b54 100644--- a/backend/src/ee/services/secret-approval-request/secret-approval-request-dal.ts+++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-dal.ts@@ -233,8 +233,13 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {const findById = async (id: string, tx?: Knex) => {try {- const sql = findQuery({ [`${TableName.SecretApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());- const docs = await sql;+ let docs = await findQuery({ [`${TableName.SecretApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());+ // A caller that just committed a write reads its own row here, and a replica may not have+ // replayed it yet. Confirm a miss against the primary so a lagging replica cannot make a+ // committed request look absent.+ if (!docs.length && !tx) {+ docs = await findQuery({ [`${TableName.SecretApprovalRequest}.id` as "id"]: id }, db.primaryNode());+ }const formattedDoc = sqlNestRelationships({data: docs,key: "id",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 34d83dbcc5..94b03843f2 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@@ -561,7 +561,7 @@ export const secretApprovalRequestServiceFactory = ({{// The job id must differ per delivery. A stable id would let BullMQ deduplicate every// state change after the first on the same request and drop it without a trace.- jobId: `change-request-webhook-${secretApprovalRequest.id}-${action}-${Date.now()}`,+ jobId: `change-request-webhook-${secretApprovalRequest.id}-${action}-${Date.now()}-${alphaNumericNanoId(6)}`,removeOnFail: { count: 5 },removeOnComplete: true,delay: 1000,diff --git a/backend/src/services/webhook/webhook-fns.test.ts b/backend/src/services/webhook/webhook-fns.test.tsindex ab6cda7f90..931301268a 100644--- a/backend/src/services/webhook/webhook-fns.test.ts+++ b/backend/src/services/webhook/webhook-fns.test.ts@@ -166,12 +166,12 @@ describe("getWebhookPayload: secrets.change-request.modified", () => {payload: {...changeRequestPayload,type: WebhookType.GENERAL,- commitMessage: "fixed the bug",- bypassReason: "on-call approved",+ commitMessage: "Rotated the staging database password",+ bypassReason: "On-call approved during the outage",request: {...changeRequestPayload.request,- commitMessage: "fixed the bug",- bypassReason: "on-call approved"+ commitMessage: "Rotated the staging database password",+ bypassReason: "On-call approved during the outage"}}} as unknown as Parameters<typeof getWebhookPayload>[0];@@ -179,6 +179,8 @@ describe("getWebhookPayload: secrets.change-request.modified", () => {const result = getWebhookPayload(eventWithFreeText);const serialized = JSON.stringify(result);+ expect(serialized).not.toContain("Rotated the staging database password");+ expect(serialized).not.toContain("On-call approved during the outage");expect(serialized).not.toContain("commitMessage");expect(serialized).not.toContain("bypassReason");});@@ -427,4 +429,13 @@ describe("isWebhookPathSubscribed", () => {expect(isWebhookPathSubscribed(WebhookEvents.AccessRequestModified, requestPath, hookPath)).toBe(expected);});});++ describe("a shared literal prefix delivers even where the patterns cannot overlap", () => {+ test.each([+ ["/api/*/private", "/api/*/public"],+ ["/production/api/*", "/prod"]+ ])("request %s against hook %s still delivers", (requestPath, hookPath) => {+ expect(isWebhookPathSubscribed(WebhookEvents.AccessRequestModified, requestPath, hookPath)).toBe(true);+ });+ });});