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; }