Skip to content

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

fix(pam): validate S3 region enum, require connection for S3 config, call onCleanup on pre-connect failures

bernie-ge380ccec405b
diff --git a/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts b/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
index 858bf50786..d327880519 100644
--- a/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
+++ b/backend/src/ee/services/pam-account-template/pam-account-template-schemas.ts
@@ -1,5 +1,7 @@
import { z } from "zod";
+import { AWSRegion } from "@app/services/app-connection/app-connection-enums";
+
import { PamRecordingStorageBackend } from "../pam-session-recording/pam-recording-enums";
export const PamPasswordConstraintsSchema = z.object({
@@ -13,7 +15,7 @@ export const PamPasswordConstraintsSchema = z.object({
export const PamRecordingS3ConfigSchema = z.object({
bucket: z.string().trim().min(1),
- region: z.string().trim().min(1),
+ region: z.nativeEnum(AWSRegion),
keyPrefix: z.string().trim().optional()
});
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index d70eb1055a..6c2ad16f38 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -258,9 +258,12 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
let resolvedS3Config = null;
if (recordingSettings?.s3Config) {
const connId = recordingConnectionId ?? template.recordingConnectionId;
- if (connId) {
- resolvedS3Config = await validateRecordingS3Config(deps, connId, recordingSettings.s3Config);
+ if (!connId) {
+ throw new BadRequestError({
+ message: "S3 recording config requires an AWS connection on the account or template"
+ });
}
+ resolvedS3Config = await validateRecordingS3Config(deps, connId, recordingSettings.s3Config);
}
const validatedConnectionDetails = validateConnectionDetails(accountType, connectionDetails);
@@ -377,9 +380,12 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
const connId =
(recordingConnectionId !== undefined ? recordingConnectionId : existing.recordingConnectionId) ??
existing.templateRecordingConnectionId;
- if (connId) {
- resolvedS3Config = await validateRecordingS3Config(deps, connId, recordingSettings.s3Config);
+ if (!connId) {
+ throw new BadRequestError({
+ message: "S3 recording config requires an AWS connection on the account or template"
+ });
}
+ resolvedS3Config = await validateRecordingS3Config(deps, connId, recordingSettings.s3Config);
}
const updateData: Record<string, unknown> = {};
diff --git a/backend/src/ee/services/pam-web-access/rdp/pam-rdp-session-handler.ts b/backend/src/ee/services/pam-web-access/rdp/pam-rdp-session-handler.ts
index 205d80c151..b0fd61aef1 100644
--- a/backend/src/ee/services/pam-web-access/rdp/pam-rdp-session-handler.ts
+++ b/backend/src/ee/services/pam-web-access/rdp/pam-rdp-session-handler.ts
@@ -32,6 +32,7 @@ export const handleRdpSession = async (ctx: TSessionContext): Promise<TSessionHa
return new Promise<TSessionHandlerResult>((resolve, reject) => {
const connectTimeout = setTimeout(() => {
logger.error({ sessionId }, "rdp session: relay connect timed out");
+ if (!cleanedUp) onCleanup();
teardown();
reject(new Error("RDP relay connection timed out"));
}, RDP_TCP_CONNECT_TIMEOUT_MS);
@@ -105,6 +106,7 @@ export const handleRdpSession = async (ctx: TSessionContext): Promise<TSessionHa
tcpSocket.once("error", (err) => {
clearTimeout(connectTimeout);
logger.error(err, "rdp session: failed to connect to relay");
+ if (!cleanedUp) onCleanup();
teardown();
reject(err);
});