Skip to content

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

Open
otsuka-star wants to merge 1 commit into
baserproject:5.3.xfrom
otsuka-star:5.3.x-168
Open

ファイル形式をzipしか受け入れないようにチェックするバリデーションを追加#4476
otsuka-star wants to merge 1 commit 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 on lines +706 to 708
if (!in_array($mimeType, ['application/zip', 'application/x-zip-compressed'], true) || !$zip->extract(TMP . $name, TMP)) {
throw new BcException(__d('baser_core', 'アップロードした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)) {
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