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 rotated credential exfiltration
Carlos Monastyrski5234ccaad638
diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.tsindex 5e5679e674..1b4cd3c216 100644--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.test.ts@@ -184,4 +184,45 @@ describe("rotateScheduledAccount recovery probe", () => {// ...but the target's own username is what gets altered.expect(applyArgs.targetUsername).toBe("app");});++ test("aborts a delegated rotation when target and rotator are no longer the same resource, sending no credential", async () => {+ // The target's host was changed after binding, so it no longer matches the rotator's resource.+ const account = {+ ...buildAccount(),+ rotationAccountId: "rot-1",+ encryptedConnectionDetails: blobOf({+ host: "attacker.host",+ port: 5432,+ database: "app",+ sslEnabled: false,+ sslRejectUnauthorized: false+ })+ };+ const rotator = {+ id: "rot-1",+ projectId: "proj-1",+ accountType: PamAccountType.Postgres,+ encryptedCredentials: blobOf({ username: "rotuser", password: "rot-pw" }),+ encryptedConnectionDetails: blobOf({+ host: "db.internal",+ port: 5432,+ database: "rotdb",+ sslEnabled: false,+ sslRejectUnauthorized: false+ }),+ gatewayId: null,+ gatewayPoolId: null,+ templateGatewayId: null,+ templateGatewayPoolId: null+ };+ const { service, applyPasswordChange, testCredential } = buildService(() => true, { account, rotator });++ const result = await service.rotateScheduledAccount("acc-1");++ expect(result?.rotationStatus).toBe(ROTATION_STATUS.Failed);+ expect(result?.message).toContain("same resource");+ // Nothing may leave: no probe (testCredential) and no apply against the redirected target.+ expect(testCredential).not.toHaveBeenCalled();+ expect(applyPasswordChange).not.toHaveBeenCalled();+ });});diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.tsindex 4dcbe2b6ff..a8a37f3dfc 100644--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts@@ -216,6 +216,22 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServicconst gatewayPoolId = account.gatewayPoolId ?? account.templateGatewayPoolId;const now = new Date();+ if (account.rotationAccountId !== account.id) {+ const rotator = await pamAccountDAL.findByIdWithDetails(account.rotationAccountId);+ if (!rotator || rotator.projectId !== projectId) {+ throw new BadRequestError({ message: "Rotation account no longer exists" });+ }+ const rotatorConnection = toSqlConnectionDetails(+ accountType,+ await decrypt(projectId, rotator.encryptedConnectionDetails)+ );+ if (rotatorConnection.host !== connectionDetails.host || rotatorConnection.port !== connectionDetails.port) {+ throw new BadRequestError({+ message: "Rotation account is no longer on the same resource (host and port) as this account"+ });+ }+ }+// Recovery from an interrupted rotation: probe the candidate then the current credential, acting only on a// definitive answer so a transient failure never discards a possibly-live credential.if (account.encryptedPendingCredentials) {diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex a2fd81f58c..2d7a721883 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -389,12 +389,24 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>updateData.credentialConfigured = isCredentialConfigured(accountType, validated);}+ const routingChanged = connectionDetails !== undefined || gatewayId !== undefined || gatewayPoolId !== undefined;+ if (routingChanged && existing.rotationAccountId) {+ updateData.rotationAccountId = null;+ }+try {const account = await pamAccountDAL.transaction(async (tx) => {const updated = await pamAccountDAL.updateById(accountId, updateData, tx);- // A template move or a credential change can flip rotation readiness; re-derive the schedule atomically- // with the write so a failure can't leave a stale nextRotationAt.- if (templateId !== undefined || credentials) {+ if (routingChanged) {+ await pamAccountDAL.update(+ { rotationAccountId: accountId },+ { rotationAccountId: null, nextRotationAt: null },+ tx+ );+ }+ // A template move, credential change, or a cleared binding can flip rotation readiness; re-derive the schedule+ // atomically with the write so a failure can't leave a stale nextRotationAt.+ if (templateId !== undefined || credentials || routingChanged) {await pamAccountDAL.reconcileRotationScheduleForAccount(accountId, tx);}return updated;