Skip to content

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

revoke on client secret rotation

Thiago Araujo da Silva50cd02cbe503
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 557a6bb714..36eb62a0c1 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -214,6 +214,16 @@ alone would otherwise be enough to rotate an existing exchange application's sec
the check on create/update a speed bump. Any future operation that establishes this trust or hands out a
credential for it goes through `checkSsoConfigPermission` (`oauth-client-service.ts`) as well.
+**Withdrawing an exchange application's authority has to revoke the tokens it already issued, not just
+stop it getting new ones.** Deleting the client, rotating its secret, and removing the token-exchange
+grant all call `revokeSessionsByUserAgent` (`oauth-client-service.ts`) — the sessions are tagged with
+`getOauthClientSessionUserAgent(clientId)`, which is the only handle we have on them. Rotation revokes
+**only** on exchange applications: there the secret alone mints tokens for any user, so rotating after a
+leak would contain nothing otherwise, whereas in the redirect flow the secret has to be paired with an
+authorization code or refresh token and blanket revocation would just sign every user out. The tag is
+per client, not per grant, so a client holding both grants loses its redirect-flow tokens too — the safe
+direction, and only reachable via the API.
+
**Everything the exchange fetches from the identity provider is cached for 10 minutes, and nothing read
from our own database is.** Token exchange sits on the caller's hot path (a middleware typically exchanges
per request it serves), so the discovery document and the `JwksClient` are both cached per URL in
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.ts
index 282f113325..bfe1b4cae0 100644
--- a/backend/src/services/oauth-client/oauth-client-service.ts
+++ b/backend/src/services/oauth-client/oauth-client-service.ts
@@ -297,6 +297,7 @@ export const oauthClientServiceFactory = ({
const client = await getOrgClientOrThrow(dto.clientDbId, actor.orgId);
const grantTypes = dedupeGrantTypes(dto.grantTypes ?? (client.grantTypes as OauthGrantType[]));
+ const wasTokenExchangeEnabled = hasTokenExchangeGrant(client.grantTypes as OauthGrantType[]);
const isTokenExchangeEnabled = hasTokenExchangeGrant(grantTypes);
const isRedirectBased = hasRedirectBasedGrant(grantTypes);
@@ -337,6 +338,10 @@ export const oauthClientServiceFactory = ({
tokenExchangeIdpSatisfiesMfa: isTokenExchangeEnabled ? resolvedIdpSatisfiesMfa : false
});
+ if (wasTokenExchangeEnabled && !isTokenExchangeEnabled) {
+ await tokenService.revokeSessionsByUserAgent(getOauthClientSessionUserAgent(client.clientId));
+ }
+
return sanitizeOauthClient(updatedClient);
};
@@ -360,7 +365,9 @@ export const oauthClientServiceFactory = ({
const client = await getOrgClientOrThrow(clientDbId, actor.orgId);
- if (hasTokenExchangeGrant(client.grantTypes as OauthGrantType[])) {
+ const usesTokenExchange = hasTokenExchangeGrant(client.grantTypes as OauthGrantType[]);
+
+ if (usesTokenExchange) {
await checkSsoConfigPermission(actor, "rotate the secret of an OAuth application that uses token exchange");
}
@@ -373,6 +380,10 @@ export const oauthClientServiceFactory = ({
clientSecretPrefix: clientSecret.slice(0, 4)
});
+ if (usesTokenExchange) {
+ await tokenService.revokeSessionsByUserAgent(getOauthClientSessionUserAgent(client.clientId));
+ }
+
return { client: sanitizeOauthClient(updatedClient), clientSecret };
};
diff --git a/docs/documentation/platform/oauth-applications.mdx b/docs/documentation/platform/oauth-applications.mdx
index c1dc1bb5e2..3becc3bad9 100644
--- a/docs/documentation/platform/oauth-applications.mdx
+++ b/docs/documentation/platform/oauth-applications.mdx
@@ -175,4 +175,6 @@ The effective permissions are the **intersection** of the user's permissions and
## Revoking access
-Deleting an OAuth application from the **OAuth Applications** tab immediately revokes every access and refresh token that application issued, so they stop working on the next request rather than living until expiry. Rotating the client secret invalidates the old secret for future token exchanges.
+Deleting an OAuth application from the **OAuth Applications** tab immediately revokes every access and refresh token that application issued, so they stop working on the next request rather than living until expiry.
+
+Rotating the client secret invalidates the old secret for future token requests but leaves already-issued tokens working until they expire, so users of the integration are not signed out. The secret alone cannot mint a token in this flow: it has to be paired with an authorization code from a user's browser or with a refresh token. If you need to cut existing access off immediately, delete the application. (Rotation on a [token exchange](/documentation/platform/oauth-token-exchange) application behaves differently, because there the secret is sufficient on its own.)
diff --git a/docs/documentation/platform/oauth-token-exchange.mdx b/docs/documentation/platform/oauth-token-exchange.mdx
index 324a5a23ee..239fdba90c 100644
--- a/docs/documentation/platform/oauth-token-exchange.mdx
+++ b/docs/documentation/platform/oauth-token-exchange.mdx
@@ -222,6 +222,10 @@ The **SSO** page lists the applications that depend on the issuer, so you can se
## Revoking access
-Deleting the application from the **OAuth Applications** page immediately revokes every token it issued, so they stop working on the next request rather than living until expiry. Rotating the client secret stops the middleware obtaining new tokens until it is updated.
+Three actions revoke every token the application has issued, so they stop working on the next request rather than living until expiry:
-Because no refresh tokens are issued, the exposure from a compromised middleware is bounded by the remaining lifetime of the access tokens it currently holds.
+- **Deleting the application** from the **OAuth Applications** page.
+- **Rotating the client secret.** On a token exchange application the secret is the whole authority, so rotating it in response to a leak also cuts off whatever was minted with the old one. Plan for the middleware to be signed out of every user until it picks up the new secret.
+- **Turning off the token exchange grant** on the application.
+
+Because no refresh tokens are issued, the exposure from a compromised middleware is otherwise bounded by the remaining lifetime of the access tokens it currently holds.