Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gateway/src/http/routes/pairing-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { getLogger } from "../../logger.js";

const log = getLogger("pairing-proxy");

/** 64 KB — pairing payloads are tiny JSON; cap well below maxWebhookPayloadBytes. */
const MAX_PAIRING_PAYLOAD_BYTES = 64 * 1024;

const HOP_BY_HOP_HEADERS = [
"connection",
"keep-alive",
Expand Down Expand Up @@ -65,8 +68,22 @@ export function createPairingProxyHandler(config: GatewayConfig) {
}

const hasBody = req.method !== "GET" && req.method !== "HEAD";

// Payload size guard — reject oversized requests before buffering.
if (hasBody) {
const contentLength = req.headers.get("content-length");
if (contentLength && Number(contentLength) > MAX_PAIRING_PAYLOAD_BYTES) {
log.warn({ contentLength }, "Pairing proxy payload too large (content-length)");
return Response.json({ error: "Payload too large" }, { status: 413 });
}
}

const bodyBuffer = hasBody ? await req.arrayBuffer() : null;
if (bodyBuffer !== null) {
if (bodyBuffer.byteLength > MAX_PAIRING_PAYLOAD_BYTES) {
log.warn({ bodyLength: bodyBuffer.byteLength }, "Pairing proxy payload too large");
Comment thread
ashleeradka marked this conversation as resolved.
return Response.json({ error: "Payload too large" }, { status: 413 });
}
reqHeaders.set("content-length", String(bodyBuffer.byteLength));
}

Expand Down
Loading