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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into useS…
Browse files Browse the repository at this point in the history
…tatementFixes
  • Loading branch information
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Request.php
Expand Up @@ -294,12 +294,16 @@ public function loadXml($request)
return false;
}

// @see ZF-12293 - disable external entities for security purposes
$loadEntities = libxml_disable_entity_loader(true);
try {
$xml = new \SimpleXMLElement($request);
libxml_disable_entity_loader($loadEntities);
} catch (\Exception $e) {
// Not valid XML
$this->_fault = new Fault(631);
$this->_fault->setEncoding($this->getEncoding());
libxml_disable_entity_loader($loadEntities);
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Response.php
Expand Up @@ -167,11 +167,15 @@ public function loadXml($response)
return false;
}

// @see ZF-12293 - disable external entities for security purposes
$loadEntities = libxml_disable_entity_loader(true);
$useInternalXmlErrors = libxml_use_internal_errors(true);
try {
$useInternalXmlErrors = libxml_use_internal_errors(true);
$xml = new \SimpleXMLElement($response);
libxml_disable_entity_loader($loadEntities);
libxml_use_internal_errors($useInternalXmlErrors);
} catch (\Exception $e) {
libxml_disable_entity_loader($loadEntities);
libxml_use_internal_errors($useInternalXmlErrors);
// Not valid XML
$this->_fault = new Fault(651);
Expand Down
9 changes: 5 additions & 4 deletions src/Value/BigInteger.php
Expand Up @@ -21,6 +21,8 @@

namespace Zend\XmlRpc\Value;

use Zend\Math\BigInteger\BigInteger as BigIntegerMath;

/**
* @category Zend
* @package Zend_XmlRpc
Expand All @@ -35,15 +37,14 @@ class BigInteger extends Integer
*/
public function __construct($value)
{
$integer = new \Zend\Math\BigInteger();
$this->_value = $integer->init($value);
$this->_type = self::XMLRPC_TYPE_I8;
$this->_value = BigIntegerMath::factory()->init($value, 10);
$this->_type = self::XMLRPC_TYPE_I8;
}

/**
* Return bigint value object
*
* @return \Zend\Math\BigInteger
* @return string
*/
public function getValue()
{
Expand Down
15 changes: 15 additions & 0 deletions test/RequestTest.php
Expand Up @@ -333,4 +333,19 @@ public function testSetGetEncoding()
$this->assertEquals('ISO-8859-1', $this->_request->getEncoding());
$this->assertEquals('ISO-8859-1', Value::getGenerator()->getEncoding());
}

/**
* @group ZF-12293
*/
public function testDoesNotAllowExternalEntities()
{
$payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-request.xml');
$payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt'));
$this->_request->loadXml($payload);
$method = $this->_request->getMethod();
$this->assertTrue(empty($method));
if (is_string($method)) {
$this->assertNotContains('Local file inclusion', $method);
}
}
}
15 changes: 15 additions & 0 deletions test/ResponseTest.php
Expand Up @@ -259,4 +259,19 @@ public function trackError($error)
{
$this->_errorOccured = true;
}

/**
* @group ZF-12293
*/
public function testDoesNotAllowExternalEntities()
{
$payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-response.xml');
$payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt'));
$this->_response->loadXml($payload);
$value = $this->_response->getReturnValue();
$this->assertTrue(empty($value));
if (is_string($value)) {
$this->assertNotContains('Local file inclusion', $value);
}
}
}
1 change: 1 addition & 0 deletions test/_files/ZF12293-payload.txt
@@ -0,0 +1 @@
Local file inclusion
8 changes: 8 additions & 0 deletions test/_files/ZF12293-request.xml
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ELEMENT methodName ANY >
<!ENTITY xxe SYSTEM "%s" >
]>
<methodCall>
<methodName>&xxe;</methodName>
</methodCall>
10 changes: 10 additions & 0 deletions test/_files/ZF12293-response.xml
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ELEMENT methodResponse ANY >
<!ENTITY xxe SYSTEM "%s" >
]>
<methodResponse>
<params>
<param><value><string>&xxe;</string></value></param>
</params>
</methodResponse>

0 comments on commit 17ed9ab

Please sign in to comment.