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: filter revocations in memory instead of pushing OR predicate to PG
Claude2f6e60222394
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 1d7e11da6e..c91a02cba4 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@@ -38,34 +38,19 @@ export const identityAccessTokenRevocationDALFactory = (db: TDbClient) => {}};- const findActiveRevocationsForToken = async ({- tokenId,- identityId,- scopes- }: {- tokenId: string;- identityId: string;- scopes: string[];- }): Promise<TRevocationRow[]> => {+ // Returns every active revocation row for the identity. Per-token / identity-wide /+ // scoped matching is done in the service so the query stays a single (identityId,+ // expiresAt) index range — no OR predicates that the planner could decompose into+ // a sequential scan based on `scope` selectivity stats.+ const findActiveRevocationsForIdentity = async (identityId: string): Promise<TRevocationRow[]> => {try {- return (- (await db- .replicaNode()(TableName.IdentityAccessTokenRevocation)- .select("id", "identityId", "revokedAt", "createdAt", "scope")- .where("expiresAt", ">", db.fn.now())- .where("identityId", identityId)- // 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]);- if (scopes.length > 0) {- void qb.orWhereIn("scope", scopes);- }- })) as TRevocationRow[]- );+ return (await db+ .replicaNode()(TableName.IdentityAccessTokenRevocation)+ .select("id", "identityId", "revokedAt", "createdAt", "scope")+ .where("expiresAt", ">", db.fn.now())+ .where("identityId", identityId)) as TRevocationRow[];} catch (error) {- throw new DatabaseError({ error, name: "IdentityAccessTokenRevocationFindActiveForToken" });+ throw new DatabaseError({ error, name: "IdentityAccessTokenRevocationFindActiveForIdentity" });}};@@ -79,7 +64,7 @@ export const identityAccessTokenRevocationDALFactory = (db: TDbClient) => {return {insertRevocation,- findActiveRevocationsForToken,+ findActiveRevocationsForIdentity,removeExpiredRevocations};};diff --git a/backend/src/services/identity-access-token/identity-access-token-service.test.ts b/backend/src/services/identity-access-token/identity-access-token-service.test.tsindex 87c6e23096..89230d3b68 100644--- a/backend/src/services/identity-access-token/identity-access-token-service.test.ts+++ b/backend/src/services/identity-access-token/identity-access-token-service.test.ts@@ -54,7 +54,7 @@ const createService = ({setItemWithExpiry: vi.fn()};const identityAccessTokenRevocationDAL = {- findActiveRevocationsForToken: vi.fn().mockResolvedValue(activeRevocations),+ findActiveRevocationsForIdentity: vi.fn().mockResolvedValue(activeRevocations),insertRevocation: vi.fn()};const identityDAL = {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 0fbfe02f3b..20da516176 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,15 +104,7 @@ 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,- scopes- });+ const activeRevocations = await identityAccessTokenRevocationDAL.findActiveRevocationsForIdentity(identityId);for (const revocation of activeRevocations) {// Legacy markers have scope=null and key off polymorphic `id`.