Skip to content

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

fix(pam): handle invalid JSON in event-batch upload with 400

bernie-g05b16f3b32c8
diff --git a/backend/src/ee/routes/v1/pam-session-router.ts b/backend/src/ee/routes/v1/pam-session-router.ts
index a92370b103..e88d20c967 100644
--- a/backend/src/ee/routes/v1/pam-session-router.ts
+++ b/backend/src/ee/routes/v1/pam-session-router.ts
@@ -15,6 +15,7 @@ import {
SessionLogsPageSchema,
TerminalEventSchema
} from "@app/ee/services/pam-session/pam-session-schemas";
+import { BadRequestError } from "@app/lib/errors";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { getTelemetryDistinctId } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
@@ -381,7 +382,12 @@ export const registerPamSessionRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.IDENTITY_ACCESS_TOKEN]),
handler: async (req) => {
const EventBatchSchema = z.array(z.union([PamSessionCommandLogSchema, TerminalEventSchema, HttpEventSchema]));
- EventBatchSchema.parse(JSON.parse(req.body.toString()));
+ try {
+ EventBatchSchema.parse(JSON.parse(req.body.toString()));
+ } catch (e) {
+ if (e instanceof SyntaxError) throw new BadRequestError({ message: "Invalid JSON in request body" });
+ throw e;
+ }
const { projectId, wasInserted } = await server.services.pamSession.uploadEventBatch(
{