This repository was archived by the owner on May 16, 2018. It is now read-only.
File tree 4 files changed +32
-5
lines changed 4 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,7 @@ public function loadXml($request)
307
307
$ loadEntities = libxml_disable_entity_loader (true );
308
308
try {
309
309
$ xml = new SimpleXMLElement ($ request );
310
+ libxml_disable_entity_loader ($ loadEntities );
310
311
} catch (Exception $ e ) {
311
312
// Not valid XML
312
313
$ this ->_fault = new Zend_XmlRpc_Fault (631 );
@@ -320,7 +321,6 @@ public function loadXml($request)
320
321
// Missing method name
321
322
$ this ->_fault = new Zend_XmlRpc_Fault (632 );
322
323
$ this ->_fault ->setEncoding ($ this ->getEncoding ());
323
- libxml_disable_entity_loader ($ loadEntities );
324
324
return false ;
325
325
}
326
326
@@ -334,7 +334,6 @@ public function loadXml($request)
334
334
if (!isset ($ param ->value )) {
335
335
$ this ->_fault = new Zend_XmlRpc_Fault (633 );
336
336
$ this ->_fault ->setEncoding ($ this ->getEncoding ());
337
- libxml_disable_entity_loader ($ loadEntities );
338
337
return false ;
339
338
}
340
339
@@ -345,7 +344,6 @@ public function loadXml($request)
345
344
} catch (Exception $ e ) {
346
345
$ this ->_fault = new Zend_XmlRpc_Fault (636 );
347
346
$ this ->_fault ->setEncoding ($ this ->getEncoding ());
348
- libxml_disable_entity_loader ($ loadEntities );
349
347
return false ;
350
348
}
351
349
}
@@ -354,7 +352,6 @@ public function loadXml($request)
354
352
$ this ->_params = $ argv ;
355
353
}
356
354
357
- libxml_disable_entity_loader ($ loadEntities );
358
355
$ this ->_xml = $ request ;
359
356
360
357
return true ;
Original file line number Diff line number Diff line change @@ -176,11 +176,15 @@ public function loadXml($response)
176
176
return false ;
177
177
}
178
178
179
+ // @see ZF-12293 - disable external entities for security purposes
180
+ $ loadEntities = libxml_disable_entity_loader (true );
181
+ $ useInternalXmlErrors = libxml_use_internal_errors (true );
179
182
try {
180
- $ useInternalXmlErrors = libxml_use_internal_errors (true );
181
183
$ xml = new SimpleXMLElement ($ response );
184
+ libxml_disable_entity_loader ($ loadEntities );
182
185
libxml_use_internal_errors ($ useInternalXmlErrors );
183
186
} catch (Exception $ e ) {
187
+ libxml_disable_entity_loader ($ loadEntities );
184
188
libxml_use_internal_errors ($ useInternalXmlErrors );
185
189
// Not valid XML
186
190
$ this ->_fault = new Zend_XmlRpc_Fault (651 );
@@ -205,6 +209,7 @@ public function loadXml($response)
205
209
206
210
try {
207
211
if (!isset ($ xml ->params ) || !isset ($ xml ->params ->param ) || !isset ($ xml ->params ->param ->value )) {
212
+ require_once 'Zend/XmlRpc/Value/Exception.php ' ;
208
213
throw new Zend_XmlRpc_Value_Exception ('Missing XML-RPC value in XML ' );
209
214
}
210
215
$ valueXml = $ xml ->params ->param ->value ->asXML ();
Original file line number Diff line number Diff line change @@ -252,4 +252,19 @@ public function trackError($error)
252
252
{
253
253
$ this ->_errorOccured = true ;
254
254
}
255
+
256
+ /**
257
+ * @group ZF-12293
258
+ */
259
+ public function testDoesNotAllowExternalEntities ()
260
+ {
261
+ $ payload = file_get_contents (dirname (__FILE__ ) . '/_files/ZF12293-response.xml ' );
262
+ $ payload = sprintf ($ payload , 'file:// ' . realpath (dirname (__FILE__ ) . '/_files/ZF12293-payload.txt ' ));
263
+ $ this ->_response ->loadXml ($ payload );
264
+ $ value = $ this ->_response ->getReturnValue ();
265
+ $ this ->assertTrue (empty ($ value ));
266
+ if (is_string ($ value )) {
267
+ $ this ->assertNotContains ('Local file inclusion ' , $ value );
268
+ }
269
+ }
255
270
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <!DOCTYPE foo [
3
+ <!ELEMENT methodResponse ANY >
4
+ <!ENTITY xxe SYSTEM " %s" >
5
+ ]>
6
+ <methodResponse >
7
+ <params >
8
+ <param ><value ><string >&xxe; </string ></value ></param >
9
+ </params >
10
+ </methodResponse >
You can’t perform that action at this time.
0 commit comments