ファイル形式をzipしか受け入れないようにチェックするバリデーションを追加#4476
Open
otsuka-star wants to merge 1 commit into
Open
Conversation
teratai3
reviewed
Jul 22, 2026
| 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)) { |
Contributor
There was a problem hiding this comment.
すでに extract メソッドは他の箇所でも使われており、このMIME typeのチェックは、ほぼセットで呼び出す必要があると認識しています。
このPRいただいた形だと、今後ほかの箇所で対応する際にも同じ処理をコピーする前提になっており、修正漏れや後から処理を変更するコスト高そうです。
AIで実装する場合も既存コードを参考にすることが多いため、明確な指示をしない限り、同じ形で処理が増えていく可能性はありそうです。
- https://github.com/baserproject/basercms/blob/5.2.8/plugins/baser-core/src/Service/ThemesService.php#L155
- https://github.com/baserproject/basercms/blob/5.2.8/plugins/baser-core/src/Service/PluginsService.php#L360
※ updateCoreFiles は、固定のzipなので、必須ではありませんが、ここでもextractは呼び出されています。
Contributor
There was a problem hiding this comment.
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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@ryuring
MIMEタイプをチェックして、zipしか受け入れないようにバリデーションを追加しました。ご確認宜しくお願いします!