fix: parse deploy webhook bodies in the handler so the size limit can be configured

This commit is contained in:
Souvik Kumar
2026-09-29 19:20:41 +05:30
parent e8be2693e0
commit 1c6d333739
4 changed files with 25 additions and 9 deletions
@@ -62,6 +62,10 @@ vi.mock("@dokploy/server/db", () => ({
},
}));
vi.mock("next/dist/server/api-utils/node/parse-body", () => ({
parseBody: async (req: { body: unknown }) => req.body,
}));
vi.mock("@dokploy/server", () => ({
DEPLOY_WEBHOOK_MAX_BODY_SIZE: 25 * 1024 * 1024,
IS_CLOUD: false,
@@ -8,6 +8,7 @@ import {
import { db } from "@dokploy/server/db";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { parseBody } from "next/dist/server/api-utils/node/parse-body";
import { applications } from "@/server/db/schema";
import type { DeploymentJob } from "@/server/queues/queue-types";
import { myQueue } from "@/server/queues/queueSetup";
@@ -35,9 +36,7 @@ const getPackageVersion = (headers: any, body: any) => {
export const config = {
api: {
bodyParser: {
sizeLimit: DEPLOY_WEBHOOK_MAX_BODY_SIZE,
},
bodyParser: false,
},
};
@@ -45,6 +44,11 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (Number(req.headers["content-length"]) > DEPLOY_WEBHOOK_MAX_BODY_SIZE) {
res.status(413).json({ message: "Payload too large" });
return;
}
req.body = await parseBody(req, DEPLOY_WEBHOOK_MAX_BODY_SIZE);
const { refreshToken } = req.query;
try {
if (req.headers["x-github-event"] === "ping") {
@@ -6,6 +6,7 @@ import {
import { db } from "@dokploy/server/db";
import { eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { parseBody } from "next/dist/server/api-utils/node/parse-body";
import { compose } from "@/server/db/schema";
import type { DeploymentJob } from "@/server/queues/queue-types";
import { myQueue } from "@/server/queues/queueSetup";
@@ -21,9 +22,7 @@ import {
export const config = {
api: {
bodyParser: {
sizeLimit: DEPLOY_WEBHOOK_MAX_BODY_SIZE,
},
bodyParser: false,
},
};
@@ -31,6 +30,11 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (Number(req.headers["content-length"]) > DEPLOY_WEBHOOK_MAX_BODY_SIZE) {
res.status(413).json({ message: "Payload too large" });
return;
}
req.body = await parseBody(req, DEPLOY_WEBHOOK_MAX_BODY_SIZE);
const { refreshToken } = req.query;
try {
if (req.headers["x-github-event"] === "ping") {
+7 -3
View File
@@ -14,6 +14,7 @@ import { db } from "@dokploy/server/db";
import { Webhooks } from "@octokit/webhooks";
import { and, eq } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
import { parseBody } from "next/dist/server/api-utils/node/parse-body";
import { applications, compose, github } from "@/server/db/schema";
import type { DeploymentJob } from "@/server/queues/queue-types";
import { myQueue } from "@/server/queues/queueSetup";
@@ -29,9 +30,7 @@ const getGithubRepositoryOwner = (githubBody: any) =>
export const config = {
api: {
bodyParser: {
sizeLimit: DEPLOY_WEBHOOK_MAX_BODY_SIZE,
},
bodyParser: false,
},
};
@@ -39,6 +38,11 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (Number(req.headers["content-length"]) > DEPLOY_WEBHOOK_MAX_BODY_SIZE) {
res.status(413).json({ message: "Payload too large" });
return;
}
req.body = await parseBody(req, DEPLOY_WEBHOOK_MAX_BODY_SIZE);
const signature = req.headers["x-hub-signature-256"];
if (!signature) {
res.status(401).json({ message: "Missing signature header" });