From 2279a7933ccf39e702565462b05ca81e7a4fac65 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Fri, 26 Feb 2021 16:54:40 +0100 Subject: [PATCH 1/3] fix(standalone): do not allow root directory as static dir --- lib/core-server/src/build-static.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/core-server/src/build-static.ts b/lib/core-server/src/build-static.ts index cb43a3061b0..96ecf564740 100644 --- a/lib/core-server/src/build-static.ts +++ b/lib/core-server/src/build-static.ts @@ -29,6 +29,10 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions & throw new Error("Won't remove current directory. Check your outputDir!"); } + if (options.staticDir?.includes('/')) { + throw new Error("Won't copy root directory. Check your staticDirs!"); + } + options.outputDir = path.isAbsolute(options.outputDir) ? options.outputDir : path.join(process.cwd(), options.outputDir); From a5ebfc2bc800cac15968d7cab75fc80af0d88c8f Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Fri, 26 Feb 2021 16:55:21 +0100 Subject: [PATCH 2/3] test(standalone): add test coverage to assure root dir for staticDir throws --- lib/core-server/src/core-presets.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/core-server/src/core-presets.test.ts b/lib/core-server/src/core-presets.test.ts index 6dcdd62557d..27644061317 100644 --- a/lib/core-server/src/core-presets.test.ts +++ b/lib/core-server/src/core-presets.test.ts @@ -203,4 +203,21 @@ describe('dev cli flags', () => { ); }); }); + + describe('Invalid staticDir must throw: root directory /', () => { + const optionsWithInvalidStaticDir = { + ...cliOptions, + staticDir: ['/'], + }; + beforeEach(() => { + jest.clearAllMocks(); + cache.clear(); + }); + it('production mode', async () => { + expect.assertions(1); + await expect(buildStaticStandalone(optionsWithInvalidStaticDir)).rejects.toThrow( + "Won't copy root directory. Check your staticDirs!" + ); + }); + }); }); From 63af718b1e4df5157ce7c1498032cd990e58d9c1 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sun, 14 Mar 2021 21:51:26 +0100 Subject: [PATCH 3/3] test(core-presets): remove redundant beforeEach steps --- lib/core-server/src/core-presets.test.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/core-server/src/core-presets.test.ts b/lib/core-server/src/core-presets.test.ts index 27644061317..b081aad91a8 100644 --- a/lib/core-server/src/core-presets.test.ts +++ b/lib/core-server/src/core-presets.test.ts @@ -192,10 +192,7 @@ describe('dev cli flags', () => { ...cliOptions, outputDir, }; - beforeEach(() => { - jest.clearAllMocks(); - cache.clear(); - }); + it('production mode', async () => { expect.assertions(1); await expect(buildStaticStandalone(optionsWithInvalidDir)).rejects.toThrow( @@ -209,10 +206,7 @@ describe('dev cli flags', () => { ...cliOptions, staticDir: ['/'], }; - beforeEach(() => { - jest.clearAllMocks(); - cache.clear(); - }); + it('production mode', async () => { expect.assertions(1); await expect(buildStaticStandalone(optionsWithInvalidStaticDir)).rejects.toThrow(