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(pam): re-check approval grant when a web ticket is redeemed
bernie-g0f93d6eaab93
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.tsindex 23a9ddee00..181ab6eacc 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@@ -411,6 +411,40 @@ export const pamWebAccessServiceFactory = ({enforceRecordingConfig(account);+ // The single-use ticket outlives its issuance check by up to 30s, so a grant revoked in the+ // meantime must be caught here; the revoke-time session sweep can't see sessions that don't+ // exist yet.+ const { requiresApproval } = resolveAccessControls(account.templatePolicies);+ let sessionDurationCapMs = policyDurationMs || DEFAULT_WEB_SESSION_DURATION_MS;+ if (requiresApproval) {+ const grant = await pamAccessRequestService.checkGrant({+ userId,+ accountId,+ accountFolderId: account.folderId,+ projectId+ });+ if (!grant) {+ sendMessage(socket, {+ type: TerminalServerMessageType.Output,+ data: `${SessionEndReason.ApprovalRevoked}\n`+ });+ sendSessionEndAndClose(socket, SessionEndReason.ApprovalRevoked);+ return;+ }+ if (grant.expiresAt) {+ const grantRemainingMs = new Date(grant.expiresAt).getTime() - Date.now();+ if (grantRemainingMs <= 0) {+ sendMessage(socket, {+ type: TerminalServerMessageType.Output,+ data: `${SessionEndReason.ApprovalRevoked}\n`+ });+ sendSessionEndAndClose(socket, SessionEndReason.ApprovalRevoked);+ return;+ }+ sessionDurationCapMs = Math.min(sessionDurationCapMs, grantRemainingMs);+ }+ }+const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({gatewayId: account.gatewayId ?? account.templateGatewayId,gatewayPoolId: account.gatewayPoolId ?? account.templateGatewayPoolId@@ -436,7 +470,7 @@ export const pamWebAccessServiceFactory = ({const credentials = await decrypt(projectId, account.encryptedCredentials);const user = await userDAL.findById(userId);- const sessionDurationMs = policyDurationMs || DEFAULT_WEB_SESSION_DURATION_MS;+ const sessionDurationMs = sessionDurationCapMs;const expiresAt = new Date(Date.now() + sessionDurationMs);session = await pamSessionDAL.create({diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-types.ts b/backend/src/ee/services/pam-web-access/pam-web-access-types.tsindex d0a74e59d7..244984138b 100644--- a/backend/src/ee/services/pam-web-access/pam-web-access-types.ts+++ b/backend/src/ee/services/pam-web-access/pam-web-access-types.ts@@ -10,7 +10,8 @@ export enum SessionEndReason {ConnectionLost = "Connection lost",SetupFailed = "Failed to establish connection",IdleTimeout = "Session closed due to inactivity",- SessionLimitReached = "Maximum concurrent sessions reached"+ SessionLimitReached = "Maximum concurrent sessions reached",+ ApprovalRevoked = "Your approved access is no longer active"}export enum TerminalServerMessageType {