Don't flag php:// stream wrappers as remote requests - #896
Open
GaryJones wants to merge 1 commit into
Open
Conversation
FetchingRemoteData treated any `file_get_contents()` argument containing `://` as a remote request and steered users towards `wpcom_vip_file_get_contents()` / `vip_safe_wp_remote_get()`. That misfires for PHP's `php://` stream wrappers, which are local, in-process streams rather than remote HTTP requests. `php://input` in particular is the canonical, unavoidable way to read a raw request body (for example when handling a webhook), so the warning was a false positive with no valid alternative to offer. Exempt the case-insensitive `php://` scheme from the remote-file check. A `php://` substring that is not the URL scheme (such as a query-string value on an https URL) is still flagged. Fixes #506.
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
The
WordPressVIPMinimum.Performance.FetchingRemoteDatasniff discourages remote requests made throughfile_get_contents(), pointing developers towardswpcom_vip_file_get_contents()orvip_safe_wp_remote_get()instead. It decided a call was remote by looking for://anywhere in the string argument.That heuristic misfires on PHP's
php://stream wrappers.php://input,php://stdin,php://memory,php://tempand friends are local, in-process streams, not remote HTTP requests, so neither suggested alternative applies.php://inputis especially awkward: it is the canonical (and effectively unavoidable) way to read a raw request body, for example when handling an incoming webhook, and there is no VIP helper that replaces it. The result was a warning the developer could only silence with an ignore annotation.This change exempts the
php://scheme from the remote-file check. Matching is anchored to the start of the string and is case-insensitive, soPHP://inputis also recognised, while aphp://substring that is not the URL scheme (such as a query-string value on anhttps://URL) continues to be flagged as remote.Fixes #506.
Test plan
Unit tests are included in
FetchingRemoteDataUnitTest.inc/.phpcovering the exempted wrappers, the case-insensitive scheme, and the regression guard that a maskedphp://substring on a genuine remote URL is still flagged.composer test -- --filter FetchingRemoteData