-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/soap: Add test for Set-Cookie option parsing bug. #21400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+66
−5
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --TEST-- | ||
| SOAP Set-Cookie option parsing starts at wrong offset due to variable shadowing | ||
| --EXTENSIONS-- | ||
| soap | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) { | ||
| echo "skip sapi/cli/tests/php_cli_server.inc required but not found"; | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc"; | ||
|
|
||
| $args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX]; | ||
| if (php_ini_loaded_file()) { | ||
| $args[] = "-c"; | ||
| $args[] = php_ini_loaded_file(); | ||
| } | ||
|
|
||
| // A 10-char name makes the wrong offset land exactly on the value "path=/evil", | ||
| // falsely matching it as a path attribute. | ||
| $code = <<<'PHP' | ||
| header("Content-Type: text/xml"); | ||
| header("Set-Cookie: sessionkey=path=/evil;domain=good.com"); | ||
| echo <<<XML | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="test-uri"> | ||
| <SOAP-ENV:Body> | ||
| <ns1:testResponse/> | ||
| </SOAP-ENV:Body> | ||
| </SOAP-ENV:Envelope> | ||
| XML; | ||
| PHP; | ||
|
|
||
| php_cli_server_start($code, null, $args); | ||
|
|
||
| $client = new SoapClient(null, [ | ||
| 'location' => 'http://' . PHP_CLI_SERVER_ADDRESS . '/test/endpoint', | ||
| 'uri' => 'test-uri', | ||
| 'trace' => true, | ||
| ]); | ||
|
|
||
| try { | ||
| $client->__soapCall("test", []); | ||
| } catch (SoapFault $e) { | ||
| // Response parsing may fault, cookies are still stored | ||
| } | ||
|
|
||
| $cookies = $client->__getCookies(); | ||
|
|
||
| // path should default to "/test" from the request URI, not "/evil" from the value. | ||
| echo "value: " . $cookies['sessionkey'][0] . "\n"; | ||
| echo "path: " . $cookies['sessionkey'][1] . "\n"; | ||
| echo "domain: " . $cookies['sessionkey'][2] . "\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| value: path=/evil | ||
| path: /test | ||
| domain: good.com |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this shadowed var is wrong: it will cause the loop advancement at line 1065 to be wrong: that line is supposed to skip the entire header value. Perhaps this shadowed variable should be renamed cookie_value_len.