Skip to content

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

address claude reviews

x0322059402da3cc315
diff --git a/backend/src/ee/routes/v1/pam-session-chunk-router.ts b/backend/src/ee/routes/v1/pam-session-chunk-router.ts
index 962714e2a2..3f03154ca6 100644
--- a/backend/src/ee/routes/v1/pam-session-chunk-router.ts
+++ b/backend/src/ee/routes/v1/pam-session-chunk-router.ts
@@ -129,11 +129,11 @@ export const registerPamSessionChunkRouter = async (server: FastifyZodProvider)
let ciphertextBuf: Buffer | undefined;
if (req.body.ciphertext) {
- try {
- ciphertextBuf = Buffer.from(req.body.ciphertext, "base64");
- } catch {
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
+ if (!BASE64_RE.test(req.body.ciphertext)) {
throw new BadRequestError({ message: "ciphertext must be valid base64" });
}
+ ciphertextBuf = Buffer.from(req.body.ciphertext, "base64");
}
const result = await server.services.pamSessionChunk.recordChunk(
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 24228e0f03..9411d3acee 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -1278,19 +1278,19 @@ export const pamAccountServiceFactory = ({
kmsService
});
- await pamSessionDAL.updateById(sessionId, {
- status: PamSessionStatus.Active,
- startedAt: new Date(),
+ const started = await pamSessionDAL.startSession(sessionId, {
encryptedSessionKey,
gatewayUploadTokenHash: uploadTokenHash
});
- sessionStarted = true;
- sessionRecordingSecrets = {
- sessionKeyBase64: sessionKey.toString("base64"),
- uploadTokenBase64: uploadToken.toString("base64"),
- storageBackend
- };
+ if (started) {
+ sessionStarted = true;
+ sessionRecordingSecrets = {
+ sessionKeyBase64: sessionKey.toString("base64"),
+ uploadTokenBase64: uploadToken.toString("base64"),
+ storageBackend
+ };
+ }
}
// Handle SSH certificate-based authentication
diff --git a/backend/src/ee/services/pam-session/pam-session-chunk-service.ts b/backend/src/ee/services/pam-session/pam-session-chunk-service.ts
index 96e4ad1478..76cb6896eb 100644
--- a/backend/src/ee/services/pam-session/pam-session-chunk-service.ts
+++ b/backend/src/ee/services/pam-session/pam-session-chunk-service.ts
@@ -148,14 +148,12 @@ export const pamSessionChunkServiceFactory = ({
});
}
- let ciphertextSha256: Buffer;
- let iv: Buffer;
- try {
- ciphertextSha256 = Buffer.from(ciphertextSha256Base64, "base64");
- iv = Buffer.from(ivBase64, "base64");
- } catch {
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
+ if (!BASE64_RE.test(ciphertextSha256Base64) || !BASE64_RE.test(ivBase64)) {
throw new BadRequestError({ message: "Invalid base64 in chunk metadata" });
}
+ const ciphertextSha256 = Buffer.from(ciphertextSha256Base64, "base64");
+ const iv = Buffer.from(ivBase64, "base64");
if (ciphertextSha256.length !== 32) {
throw new BadRequestError({ message: "ciphertextSha256 must be 32 bytes (sha256 digest)" });
}
diff --git a/backend/src/ee/services/pam-session/pam-session-dal.ts b/backend/src/ee/services/pam-session/pam-session-dal.ts
index 693f62a8c2..7a696a1676 100644
--- a/backend/src/ee/services/pam-session/pam-session-dal.ts
+++ b/backend/src/ee/services/pam-session/pam-session-dal.ts
@@ -82,6 +82,26 @@ export const pamSessionDALFactory = (db: TDbClient) => {
return updated;
};
+ const startSession = async (
+ sessionId: string,
+ patch: {
+ encryptedSessionKey: Buffer;
+ gatewayUploadTokenHash: Buffer;
+ },
+ tx?: Knex
+ ) => {
+ const [updated] = await (tx || db)(TableName.PamSession)
+ .where("id", sessionId)
+ .where("status", PamSessionStatus.Starting)
+ .update({
+ status: PamSessionStatus.Active,
+ startedAt: new Date(),
+ ...patch
+ })
+ .returning("*");
+ return updated;
+ };
+
return {
...orm,
findById,
@@ -89,6 +109,7 @@ export const pamSessionDALFactory = (db: TDbClient) => {
expireSessionById,
countActiveWebSessions,
endSessionById,
- terminateSessionById
+ terminateSessionById,
+ startSession
};
};
diff --git a/backend/src/ee/services/pam-session/pam-session-schemas.ts b/backend/src/ee/services/pam-session/pam-session-schemas.ts
index f6816ca146..d12ef510eb 100644
--- a/backend/src/ee/services/pam-session/pam-session-schemas.ts
+++ b/backend/src/ee/services/pam-session/pam-session-schemas.ts
@@ -54,22 +54,21 @@ export const AiInsightsSchema = z
.nullable()
.optional();
-export const SanitizedSessionSchema = PamSessionsSchema.omit({
+const SessionInternalFieldsOmit = {
encryptedLogsBlob: true,
- encryptedAiInsights: true
-}).extend({
+ encryptedAiInsights: true,
+ encryptedSessionKey: true,
+ gatewayUploadTokenHash: true
+} as const;
+
+export const SanitizedSessionSchema = PamSessionsSchema.omit(SessionInternalFieldsOmit).extend({
logs: z.array(z.union([PamSessionCommandLogSchema, HttpEventSchema, TerminalEventSchema])),
gatewayIdentityId: z.string().nullable().optional(),
gatewayId: z.string().nullable().optional(),
aiInsights: AiInsightsSchema
});
-export const SanitizedSessionListItemSchema = PamSessionsSchema.omit({
- encryptedLogsBlob: true,
- encryptedAiInsights: true,
- encryptedSessionKey: true,
- gatewayUploadTokenHash: true
-}).extend({
+export const SanitizedSessionListItemSchema = PamSessionsSchema.omit(SessionInternalFieldsOmit).extend({
gatewayIdentityId: z.string().nullable().optional(),
gatewayId: z.string().nullable().optional()
});