Skip to content

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

fix(pam): address bot review issues in web access session handling

bernie-g293f0ea83d96
diff --git a/backend/src/ee/services/pam-web-access/pam-rdp-session-handler.ts b/backend/src/ee/services/pam-web-access/pam-rdp-session-handler.ts
index 548270d8ca..34453081f5 100644
--- a/backend/src/ee/services/pam-web-access/pam-rdp-session-handler.ts
+++ b/backend/src/ee/services/pam-web-access/pam-rdp-session-handler.ts
@@ -54,6 +54,7 @@ export const handleRdpSession = async (ctx: TSessionContext): Promise<TSessionHa
try {
tcpSocket.write(buf);
} catch {
+ if (!cleanedUp) onCleanup();
teardown();
}
});
@@ -63,6 +64,7 @@ export const handleRdpSession = async (ctx: TSessionContext): Promise<TSessionHa
socket.send(chunk, { binary: true }, (err) => {
if (err) {
logger.error(err, "rdp session: ws send failed");
+ if (!cleanedUp) onCleanup();
teardown();
}
});
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 26265fac52..2502db8112 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
@@ -428,12 +428,11 @@ export const pamWebAccessServiceFactory = ({
if (session) {
try {
- await pamSessionDAL.updateById(session.id, {
- status: PamSessionStatus.Ended,
- endedAt: new Date()
- });
+ await pamSessionDAL.endSessionById(session.id);
} catch (err) {
logger.debug(err, "Error marking session ended in cleanup");
+ } finally {
+ session = null;
}
}
@@ -627,6 +626,11 @@ export const pamWebAccessServiceFactory = ({
handlerResult = await handleRdpSession(ctx);
}
+ // RDP calls releaseEarlyBuffer() itself; detach for all other types
+ if (resource.resourceType !== PamResource.Windows) {
+ releaseEarlyBuffer();
+ }
+
// 7. ACTIVATE SESSION
await pamSessionDAL.updateById(session.id, {
status: PamSessionStatus.Active,