Repository navigation
Fix in-place URL decoding of interned userinfo in the http and ftp wrappers - #24341
Open
alepacheco wants to merge 1 commit into
Open
alepacheco wants to merge 1 commit into
alepacheco wants to merge 1 commit into
Conversation
…appers The http and ftp stream wrappers decoded the user and password (and, when checking a redirect, the path) of the parsed URL in place. The components of a php_uri may be interned strings (the WHATWG parser returns one-character usernames and passwords as interned single-char strings, the RFC 3986 parser returns the path "/" as one), so decoding a redirect target such as http://+@host/ rewrote the shared "+" string for the whole process. Decode the components into new strings instead, and build the relative redirect path without writing into the current path.
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.
The http and ftp stream wrappers url-decode the user and password of the parsed URL in place (
php_url_decode(ZSTR_VAL(resource->user), ...)), and the http wrapper does the same for user, password and path when it checks a redirect target for control characters.Since the wrappers take a
php_urifromuri_parser_class, those components can be interned strings: the WHATWG parser returns one-character usernames and passwords throughZVAL_STRINGL_FAST(the interned single-char strings), and the RFC 3986 parser returns the path/withZVAL_CHAR. Withuri_parser_class => Uri\WhatWg\Url, a redirect tohttp://+@host/therefore rewrites the shared"+"string to" "for the rest of the process (with opcache, in shared memory).This changes the wrappers to never write into
php_urifields:http_fopen_wrapper.c: the Basic auth header and the redirect control-character check decode into new strings; the relative redirect path is built from the directory part of the current path instead of truncatingresource->pathin place (same resulting URL as before).ftp_fopen_wrapper.c:USER/PASSare sent from decoded copies.The new test follows a redirect with a one-character username under the WHATWG parser and checks both the
Authorizationheader sent and thatchr(43)is still"+"afterwards.Targeting PHP-8.5, the first branch with
uri_parser_class.