Skip to content

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

fix(pam): bind access grants to the account's folder at launch

bernie-g3fd55d59ec55
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 195b017fdf..ea71847055 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
@@ -1103,6 +1103,7 @@ export const pamAccessRequestServiceFactory = ({
const checkGrant = async ({
userId,
accountId,
+ accountFolderId,
projectId
}: TCheckGrantDTO): Promise<TApprovalRequestGrants | null> => {
const grants = await approvalRequestGrantsDAL.find({
@@ -1113,7 +1114,13 @@ export const pamAccessRequestServiceFactory = ({
});
const now = new Date();
- const forAccount = grants.filter((g) => (g.attributes as { accountId?: string } | null)?.accountId === accountId);
+ // Match the grant's snapshot folder against the account's CURRENT folder: a grant approved while
+ // the account lived in another folder must not authorize launch after the account is moved into a
+ // different (gated) folder whose approvers never reviewed it.
+ const forAccount = grants.filter((g) => {
+ const attrs = g.attributes as { accountId?: string; folderId?: string | null } | null;
+ return attrs?.accountId === accountId && (attrs?.folderId ?? null) === (accountFolderId ?? null);
+ });
// 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);
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-types.ts b/backend/src/ee/services/pam-access-request/pam-access-request-types.ts
index 1c51257f09..f436152d4b 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-types.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-types.ts
@@ -53,6 +53,7 @@ export type TRevokeAccessRequestDTO = {
export type TCheckGrantDTO = {
userId: string;
accountId: string;
+ accountFolderId?: string | null;
projectId: string;
};
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 25f140ee4d..4cf03480fc 100644
--- a/backend/src/ee/services/pam-session/pam-session-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-service.ts
@@ -401,6 +401,7 @@ export const pamSessionServiceFactory = ({
const grant = await pamAccessRequestService.checkGrant({
userId: actor.actorId,
accountId: account.id,
+ accountFolderId: account.folderId,
projectId
});
if (!grant) {
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 4270494b9c..792bf03ac7 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
@@ -185,7 +185,12 @@ export const pamWebAccessServiceFactory = ({
let grantRemainingMs: number | null = null;
if (requiresApproval) {
- const grant = await pamAccessRequestService.checkGrant({ userId: actor.id, accountId, projectId });
+ const grant = await pamAccessRequestService.checkGrant({
+ userId: actor.id,
+ accountId,
+ accountFolderId: account.folderId,
+ projectId
+ });
if (!grant) {
throw new ForbiddenRequestError({ name: "PAM_APPROVAL_REQUIRED", message: "Access request required" });
}