Limit maximum number of filter chains - #22110
Conversation
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
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.
Parallel to this work, the stream_errors RFC was accepted and merged. Use the new API php_stream_wrapper_log_warn to report the error of too many filters.
|
It's looking pretty good for the RFC, so it would be nice to get a review of this PR. |
|
RFC is accepted. @bukka could you review this? |
|
Will check this or next weekend hopefully. |
|
@bukka Could you review this please? |
|
@LamentXU123 , @arnaud-lb Could one of you perhaps review this pull request? |
LamentXU123
left a comment
There was a problem hiding this comment.
Sorry for the late response and thank you for your work.
I am not an expert in this topic so just my 2 cents
When both read_chain and write_chain are true, also count the number of write filters and give a deprecation warning when that is exceeded.
Do the counting in php_stream_apply_filter_list and stop adding filters when the limit is reached, instead of adding them all first.
|
@Sjord Thanks. Now please wait for others reviews on this topic because i am not an expert on this.Also keep my reviews unresolved because I want to hear from others opinions. This looks good to me :) |
TimWolla
left a comment
There was a problem hiding this comment.
Didn't actually look at the code, but these stood out. There might be more cases where you're using spaces instead of tabs.
Instead of counting the number of items in the chain every time we add a filter to the chain, keep an attribute `count` to determine the number of filters already on the chain.
Negative values now disable the limit.
arnaud-lb
left a comment
There was a problem hiding this comment.
Looks good to me otherwise!
LamentXU123
left a comment
There was a problem hiding this comment.
Awaiting Jakub for final review 👍
|
@bukka Could you review/merge this? |
This is an implementation suggestion for the RFC to limit the maximum number of filters in a
php://filterURL.