Backport view path containment check for CVE-2026-48820 - #22
Merged
Merged
Conversation
Reject view, layout, element, and scaffold template paths that resolve outside configured view roots. Add regression coverage and prepare the v1.2.0 release.
Owner
Author
|
CI status note: all four matrix jobs stopped before running tests during Composer dependency resolution. Current Composer blocks the repository's existing cakephp/cakephp-codesniffer 1.x dependency because it requires PHPCS 1.x versions covered by PKSA-rdkp-vv9z-mjkg and PKSA-6vdd-n4sx-knhy. This is independent of the five-file CVE backport. Local PHP 8.2 verification completed successfully for both modified files (syntax), the six focused regression tests (10 assertions), and the complete ViewTest suite (87 tests, 172 assertions). |
This was referenced Aug 26, 2026
basi
marked this pull request as ready for review
August 28, 2026 04:39
shin2ro
approved these changes
Sep 3, 2026
| } | ||
| foreach ($this->_paths($plugin) as $path) { | ||
| if (strpos($absolute, rtrim($path, DS) . DS) === 0) { | ||
| return $file; |
| } | ||
| $root = realpath($path); | ||
| if ($root !== false && strpos($absolute, rtrim($root, DS) . DS) === 0) { | ||
| return $file; |
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.
Problem
CVE-2026-48820 / GHSA-wpvj-hjcr-h3p2 allows a request-controlled element name containing
../to make CakePHP include a PHP template outside the configured view template paths. CakePHP fixed the issue in 4.5.11 with cakephp/cakephp@2af17bd02, but CakePHP 2.x is EOL and requires a backport.This fork is used by
bask/cakephpin production, so leaving Dependabot alert #6 unresolved exposes applications that pass request data into view resolution to local file inclusion of.ctpfiles.Changes
View::_checkFilePath()with a no-..fast path and canonical containment checks against all configured view template roots.ScaffoldViewoverride.elementExists()compatibility note in the changelog.Deliberate deviation from upstream
The upstream implementation compares the canonical candidate path with raw configured roots. This backport also compares it with
realpath()of each root and normalizes the trailing directory separator.The additional comparison preserves valid
../templates in deployments whose configured view root contains a symlink, such ascurrent -> releases/N. It is additive: a path is accepted only when its canonical target is actually contained by a configured canonical root. The separator normalization also prevents prefix collisions such as/app/Viewand/app/ViewX.Compatibility and BC notes
realpath()cost because paths without..return immediately.bask/cakephphas no..view/element calls,elementExists()calls, custom view roots, or themes, so no consumer impact is expected.elementExists()now throwsInvalidArgumentExceptionfor an existing template that resolves outside all view roots instead of returningfalse. This matches CakePHP 4.5.11...can follow an outward symlink inside a view root;realpath()failure is passed through; and a filesystem race remains possible between validation and inclusion.Test plan
InvalidArgumentException.git diff --checklib/Cake/View/View.phpandlib/Cake/View/ScaffoldView.phpViewTest: 87 tests, 172 assertions — pass with 5 pre-existing PHPUnit deprecation warningsAllTestsTestwas attempted and stopped at 1,952 / 4,078 tests on the unrelated existing PHP 8.2 deprecationCreation of dynamic property FormHelperTest::$db is deprecated.GitHub Actions remains the final matrix gate for PHP 8.0/8.2 with MySQL, PostgreSQL, and SQLite.
Post-merge steps
mainpush triggerbump-version.ymlto create the v1.2.0 tag and release, with theelementExists()BC note in the release notes.bask/cakephp, updatebasi/cakephp2-php8and verify thatlib/Cake/View/View.phpis refreshed in the dependency-copy diff.kamilwylegala/cakephp2-php8.