diff --git a/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts b/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts index d11c9c736..6b61c97d7 100644 --- a/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts +++ b/apps/dokploy/__test__/deploy/github-webhook-handler.test.ts @@ -62,12 +62,7 @@ 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, shouldDeploy: mocks.shouldDeploy, checkUserRepositoryPermissions: vi.fn(), diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index 03430ea08..988a344d4 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -1,6 +1,5 @@ import { type Bitbucket, - DEPLOY_WEBHOOK_MAX_BODY_SIZE, getBitbucketHeaders, IS_CLOUD, shouldDeploy, @@ -8,7 +7,6 @@ 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"; @@ -36,7 +34,9 @@ const getPackageVersion = (headers: any, body: any) => { export const config = { api: { - bodyParser: false, + bodyParser: { + sizeLimit: "25mb", + }, }, }; @@ -44,11 +44,6 @@ 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") { diff --git a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts index fc7d3c54e..06b4e768d 100644 --- a/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/compose/[refreshToken].ts @@ -1,12 +1,7 @@ -import { - DEPLOY_WEBHOOK_MAX_BODY_SIZE, - IS_CLOUD, - shouldDeploy, -} from "@dokploy/server"; +import { IS_CLOUD, shouldDeploy } from "@dokploy/server"; 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"; @@ -22,7 +17,9 @@ import { export const config = { api: { - bodyParser: false, + bodyParser: { + sizeLimit: "25mb", + }, }, }; @@ -30,11 +27,6 @@ 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") { diff --git a/apps/dokploy/pages/api/deploy/github.ts b/apps/dokploy/pages/api/deploy/github.ts index 55427c10f..bb39ed7d5 100644 --- a/apps/dokploy/pages/api/deploy/github.ts +++ b/apps/dokploy/pages/api/deploy/github.ts @@ -2,7 +2,6 @@ import { checkUserRepositoryPermissions, createPreviewDeployment, createSecurityBlockedComment, - DEPLOY_WEBHOOK_MAX_BODY_SIZE, findGithubById, findPreviewDeploymentByApplicationId, findPreviewDeploymentsByPullRequestId, @@ -14,7 +13,6 @@ 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"; @@ -30,7 +28,9 @@ const getGithubRepositoryOwner = (githubBody: any) => export const config = { api: { - bodyParser: false, + bodyParser: { + sizeLimit: "25mb", + }, }, }; @@ -38,11 +38,6 @@ 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" }); diff --git a/packages/server/src/constants/index.ts b/packages/server/src/constants/index.ts index 133a09f7a..c303041f3 100644 --- a/packages/server/src/constants/index.ts +++ b/packages/server/src/constants/index.ts @@ -13,7 +13,7 @@ export const DOKPLOY_DOCKER_PORT = process.env.DOKPLOY_DOCKER_PORT export const CLEANUP_CRON_JOB = "50 23 * * *"; -// Body size limits for the OpenAPI catch-all route (pages/api/[...trpc].ts) and the deploy webhooks (pages/api/deploy/*). +// Body size limits for the OpenAPI catch-all route (pages/api/[...trpc].ts). const parseByteSize = (envVar: string, fallback: number): number => { const raw = process.env[envVar]; if (!raw) return fallback; @@ -35,11 +35,6 @@ export const OPENAPI_MAX_UPLOAD_SIZE = parseByteSize( 1024 * 1024 * 1024, // 1gb ); -export const DEPLOY_WEBHOOK_MAX_BODY_SIZE = parseByteSize( - "DEPLOY_WEBHOOK_MAX_BODY_SIZE", - 25 * 1024 * 1024, // 25mb, GitHub's max webhook payload -); - type DockerSocketCandidate = { label: string; path: string;