From 0b3bae50bcfee5fd4c140e2980f0b876d63d9380 Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Wed, 28 May 2025 17:53:05 +0200 Subject: [PATCH 1/5] Follow symlinks in Preview sites when archiving directories --- patches/archiver+6.0.2.patch | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 patches/archiver+6.0.2.patch diff --git a/patches/archiver+6.0.2.patch b/patches/archiver+6.0.2.patch new file mode 100644 index 0000000000..9e10657d31 --- /dev/null +++ b/patches/archiver+6.0.2.patch @@ -0,0 +1,14 @@ +diff --git a/node_modules/archiver/lib/core.js b/node_modules/archiver/lib/core.js +index 7c0a74d..5ac4e3a 100644 +--- a/node_modules/archiver/lib/core.js ++++ b/node_modules/archiver/lib/core.js +@@ -631,7 +631,8 @@ Archiver.prototype.directory = function(dirpath, destpath, data) { + + var globOptions = { + stat: true, +- dot: true ++ dot: true, ++ follow: true, + }; + + function onGlobEnd() { From a6cc70ce9a756b2bcfadcd6640dd5bdd26cd5352 Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Wed, 28 May 2025 18:04:19 +0200 Subject: [PATCH 2/5] Add release note --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 35b5a83942..22a3a940a6 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,7 @@ Unreleased ========== * Miscellaneous security improvements #1411 +* Follow symlinks when creating preview sites #1447 1.5.2 ===== From f10e4c852065b2d7e6147e5abb167ee8689f8000 Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Thu, 29 May 2025 10:54:31 +0200 Subject: [PATCH 3/5] Use an option in the archiver instead of harcoding the value --- cli/lib/archive.ts | 1 + patches/@types+archiver+6.0.2.patch | 12 ++++++++++++ .../{archiver+6.0.2.patch => archiver+6.0.1.patch} | 12 ++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 patches/@types+archiver+6.0.2.patch rename patches/{archiver+6.0.2.patch => archiver+6.0.1.patch} (51%) diff --git a/cli/lib/archive.ts b/cli/lib/archive.ts index 31089ec91a..1b0548eec5 100644 --- a/cli/lib/archive.ts +++ b/cli/lib/archive.ts @@ -14,6 +14,7 @@ export async function createArchive( const output = fs.createWriteStream( archivePath ); const archive = archiver( 'zip', { zlib: { level: ZIP_COMPRESSION_LEVEL }, + followSymlinks: true, } ); output.on( 'close', () => { diff --git a/patches/@types+archiver+6.0.2.patch b/patches/@types+archiver+6.0.2.patch new file mode 100644 index 0000000000..945e1d0956 --- /dev/null +++ b/patches/@types+archiver+6.0.2.patch @@ -0,0 +1,12 @@ +diff --git a/node_modules/@types/archiver/index.d.ts b/node_modules/@types/archiver/index.d.ts +index 00829ac..495887b 100644 +--- a/node_modules/@types/archiver/index.d.ts ++++ b/node_modules/@types/archiver/index.d.ts +@@ -106,6 +106,7 @@ declare namespace archiver { + + interface CoreOptions { + statConcurrency?: number | undefined; ++ followSymlinks?: true + } + + interface TransformOptions { diff --git a/patches/archiver+6.0.2.patch b/patches/archiver+6.0.1.patch similarity index 51% rename from patches/archiver+6.0.2.patch rename to patches/archiver+6.0.1.patch index 9e10657d31..16862adc83 100644 --- a/patches/archiver+6.0.2.patch +++ b/patches/archiver+6.0.1.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/archiver/lib/core.js b/node_modules/archiver/lib/core.js -index 7c0a74d..5ac4e3a 100644 +index 7c0a74d..c70117b 100644 --- a/node_modules/archiver/lib/core.js +++ b/node_modules/archiver/lib/core.js @@ -631,7 +631,8 @@ Archiver.prototype.directory = function(dirpath, destpath, data) { @@ -8,7 +8,15 @@ index 7c0a74d..5ac4e3a 100644 stat: true, - dot: true + dot: true, -+ follow: true, ++ follow: this.options.followSymlinks }; function onGlobEnd() { +@@ -922,6 +923,7 @@ module.exports = Archiver; + * @global + * @property {Number} [statConcurrency=4] Sets the number of workers used to + * process the internal fs stat queue. ++ * @property {Boolean} [followSymLinks=false] Sets whether to follow symlinks. + */ + + /** From be3b8a63327eb1a2c4dfe7bfb77a646fd7393728 Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Thu, 29 May 2025 11:08:49 +0200 Subject: [PATCH 4/5] Fix error in type declaration --- patches/@types+archiver+6.0.2.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/@types+archiver+6.0.2.patch b/patches/@types+archiver+6.0.2.patch index 945e1d0956..5a8f12dbd7 100644 --- a/patches/@types+archiver+6.0.2.patch +++ b/patches/@types+archiver+6.0.2.patch @@ -1,12 +1,12 @@ diff --git a/node_modules/@types/archiver/index.d.ts b/node_modules/@types/archiver/index.d.ts -index 00829ac..495887b 100644 +index 00829ac..fab29c9 100644 --- a/node_modules/@types/archiver/index.d.ts +++ b/node_modules/@types/archiver/index.d.ts @@ -106,6 +106,7 @@ declare namespace archiver { interface CoreOptions { statConcurrency?: number | undefined; -+ followSymlinks?: true ++ followSymlinks?: boolean } interface TransformOptions { From 51437f9fe9e2a21ae31405e4c8b5afcb4d080b37 Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Thu, 29 May 2025 11:11:31 +0200 Subject: [PATCH 5/5] Add new option to tests --- cli/lib/tests/archive.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/lib/tests/archive.test.ts b/cli/lib/tests/archive.test.ts index bb59ac32d0..aeaac1cfd5 100644 --- a/cli/lib/tests/archive.test.ts +++ b/cli/lib/tests/archive.test.ts @@ -48,7 +48,10 @@ describe( 'Archive Module', () => { const result = await createArchive( mockSiteFolder, mockArchivePath ); expect( fs.createWriteStream ).toHaveBeenCalledWith( mockArchivePath ); - expect( archiver ).toHaveBeenCalledWith( 'zip', { zlib: { level: 9 } } ); + expect( archiver ).toHaveBeenCalledWith( 'zip', { + followSymlinks: true, + zlib: { level: 9 }, + } ); expect( mockArchiver.pipe ).toHaveBeenCalledWith( mockWriteStream ); expect( path.join ).toHaveBeenCalledWith( mockSiteFolder, 'wp-content' ); expect( mockArchiver.directory ).toHaveBeenCalledWith(