Skip to content

Limit maximum number of filter chains#22110

Open
Sjord wants to merge 4 commits into
php:masterfrom
Sjord:limit_filters
Open

Limit maximum number of filter chains#22110
Sjord wants to merge 4 commits into
php:masterfrom
Sjord:limit_filters

Conversation

@Sjord
Copy link
Copy Markdown

@Sjord Sjord commented May 21, 2026

jvoisin and others added 2 commits May 13, 2026 15:21
Chaining filters is becoming an increasingly popular primitive to exploit PHP
applications. Limiting the usage of only a few of them at the time should,
if not close entirely, make it significantly less attractive.

This should close php#10453
Limit number of filters that can be chained in a php://filter URL.

Count number of filters already on the stream, instead of counting iterations on the loop. When filters are separated by slash instead of pipe, php_stream_apply_filter_list is called muliple times, so counting iterations won't work. Instead, count numbers of filters already on the chain.
Add more elaborate test that tests:
- file read
- file include
- no warning on stream_filter_append

Related to:
php#10453
php#16699
Sjoerd Langkemper added 2 commits May 22, 2026 11:46
Read the maximum number of filters from context stream. If it is set, it
doesn't make sense to raise a deprecation warning, because this stream
context option didn't exist earlier. We raise an error consistent with
current stream handling, as long as rfc/stream_errors has not landed.

If it is not set, we give a deprecation warning when the 17th filter is
added. This is unfortunately done in another place; to prevent showing
warnings multiple times, the counting is done within the loop and not at
the end.
We get a zend_long from the stream context, so it makes sense to
consistently use it for all counts of filters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants