Skip to content

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

fix(tls-cert-auth): revoke unbound tokens in the same transaction as enabling binding

bernie-g271bfd5db5f4
diff --git a/backend/src/services/identity-access-token/identity-access-token-service.ts b/backend/src/services/identity-access-token/identity-access-token-service.ts
index 1552851cf5..c12838e6c5 100644
--- a/backend/src/services/identity-access-token/identity-access-token-service.ts
+++ b/backend/src/services/identity-access-token/identity-access-token-service.ts
@@ -803,24 +803,30 @@ export const identityAccessTokenServiceFactory = ({
// Scoped revoke for auth-method removal: rejects every JWT issued via the
// removed method with iat < revokedAt. Tokens issued via other methods on
// the same identity stay valid.
+ // With a tx the caller must call bumpIdentityRevocationVersion after commit.
const revokeTokensForIdentityAuthMethod = async ({
identityId,
- authMethod
+ authMethod,
+ tx
}: {
identityId: string;
authMethod: IdentityAuthMethod;
+ tx?: Knex;
}) => {
const appCfg = getConfig();
const revokedAt = new Date();
- await identityAccessTokenRevocationDAL.insertRevocation({
- id: crypto.nativeCrypto.randomUUID(),
- identityId,
- scope: authMethod,
- revokedAt,
- expiresAt: new Date(revokedAt.getTime() + appCfg.MAX_MACHINE_IDENTITY_TOKEN_AGE * 1000)
- });
- await bumpRevocationVersion(identityId);
+ await identityAccessTokenRevocationDAL.insertRevocation(
+ {
+ id: crypto.nativeCrypto.randomUUID(),
+ identityId,
+ scope: authMethod,
+ revokedAt,
+ expiresAt: new Date(revokedAt.getTime() + appCfg.MAX_MACHINE_IDENTITY_TOKEN_AGE * 1000)
+ },
+ tx
+ );
+ if (!tx) await bumpRevocationVersion(identityId);
};
// Org-scoped revoke marker for membership deactivate / remove-from-org: rejects
diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
index ced9ae34ba..8aceb3a677 100644
--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts
@@ -184,7 +184,10 @@ type TIdentityTlsCertAuthServiceFactoryDep = {
orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;
identityAccessTokenService: Pick<
TIdentityAccessTokenServiceFactory,
- "issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache"
+ | "issueIdentityAccessToken"
+ | "revokeTokensForIdentityAuthMethod"
+ | "invalidateTrustedIpsCache"
+ | "bumpIdentityRevocationVersion"
>;
eventEmitter: TEventEmitter;
};
@@ -685,6 +688,8 @@ export const identityTlsCertAuthServiceFactory = ({
validateCaCertificateUsable(caCertificate);
}
+ const isEnablingBinding =
+ Boolean(bindAccessTokenToCertificate) && !identityTlsCertAuth.bindAccessTokenToCertificate;
const updatedTlsCertAuth = await identityTlsCertAuthDAL.transaction(async (tx) => {
const doc = await identityTlsCertAuthDAL.updateById(
identityTlsCertAuth.id,
@@ -716,15 +721,19 @@ export const identityTlsCertAuthServiceFactory = ({
},
tx
);
+ // Tokens issued before binding was enabled carry no certificate claim, so they must not outlive the change.
+ if (isEnablingBinding) {
+ await identityAccessTokenService.revokeTokensForIdentityAuthMethod({
+ identityId,
+ authMethod: IdentityAuthMethod.TLS_CERT_AUTH,
+ tx
+ });
+ }
return doc;
});
- // Tokens issued before binding was enabled carry no certificate claim, so they must not outlive the change.
- if (bindAccessTokenToCertificate && !identityTlsCertAuth.bindAccessTokenToCertificate) {
- await identityAccessTokenService.revokeTokensForIdentityAuthMethod({
- identityId,
- authMethod: IdentityAuthMethod.TLS_CERT_AUTH
- });
+ if (isEnablingBinding) {
+ await identityAccessTokenService.bumpIdentityRevocationVersion({ identityId });
}
await identityAccessTokenService.invalidateTrustedIpsCache(identityId, IdentityAuthMethod.TLS_CERT_AUTH);
return { ...updatedTlsCertAuth, orgId: identityMembershipOrg.scopeOrgId };