[5.4] Prevent PHAR stub detection bypass across InputFilter chunk boundaries#47952
Open
saddamr3e wants to merge 1 commit into
Open
[5.4] Prevent PHAR stub detection bypass across InputFilter chunk boundaries#47952saddamr3e wants to merge 1 commit into
saddamr3e wants to merge 1 commit into
Conversation
saddamr3e
force-pushed
the
inputfilter-boundary-scan-bypass
branch
from
June 13, 2026 18:32
f849e67 to
4f52f9b
Compare
Author
|
any update? |
Contributor
|
Hi @saddamr3e, thank you for your contribution. This PR is still awaiting two human tests/code reviews. As with many parts of the project, reviews depend on volunteer availability. |
Author
|
Understood, will wait. For anyone picking this up to test: the bundled unit tests reproduce the boundary case directly (libraries/vendor/bin/phpunit tests/Unit/Libraries/Cms/Filter/InputFilterTest.php). The two phar-stub tests fail without the InputFilter change and pass with it. |
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.
Summary of Changes
InputFilter::isSafeFile()scans uploaded file contents in 131072-byte (128 KB) chunks. To catch a dangerous signature that lands across the boundary between two reads, it carried over the tail of each read into the next one — but only a fixed 10 bytes. That value was sized for<?php(5 bytes) and never updated when the longer__HALT_COMPILER()phar-stub check (17 bytes, enabled by default viaphar_stub_in_content) was added to the same loop.As a result, a phar stub aligned so that 11 or more of its 17 bytes fall before a 128 KB boundary is split across two reads and never detected, so the file passes the content scan.
This change computes the carry-over (
$scanOverlap) from the longest signature actually being scanned given the current options, instead of a magic number. For the default options that isstrlen('__HALT_COMPILER()') - 1 = 16. It also stays correct automatically if the forbidden-extension list or signature set changes.Files:
libraries/src/Filter/InputFilter.php— compute$scanOverlap; replacesubstr($data, -10)withsubstr($data, -$scanOverlap).tests/Unit/Libraries/Cms/Filter/InputFilterTest.php— new regression tests.Testing Instructions
Run the bundled unit tests:
Actual result BEFORE applying this Pull Request
isSafeFile()returnstrue(file considered safe) the phar stub spanning the read boundary is not detected and the new unit tests fail.Expected result AFTER applying this Pull Request
isSafeFile()returnsfalse(file rejected) the phar stub is detected regardless of where it falls relative to the read boundary Large benign files containing none of the scanned signatures are still accepted (no false positives) All new unit tests passLink to documentations
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed