-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/soap: Fix SOAP classmap validation for integer keys #22884
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6daf60a
ext/soap: Fix SOAP classmap validation for integer keys
LamentXU123 b49aaf4
Change to ValueError
LamentXU123 a2232d4
fix CI
LamentXU123 b92b376
Reject invalid classmap earlier
LamentXU123 2c3a3d8
Update soap.c
LamentXU123 e44f283
Apply suggestions from code review
LamentXU123 d7dbe19
feedback
LamentXU123 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
Some comments aren't visible on the classic Files Changed page.
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
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
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,68 @@ | ||
| --TEST-- | ||
| SoapClient and SoapServer classmap options must only contain string keys | ||
| --EXTENSIONS-- | ||
| soap | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $emptyHash = ['type' => 'stdClass']; | ||
| unset($emptyHash['type']); | ||
|
|
||
| $cases = [ | ||
| 'empty' => [], | ||
| 'empty hash' => $emptyHash, | ||
| 'packed' => ['stdClass'], | ||
| 'sparse numeric' => [100 => 'stdClass'], | ||
| 'numeric string' => ['1' => 'stdClass'], | ||
| 'mixed' => ['type' => 'stdClass', 1 => 'stdClass'], | ||
| 'associative' => ['type' => 'stdClass'], | ||
| ]; | ||
|
|
||
| foreach ($cases as $name => $classmap) { | ||
| echo "-- $name --\n"; | ||
|
|
||
| try { | ||
| new SoapClient(null, [ | ||
| 'location' => 'http://example.com/', | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => $classmap, | ||
| ]); | ||
| echo "SoapClient: OK\n"; | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| new SoapServer(null, [ | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => $classmap, | ||
| ]); | ||
| echo "SoapServer: OK\n"; | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| -- empty -- | ||
| SoapClient: OK | ||
| SoapServer: OK | ||
| -- empty hash -- | ||
| SoapClient: OK | ||
| SoapServer: OK | ||
| -- packed -- | ||
| ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| -- sparse numeric -- | ||
| ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| -- numeric string -- | ||
| ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| -- mixed -- | ||
| ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| -- associative -- | ||
| SoapClient: OK | ||
| SoapServer: OK |
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,32 @@ | ||
| --TEST-- | ||
| SoapClient and SoapServer report an invalid classmap option as ValueError | ||
| --EXTENSIONS-- | ||
| soap | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $classmap = ['type' => 'stdClass', 1 => 'stdClass']; | ||
|
|
||
| try { | ||
| new SoapClient(null, [ | ||
| 'location' => 'http://example.com/', | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => $classmap, | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| echo 'SoapClient: ', $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| new SoapServer(null, [ | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => $classmap, | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| echo 'SoapServer: ', $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| SoapClient: ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array | ||
| SoapServer: ValueError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be an associative array |
21 changes: 21 additions & 0 deletions
21
ext/soap/tests/classmap_invalid_keys_exceptions_disabled.phpt
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,21 @@ | ||
| --TEST-- | ||
| SoapClient reports an invalid classmap option as ValueError when exceptions are disabled | ||
| --EXTENSIONS-- | ||
| soap | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| try { | ||
| new SoapClient(null, [ | ||
| 'location' => 'http://example.com/', | ||
| 'uri' => 'urn:test', | ||
| 'exceptions' => false, | ||
| 'classmap' => ['type' => 'stdClass', 1 => 'stdClass'], | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| ValueError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be an associative array |
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,30 @@ | ||
| --TEST-- | ||
| SoapClient and SoapServer classmap options must be arrays | ||
| --EXTENSIONS-- | ||
| soap | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| try { | ||
| new SoapClient(null, [ | ||
| 'location' => 'http://example.com/', | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => 1, | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| echo 'SoapClient: ', $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| new SoapServer(null, [ | ||
| 'uri' => 'urn:test', | ||
| 'classmap' => 1, | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| echo 'SoapServer: ', $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| SoapClient: TypeError: SoapClient::__construct(): Argument #2 ($options) "classmap" option must be of type array, int given | ||
| SoapServer: TypeError: SoapServer::__construct(): Argument #2 ($options) "classmap" option must be of type array, int given |
45 changes: 45 additions & 0 deletions
45
ext/soap/tests/classmap_private_property_packed_array.phpt
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,45 @@ | ||
| --TEST-- | ||
| SoapClient must not read packed private classmap as string-keyed map | ||
| --EXTENSIONS-- | ||
| soap | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class LocalSoapClient extends SoapClient { | ||
| public function __doRequest($request, $location, $action, $version, $one_way = false, ?string $uriParserClass = null): string { | ||
| echo "__doRequest called\n"; | ||
|
|
||
| return <<<'XML' | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | ||
| <SOAP-ENV:Body> | ||
| <SOAP-ENV:Fault> | ||
| <faultcode>SOAP-ENV:Server</faultcode> | ||
| <faultstring>expected fault</faultstring> | ||
| </SOAP-ENV:Fault> | ||
| </SOAP-ENV:Body> | ||
| </SOAP-ENV:Envelope> | ||
| XML; | ||
| } | ||
| } | ||
|
|
||
| class Foo {} | ||
|
|
||
| $client = new LocalSoapClient(null, [ | ||
| 'location' => 'http://example.org/', | ||
| 'uri' => 'http://example.org/', | ||
| ]); | ||
|
|
||
| $property = new ReflectionProperty(SoapClient::class, '_classmap'); | ||
| $property->setValue($client, ['Foo']); | ||
|
|
||
| try { | ||
| $client->__soapCall('foo', [new Foo()]); | ||
| } catch (SoapFault) { | ||
| echo "SOAP Fault thrown\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| __doRequest called | ||
| SOAP Fault thrown |
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.
it might be preferable to throw if this is not an array