BcZip: ZIP展開時にエントリパス検証を追加(Zip Slip対策)#4300
Merged
ryuring merged 4 commits intobaserproject:5.2.xfrom Jan 16, 2026
Merged
Conversation
ZIP内エントリのパスを事前に検証し、 展開先ディレクトリ配下に収まらないパスを拒否する処理を追加。
There was a problem hiding this comment.
Pull request overview
This PR addresses the Zip Slip (path traversal) vulnerability in the BcZip class by adding validation to ensure ZIP entry paths remain within the intended extraction directory. The implementation follows a defense-in-depth approach by validating paths before extraction regardless of runtime behavior.
Key Changes:
- Added pre-extraction path validation to both
_extractByPhpLiband_extractByCommandmethods - Implemented helper methods for path normalization and safety checks (
_normalizeTargetPath,_normalizeRelativePath,_normalizeAbsolutePath,_isZipEntrySafe,_validateZipEntries) - Added unit tests to verify rejection of malicious ZIP files containing path traversal attempts
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 16 comments.
| File | Description |
|---|---|
| plugins/baser-core/src/Utility/BcZip.php | Implemented ZIP entry path validation logic with new helper methods to detect and reject malicious paths (e.g., ../, absolute paths, null bytes) before extraction |
| plugins/baser-core/tests/TestCase/Utility/BcZipTest.php | Added unit tests for Zip Slip protection, path normalization, and entry safety validation to verify the security fixes work correctly |
指摘の通り、上記を含めるとリスクがあるので、 指摘通り削除します。 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
|
@kaminuma 手動での動作確認も問題ありませんでしたのでマージさせて頂きます。ありがとうございました。 |
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.
概要
BcZipクラスのZIP展開処理において、ZIP内エントリのパスを事前に検証し、
展開先ディレクトリ配下に収まらないエントリを含むZIPを拒否する処理を追加しました。
Zip Slip(パストラバーサル)脆弱性への対策となります。
補足(設計意図)
本PRは、ZIP 展開処理におけるパス検証の欠如を補う目的で、
Defense in Depth の観点から実装したものになります。
変更点
BcZip::_extractByPhpLibおよび_extractByCommandメソッドに、ZIPエントリのパス検証処理を追加しました。$target)配下に収まっているかをチェックします。背景
ZIP展開処理は、実行環境や展開経路(
ZipArchive/unzipコマンド)によって挙動が異なる可能性があります。そのため、ランタイムやライブラリ側の挙動に依存せず、アプリケーション側で明示的にZIPエントリの検証を行うことで、Defense in Depth(多層防御)の観点から安全性を向上させています。
動作確認
1. ユニットテスト
BcZipTest.phpに追加したテストケースが通過することを確認しました。2. 管理画面での動作確認(GUI)
正常系(リグレッション確認)
修正適用後、通常のテーマ・プラグインのアップロード機能に影響がないことを確認しました。
正常なテーマZIPをアップロード → 正常にインストール完了
正常なプラグインZIPをアップロード → 正常にインストール完了
異常系(脆弱性対策確認)
不正なパス(例:
../を含むエントリ)を含むZIPファイルが、適切に拒否されることを確認しました。不正なZIPをアップロード → エラーとなり、展開されないことを確認