Skip to content

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

revoke when client deletion

Thiago Araujo da Silva28fc52bf4b4a
diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.ts
index 1d2929872e..1449687746 100644
--- a/backend/src/services/auth-token/auth-token-service.ts
+++ b/backend/src/services/auth-token/auth-token-service.ts
@@ -196,6 +196,10 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgDAL, keyStore }: TAu
const revokeMySessionById = async (userId: string, sessionId: string) =>
tokenDAL.deleteTokenSession({ userId, id: sessionId });
+ // Revokes every token session created under the given userAgent (across all users/IPs). Used to
+ // invalidate all OAuth access/refresh tokens issued for a client when that client is deleted.
+ const revokeSessionsByUserAgent = async (userAgent: string) => tokenDAL.deleteTokenSession({ userAgent });
+
const validateRefreshToken = async (refreshToken?: string, opts?: { allowOauthClientToken?: boolean }) => {
const appCfg = getConfig();
if (!refreshToken) {
@@ -488,6 +492,7 @@ export const tokenServiceFactory = ({ tokenDAL, userDAL, orgDAL, keyStore }: TAu
getTokenSessionByUser,
revokeAllMySessions,
revokeMySessionById,
+ revokeSessionsByUserAgent,
validateRefreshToken,
rotateRefreshToken,
fnValidateJwtIdentity,
diff --git a/backend/src/services/oauth-client/oauth-client-fns.ts b/backend/src/services/oauth-client/oauth-client-fns.ts
index bcf44ca230..a91f724515 100644
--- a/backend/src/services/oauth-client/oauth-client-fns.ts
+++ b/backend/src/services/oauth-client/oauth-client-fns.ts
@@ -61,6 +61,11 @@ export const isAllowedRedirectUri = (uri: string) => {
return false;
};
+// OAuth token sessions are tagged with this userAgent so they are distinguishable from first-party
+// browser sessions and from other clients. Deleting a client revokes its sessions by this exact value,
+// so the format must stay in sync between session creation and revocation.
+export const getOauthClientSessionUserAgent = (clientId: string) => `Infisical OAuth - ${clientId}`;
+
export const isRegisteredRedirectUri = (registeredUris: string[], redirectUri: string) =>
registeredUris.some((uri) => {
if (uri === redirectUri) return true;
diff --git a/backend/src/services/oauth-client/oauth-client-service.ts b/backend/src/services/oauth-client/oauth-client-service.ts
index 3249e39c47..04fae9e29a 100644
--- a/backend/src/services/oauth-client/oauth-client-service.ts
+++ b/backend/src/services/oauth-client/oauth-client-service.ts
@@ -15,7 +15,12 @@ import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-se
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TOauthClientDALFactory } from "./oauth-client-dal";
-import { computePkceChallenge, isRegisteredRedirectUri, PKCE_CODE_VERIFIER_REGEX } from "./oauth-client-fns";
+import {
+ computePkceChallenge,
+ getOauthClientSessionUserAgent,
+ isRegisteredRedirectUri,
+ PKCE_CODE_VERIFIER_REGEX
+} from "./oauth-client-fns";
import {
OauthAuthorizationCodePayloadSchema,
TCreateOauthClientDTO,
@@ -32,7 +37,11 @@ type TOauthClientServiceFactoryDep = {
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "getItem" | "deleteItem">;
tokenService: Pick<
TAuthTokenServiceFactory,
- "getUserTokenSession" | "getUserTokenSessionById" | "validateRefreshToken" | "rotateRefreshToken"
+ | "getUserTokenSession"
+ | "getUserTokenSessionById"
+ | "validateRefreshToken"
+ | "rotateRefreshToken"
+ | "revokeSessionsByUserAgent"
>;
orgDAL: Pick<TOrgDALFactory, "findById">;
};
@@ -183,6 +192,12 @@ export const oauthClientServiceFactory = ({
if (!client) throw new NotFoundError({ message: `OAuth client with ID '${clientDbId}' not found` });
const deletedClient = await oauthClientDAL.deleteById(client.id);
+
+ // Revoke all access/refresh tokens issued for this client. The OAuth token sessions are tagged
+ // with the client's userAgent, so deleting them makes fnValidateJwtIdentity reject every token
+ // the client issued on the next request, rather than letting them live until JWT expiry.
+ await tokenService.revokeSessionsByUserAgent(getOauthClientSessionUserAgent(client.clientId));
+
return sanitizeOauthClient(deletedClient);
};
@@ -244,7 +259,7 @@ export const oauthClientServiceFactory = ({
const tokenSession = await tokenService.getUserTokenSession({
userId: dto.userId,
ip: dto.ip,
- userAgent: `Infisical OAuth - ${client.clientId}`
+ userAgent: getOauthClientSessionUserAgent(client.clientId)
});
if (!tokenSession) throw new BadRequestError({ message: "Failed to create user token session" });