Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Client/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public function _doRequest(Common $client, $request, $location, $action, $versio
$this->server->handle($request);
$response = ob_get_clean();

if ($response === null || $response === '') {
$serverResponse = $this->server->getResponse();
if ($serverResponse !== null) {
$response = $serverResponse;
}
}

return $response;
}
}
18 changes: 15 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ protected function _setRequest($request)
if (strlen($xml) == 0 || !$dom->loadXML($xml)) {
throw new Exception\InvalidArgumentException('Invalid XML');
}
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader(false);
}
$this->request = $xml;
Expand Down Expand Up @@ -791,16 +798,16 @@ public function handle($request = null)

$soap = $this->_getSoap();

$fault = false;
ob_start();
if ($setRequestException instanceof \Exception) {
// Send SOAP fault message if we've catched exception
$soap->fault('Sender', $setRequestException->getMessage());
// Create SOAP fault message if we've caught a request exception
$fault = $this->fault($setRequestException->getMessage(), 'Sender');
} else {
try {
$soap->handle($this->request);
} catch (\Exception $e) {
$fault = $this->fault($e);
$soap->fault($fault->faultcode, $fault->faultstring);
}
}
$this->response = ob_get_clean();
Expand All @@ -809,6 +816,11 @@ public function handle($request = null)
restore_error_handler();
ini_set('display_errors', $displayErrorsOriginalState);

// Send a fault, if we have one
if ($fault) {
$this->response = $fault;
}

if (!$this->returnResponse) {
echo $this->response;
return;
Expand Down
7 changes: 7 additions & 0 deletions src/Wsdl.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, a
if (!$this->dom->loadXML($wsdl)) {
throw new Exception\RuntimeException('Unable to create DomDocument');
} else {
foreach ($this->dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\RuntimeException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
$this->wsdl = $this->dom->documentElement;
}
libxml_disable_entity_loader(false);
Expand Down
30 changes: 30 additions & 0 deletions test/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,34 @@ public function testHandleUsesProperRequestParameter()
$r = $server->handle(new \DOMDocument('1.0', 'UTF-8'));
$this->assertTrue(is_string($server->mockSoapServer->handle[0]));
}

/**
* @runInSeparateProcess
*/
public function testShouldThrowExceptionIfHandledRequestContainsDoctype()
{
$server = new Server();
$server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
$server->setReturnResponse(true);

$server->setClass('\ZendTest\Soap\TestAsset\ServerTestClass');

$request =
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<!DOCTYPE foo>' . "\n"
. '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
. 'xmlns:ns1="http://framework.zend.com" '
. 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
. 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
. 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
. 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
. '<SOAP-ENV:Body>'
. '<ns1:testFunc2>'
. '<param0 xsi:type="xsd:string">World</param0>'
. '</ns1:testFunc2>'
. '</SOAP-ENV:Body>'
. '</SOAP-ENV:Envelope>' . "\n";
$response = $server->handle($request);
$this->assertContains('Invalid XML', $response->getMessage());
}

}

0 comments on commit ec85470

Please sign in to comment.