From af8072d7ad33b5fd5b216ae30e3e1fb1a0dade2d Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Fri, 22 May 2026 16:26:34 -0600 Subject: [PATCH] fix: allow square brackets in zip path validation for Next.js dynamic routes (#4468) * fix: allow square brackets in zip drop path validation for Next.js dynamic routes ZIP uploads containing Next.js dynamic route files (e.g. app/api/[id]/route.ts, pages/[slug].tsx) were rejected by readValidDirectory because the path regex did not include square bracket characters. * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../__test__/wss/readValidDirectory.test.ts | 16 ++++++++++++++++ packages/server/src/wss/utils.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/__test__/wss/readValidDirectory.test.ts b/apps/dokploy/__test__/wss/readValidDirectory.test.ts index 8107bb591..29d3152eb 100644 --- a/apps/dokploy/__test__/wss/readValidDirectory.test.ts +++ b/apps/dokploy/__test__/wss/readValidDirectory.test.ts @@ -78,4 +78,20 @@ describe("readValidDirectory (path traversal)", () => { it("returns false for empty string (resolves to cwd)", () => { expect(readValidDirectory("")).toBe(false); }); + + it("returns true for Next.js dynamic route paths with square brackets", () => { + expect( + readValidDirectory( + `${BASE}/applications/myapp/code/app/api/[id]/route.ts`, + ), + ).toBe(true); + expect( + readValidDirectory(`${BASE}/applications/myapp/code/pages/[slug].tsx`), + ).toBe(true); + expect( + readValidDirectory( + `${BASE}/applications/myapp/code/app/[...catch]/page.tsx`, + ), + ).toBe(true); + }); }); diff --git a/packages/server/src/wss/utils.ts b/packages/server/src/wss/utils.ts index bce5aa245..ec590399d 100644 --- a/packages/server/src/wss/utils.ts +++ b/packages/server/src/wss/utils.ts @@ -40,7 +40,7 @@ export const readValidDirectory = ( directory: string, serverId?: string | null, ) => { - if (!/^[\w/. :-]{1,500}$/.test(directory)) { + if (!/^[\w/. :[\]-]{1,500}$/.test(directory)) { return false; }