Skip to content

ファイル形式をzipしか受け入れないようにチェックするバリデーションを追加 - #4476

Merged
ryuring merged 5 commits into
baserproject:5.3.xfrom
otsuka-star:5.3.x-168
Aug 26, 2026
Merged

ファイル形式をzipしか受け入れないようにチェックするバリデーションを追加#4476
ryuring merged 5 commits into
baserproject:5.3.xfrom
otsuka-star:5.3.x-168

Conversation

@otsuka-star

Copy link
Copy Markdown
Contributor

@ryuring

MIMEタイプをチェックして、zipしか受け入れないようにバリデーションを追加しました。ご確認宜しくお願いします!

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)) {

@teratai3 teratai3 Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すでに extract メソッドは他の箇所でも使われており、このMIME typeのチェックは、ほぼセットで呼び出す必要があると認識しています。
このPRいただいた形だと、今後ほかの箇所で対応する際にも同じ処理をコピーする前提になっており、修正漏れや後から処理を変更するコスト高そうです。
AIで実装する場合も既存コードを参考にすることが多いため、明確な指示をしない限り、同じ形で処理が増えていく可能性はありそうです。

※ updateCoreFiles は、固定のzipなので、必須ではありませんが、ここでもextractは呼び出されています。

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

プラグインアップロード(PluginsService::add())に対して、アップロードされたファイルのMIMEタイプを検査し、ZIP形式のみ受け付けるようにすることで、誤ったファイル形式の混入を早期に弾くことを目的としたPRです。

Changes:

  • アップロードされた一時ファイルのMIMEタイプを finfo(FILEINFO_MIME_TYPE) で判定する処理を追加
  • ZIP(application/zip, application/x-zip-compressed)以外の場合に展開処理へ進まないようガードを追加

Comment thread plugins/baser-core/src/Service/PluginsService.php Outdated
Comment thread plugins/baser-core/src/Service/PluginsService.php Outdated
@ryuring ryuring assigned otsuka-star and unassigned ryuring, kaburk and katokaisya Jul 25, 2026
otsuka-star and others added 4 commits July 27, 2026 18:47
・MIME不一致のケースと、ZIPファイルの展開に失敗したケースを分ける
・例外前は1時ファイルを削除()
[ PluginsServiceTest.php ]
・MIME不一致の際のテストの追加
- ext-fileinfo が無効な環境で finfo クラスが存在せず致命的エラーになるため、
  class_exists() でガードし、判定できない場合は展開時のエラーに委ねるようにした。
  レンタルサーバー等で無効化されている可能性があるため、require ではなく
  suggest に記載して任意依存として扱う。
  既存の BcBlog RssHelper も function_exists('mime_content_type') で
  同様にガードしている。
- 「ZIPファイルをアップロードしてください。」を英語の翻訳ファイルに追加。
  同じメソッド内の既存メッセージは登録済みのため揃えた。
- application/x-zip-compressed はブラウザが申告する MIME であり finfo が
  返す値ではない旨をコメントで補足。誤解を避けるため残しつつ意図を明示した。
- 失敗時のテンポラリファイル削除が2箇所に重複していたため、try/catch で
  1箇所にまとめた。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ryuring

ryuring commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

取り急ぎは、本件だけを対象としてコミット内容を調整しました。
テストも通りましたのでマージします。

@ryuring
ryuring merged commit ed12806 into baserproject:5.3.x Aug 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants