Work around parse_url() bug (bis)#58836
Merged
nicolas-grekas merged 1 commit intosymfony:5.4from Nov 13, 2024
Merged
Conversation
6c067aa to
5e3509b
Compare
xabbuh
reviewed
Nov 12, 2024
parse_url() bug (bis)
0cbc0dd to
6cd3610
Compare
Member
Author
|
PR ready. I figured out a way to fix #58313 |
nicolas-grekas
commented
Nov 13, 2024
| $scheme = $parts['scheme'] ?? null; | ||
| $host = $parts['host'] ?? null; | ||
|
|
||
| if (!$scheme && $host && !str_starts_with($url, '//')) { |
Member
Author
There was a problem hiding this comment.
I wondered if we could add the same logic to Request::create() but we have a test case that ensure Request::create("test.com:80") is parsed as host+port (which is not how the URL spec would parse it)
|
|
||
| [$host, $port] = self::parseHostPort($url, $info); | ||
|
|
||
| if (false !== (parse_url($location.'#', \PHP_URL_HOST) ?? false)) { |
Member
Author
There was a problem hiding this comment.
stop using parse_url on user-input
| curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false); | ||
| curl_setopt($ch, \CURLOPT_MAXREDIRS, $options['max_redirects']); | ||
| } else { | ||
| $url = parse_url($location ?? ':'); |
Member
Author
There was a problem hiding this comment.
stop using parse_url on user-input here also
| unset($server['HTTPS']); | ||
| $server['SERVER_PORT'] = 80; | ||
| } else { | ||
| throw new BadRequestException('Invalid URI: http(s) scheme expected.'); |
Member
Author
There was a problem hiding this comment.
looks like a missing check here, Request::create('random-scheme:foo') cannot give port 80
6cd3610 to
80257ea
Compare
This was referenced Nov 27, 2024
Merged
Merged
Closed
Merged
Merged
1 task
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.
This PR is a follow up of #58218
parse_url behaves incorrectly when parsing some URLs that don't contain
?or#.This PR ensures that one of those chars is always found when calling the function.