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 token revokation look up
Thiago Araujo da Silva2d49ac67f8ac
diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.test.tsindex 7dc2a997f8..24b92868e9 100644--- a/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.test.ts@@ -15,7 +15,9 @@ const buildDAL = () => {whereRaw: [] as unknown[][],// Calls made inside a `.where((builder) => ...)` group.groupedWhereNull: [] as unknown[],- groupedOrWhere: [] as unknown[][]+ groupedOrWhere: [] as unknown[][],+ // Calls made on the subquery passed to `.whereNotExists(...)`.+ notExists: [] as { from: unknown; whereRaw: unknown[][] }[]};const group = {@@ -50,6 +52,23 @@ const buildDAL = () => {calls.whereRaw.push(args);return chain;},+ whereNotExists: (cb: (sub: unknown) => void) => {+ const entry = { from: undefined as unknown, whereRaw: [] as unknown[][] };+ const sub = {+ select: () => sub,+ from: (table: unknown) => {+ entry.from = table;+ return sub;+ },+ whereRaw: (...args: unknown[]) => {+ entry.whereRaw.push(args);+ return sub;+ }+ };+ cb(sub);+ calls.notExists.push(entry);+ return chain;+ },orderByRaw: () => chain,select: async () => []};@@ -149,6 +168,21 @@ describe("identity credential alert dal", () => {expect(calls.where).toContainEqual([`${TableName.IdentityAccessToken}.accessTokenTTL`, ">", 0]);});+ test("a Token Auth scan skips tokens revoked through a per-token revocation marker", async () => {+ const { dal, calls } = buildDAL();++ await dal.findExpiringTokenAuthTokens(scanArgs);++ // POST /auth/token/revoke only writes the marker and leaves isAccessTokenRevoked false, so the+ // flag alone would keep alerting on a token nobody can use until it expires.+ expect(calls.notExists).toContainEqual({+ from: TableName.IdentityAccessTokenRevocation,+ whereRaw: [+ ["?? = ??::uuid", [`${TableName.IdentityAccessTokenRevocation}.id`, `${TableName.IdentityAccessToken}.id`]]+ ]+ });+ });+test("a Token Auth token expires at its creation time plus its clamped stored TTL, not its max TTL", async () => {const { dal, calls } = buildDAL();diff --git a/backend/src/services/alert/providers/identity-credential-alert-dal.ts b/backend/src/services/alert/providers/identity-credential-alert-dal.tsindex b9b032b9c7..cd7a7bf777 100644--- a/backend/src/services/alert/providers/identity-credential-alert-dal.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-dal.ts@@ -116,6 +116,16 @@ export const identityCredentialAlertDALFactory = (db: TDbClient) => {const query = (tx || db.replicaNode())(TableName.IdentityAccessToken).where(`${TableName.IdentityAccessToken}.authMethod`, IdentityAuthMethod.TOKEN_AUTH).where(`${TableName.IdentityAccessToken}.isAccessTokenRevoked`, false)+ .whereNotExists(+ (sub) =>+ void sub+ .select(db.raw("1"))+ .from(TableName.IdentityAccessTokenRevocation)+ .whereRaw("?? = ??::uuid", [+ `${TableName.IdentityAccessTokenRevocation}.id`,+ `${TableName.IdentityAccessToken}.id`+ ])+ ).where(`${TableName.IdentityAccessToken}.accessTokenTTL`, ">", 0).whereRaw(`${expiresAtSql} > ?::timestamptz`, [asOf]).whereRaw(`${expiresAtSql} <= ?::timestamptz + ?::interval + ?::interval`, [