Skip to content

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

fix(pam): distinguish expired grant from missing grant at launch gate

bernie-g60f58f1f774e
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
index b173e93b81..195b017fdf 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
@@ -1113,13 +1113,11 @@ export const pamAccessRequestServiceFactory = ({
});
const now = new Date();
- return (
- grants.find((g) => {
- if (g.expiresAt && new Date(g.expiresAt) <= now) return false;
- const attrs = g.attributes as { accountId?: string } | null;
- return attrs?.accountId === accountId;
- }) ?? null
- );
+ const forAccount = grants.filter((g) => (g.attributes as { accountId?: string } | null)?.accountId === accountId);
+ // Prefer a still-valid grant; otherwise return an expired one (rather than null) so the caller can
+ // distinguish "grant expired" from "no grant" and signal PAM_GRANT_EXPIRED vs PAM_APPROVAL_REQUIRED.
+ const valid = forAccount.find((g) => !g.expiresAt || new Date(g.expiresAt) > now);
+ return valid ?? forAccount[0] ?? null;
};
const getAccessStatusBatch = async (
diff --git a/backend/src/ee/services/pam-session/pam-session-service.ts b/backend/src/ee/services/pam-session/pam-session-service.ts
index e3ed85a81c..25f140ee4d 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -414,7 +414,7 @@ export const pamSessionServiceFactory = ({
const grantRemainingMs = new Date(grant.expiresAt).getTime() - Date.now();
if (grantRemainingMs <= 0) {
throw new ForbiddenRequestError({
- name: "PAM_APPROVAL_REQUIRED",
+ name: "PAM_GRANT_EXPIRED",
message: "Access grant has expired"
});
}
diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
index 90ed048fb8..4270494b9c 100644
--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts
@@ -193,7 +193,7 @@ export const pamWebAccessServiceFactory = ({
if (grant.expiresAt) {
grantRemainingMs = new Date(grant.expiresAt).getTime() - Date.now();
if (grantRemainingMs <= 0) {
- throw new ForbiddenRequestError({ name: "PAM_APPROVAL_REQUIRED", message: "Access grant has expired" });
+ throw new ForbiddenRequestError({ name: "PAM_GRANT_EXPIRED", message: "Access grant has expired" });
}
}
}