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: make scoped identity access token revocation lookup sargable
Claude6c1c8ea4215a
diff --git a/backend/src/services/identity-access-token/identity-access-token-revocation-dal.ts b/backend/src/services/identity-access-token/identity-access-token-revocation-dal.tsindex 69cc24b1d6..1d7e11da6e 100644--- a/backend/src/services/identity-access-token/identity-access-token-revocation-dal.ts+++ b/backend/src/services/identity-access-token/identity-access-token-revocation-dal.ts@@ -40,10 +40,12 @@ export const identityAccessTokenRevocationDALFactory = (db: TDbClient) => {const findActiveRevocationsForToken = async ({tokenId,- identityId+ identityId,+ scopes}: {tokenId: string;identityId: string;+ scopes: string[];}): Promise<TRevocationRow[]> => {try {return (@@ -52,10 +54,14 @@ export const identityAccessTokenRevocationDALFactory = (db: TDbClient) => {.select("id", "identityId", "revokedAt", "createdAt", "scope").where("expiresAt", ">", db.fn.now()).where("identityId", identityId)- // Legacy markers key off id (tokenId or identityId); scoped markers always- // come along so the in-memory filter can match by clientSecretId / authMethod.+ // Both halves of the OR must be equality predicates so the planner can+ // serve `id IN (...)` from the PK and the `scope IN (...)` filter stays+ // selective. `scope IS NOT NULL` would force a non-sargable scan..andWhere((qb) => {- void qb.whereIn("id", [tokenId, identityId]).orWhereNotNull("scope");+ void qb.whereIn("id", [tokenId, identityId]);+ if (scopes.length > 0) {+ void qb.orWhereIn("scope", scopes);+ }})) as TRevocationRow[]);} catch (error) {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.tsindex 345727cd38..0fbfe02f3b 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@@ -104,9 +104,14 @@ export const identityAccessTokenServiceFactory = ({authMethod?: string;messagePrefix?: "Failed to authorize" | "Cannot renew";}) => {+ const scopes: string[] = [];+ if (clientSecretId) scopes.push(clientSecretId);+ if (authMethod) scopes.push(authMethod);+const activeRevocations = await identityAccessTokenRevocationDAL.findActiveRevocationsForToken({tokenId,- identityId+ identityId,+ scopes});for (const revocation of activeRevocations) {