Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins/baser-core/src/Service/PluginsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,18 @@ public function add(array $postData)
$name = $postData['file']->getClientFileName();
$postData['file']->moveTo(TMP . $name);
$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)) {
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;
Expand Down
35 changes: 35 additions & 0 deletions plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,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();
}
}
}
Loading