From c19484fc9ad5cb9a62f8cca49bce42bef20f7595 Mon Sep 17 00:00:00 2001 From: otsuka Date: Wed, 22 Jul 2026 18:22:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=E3=82=92zip=E3=81=97=E3=81=8B=E5=8F=97?= =?UTF-8?q?=E3=81=91=E5=85=A5=E3=82=8C=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Service/PluginsService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Service/PluginsService.php b/plugins/baser-core/src/Service/PluginsService.php index 5b3787cfb2..b42a291ec6 100644 --- a/plugins/baser-core/src/Service/PluginsService.php +++ b/plugins/baser-core/src/Service/PluginsService.php @@ -701,7 +701,9 @@ public function add(array $postData) $name = $postData['file']->getClientFileName(); $postData['file']->moveTo(TMP . $name); $zip = new BcZip(); - if (!$zip->extract(TMP . $name, TMP)) { + $finfo = new \finfo(FILEINFO_MIME_TYPE); + $mimeType = $finfo->file(TMP . $name); + if (!in_array($mimeType, ['application/zip', 'application/x-zip-compressed'], true) || !$zip->extract(TMP . $name, TMP)) { throw new BcException(__d('baser_core', 'アップロードしたZIPファイルの展開に失敗しました。')); } $srcDirName = $zip->topArchiveName; From 9254464155ee0010b04964ca8f065b6ce4770b80 Mon Sep 17 00:00:00 2001 From: otsuka Date: Mon, 27 Jul 2026 18:47:42 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[=20PluginsService.php=20]=20=E3=83=BBMIME?= =?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4=E3=81=AE=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=81=A8=E3=80=81ZIP=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=B1=95=E9=96=8B=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=82=B1=E3=83=BC=E3=82=B9=E3=82=92=E5=88=86=E3=81=91?= =?UTF-8?q?=E3=82=8B=20=E3=83=BB=E4=BE=8B=E5=A4=96=E5=89=8D=E3=81=AF?= =?UTF-8?q?=EF=BC=91=E6=99=82=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4=EF=BC=88=EF=BC=89=20[=20PluginsServiceTest.p?= =?UTF-8?q?hp=20]=20=E3=83=BBMIME=E4=B8=8D=E4=B8=80=E8=87=B4=E3=81=AE?= =?UTF-8?q?=E9=9A=9B=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baser-core/src/Service/PluginsService.php | 11 +++++- .../TestCase/Service/PluginsServiceTest.php | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Service/PluginsService.php b/plugins/baser-core/src/Service/PluginsService.php index b42a291ec6..5988255cff 100644 --- a/plugins/baser-core/src/Service/PluginsService.php +++ b/plugins/baser-core/src/Service/PluginsService.php @@ -703,7 +703,16 @@ public function add(array $postData) $zip = new BcZip(); $finfo = new \finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file(TMP . $name); - if (!in_array($mimeType, ['application/zip', 'application/x-zip-compressed'], true) || !$zip->extract(TMP . $name, TMP)) { + if (!in_array($mimeType, ['application/zip', 'application/x-zip-compressed'], true)) { + if (file_exists(TMP . $name)) { + unlink(TMP . $name); + } + throw new BcException(__d('baser_core', 'ZIPファイルをアップロードしてください。')); + } + if (!$zip->extract(TMP . $name, TMP)) { + if (file_exists(TMP . $name)) { + unlink(TMP . $name); + } throw new BcException(__d('baser_core', 'アップロードしたZIPファイルの展開に失敗しました。')); } $srcDirName = $zip->topArchiveName; diff --git a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php index d21c1117c3..1f5b2b2b01 100644 --- a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php @@ -469,6 +469,41 @@ public function test_add() // $this->Plugins->add(["file" => $files]); } + /** + * test add ZIP以外のファイルをアップロードした場合 + * @return void + */ + public function test_addRejectsNonZipFile() + { + $zipSrcPath = TMP . 'zip' . DS; + $folder = new BcFolder($zipSrcPath); + $folder->create(); + //架空のプラグイン名を指定して、ZIP以外のファイルを作成 + $plugin = 'NotZipPlugin'; + $testFile = $zipSrcPath . $plugin . '.zip'; + file_put_contents($testFile, 'This is not a zip file.'); + $size = filesize($testFile); + + $this->setUploadFileToRequest('file', $testFile); + $files = new UploadedFile( + $testFile, + $size, + UPLOAD_ERR_OK, + $plugin . '.zip', + 'text/plain' + ); + + $this->expectException("BaserCore\Error\BcException"); + $this->expectExceptionMessage("ZIPファイルをアップロードしてください。"); + try { + $this->Plugins->add(["file" => $files]); + } finally { + // アップロードされた一時ファイルが削除されていること + $this->assertFileDoesNotExist(TMP . $plugin . '.zip'); + $folder->delete(); + } + } + /** * test getAvailableCoreVersionInfo * @return void From ef247517419a5f1e172816272f11bbe2bcfd19c1 Mon Sep 17 00:00:00 2001 From: otsuka Date: Fri, 31 Jul 2026 12:36:16 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test=5FaddRejectsNonZipFile()=20=E3=82=92?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AE=E6=9C=AB=E5=B0=BE=E3=81=AB?= =?UTF-8?q?=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Service/PluginsServiceTest.php | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php index 1f5b2b2b01..79a35e390e 100644 --- a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php @@ -469,41 +469,6 @@ public function test_add() // $this->Plugins->add(["file" => $files]); } - /** - * test add ZIP以外のファイルをアップロードした場合 - * @return void - */ - public function test_addRejectsNonZipFile() - { - $zipSrcPath = TMP . 'zip' . DS; - $folder = new BcFolder($zipSrcPath); - $folder->create(); - //架空のプラグイン名を指定して、ZIP以外のファイルを作成 - $plugin = 'NotZipPlugin'; - $testFile = $zipSrcPath . $plugin . '.zip'; - file_put_contents($testFile, 'This is not a zip file.'); - $size = filesize($testFile); - - $this->setUploadFileToRequest('file', $testFile); - $files = new UploadedFile( - $testFile, - $size, - UPLOAD_ERR_OK, - $plugin . '.zip', - 'text/plain' - ); - - $this->expectException("BaserCore\Error\BcException"); - $this->expectExceptionMessage("ZIPファイルをアップロードしてください。"); - try { - $this->Plugins->add(["file" => $files]); - } finally { - // アップロードされた一時ファイルが削除されていること - $this->assertFileDoesNotExist(TMP . $plugin . '.zip'); - $folder->delete(); - } - } - /** * test getAvailableCoreVersionInfo * @return void @@ -870,4 +835,39 @@ public function test_getCoreUpdate_vulnerability() $this->assertFalse(file_exists($rceFile), 'getCoreUpdate でOSコマンドインジェクションが発生しました'); } + + /** + * test add ZIP以外のファイルをアップロードした場合 + * @return void + */ + public function test_addRejectsNonZipFile() + { + $zipSrcPath = TMP . 'zip' . DS; + $folder = new BcFolder($zipSrcPath); + $folder->create(); + //架空のプラグイン名を指定して、ZIP以外のファイルを作成 + $plugin = 'NotZipPlugin'; + $testFile = $zipSrcPath . $plugin . '.zip'; + file_put_contents($testFile, 'This is not a zip file.'); + $size = filesize($testFile); + + $this->setUploadFileToRequest('file', $testFile); + $files = new UploadedFile( + $testFile, + $size, + UPLOAD_ERR_OK, + $plugin . '.zip', + 'text/plain' + ); + + $this->expectException("BaserCore\Error\BcException"); + $this->expectExceptionMessage("ZIPファイルをアップロードしてください。"); + try { + $this->Plugins->add(["file" => $files]); + } finally { + // アップロードされた一時ファイルが削除されていること + $this->assertFileDoesNotExist(TMP . $plugin . '.zip'); + $folder->delete(); + } + } }