Skip to content

Commit 9efec58

Browse files
committed
Explicitly wrap some XML calls in libxml_disable_entity_loader()
As per https://www.php.net/manual/en/function.libxml-disable-entity-loader.php this is technically unnecessary. >However, as of libxml 2.9.0 entity substitution is disabled by default, >so there is no need to disable the loading of external entities. See also php/php-src#5867 >Since the release of libxml 2.9.0 in 2012 external entity loading is >disabled in libxml by default. This means that using >libxml_disable_entity_loader() is no longer needed. Hopefully helps prevent false positive reports from security scanning tools. Change-Id: I8a09d62a9920fd0bf4a388baa5544a02323bb541 (cherry picked from commit 64ea157)
1 parent 40c15fd commit 9efec58

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

includes/site/SiteImporter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ public function importFromXML( $xml ) {
8282
$document = new DOMDocument();
8383

8484
$oldLibXmlErrors = libxml_use_internal_errors( true );
85+
$oldDisable = libxml_disable_entity_loader( true );
8586
$ok = $document->loadXML( $xml, LIBXML_NONET );
8687

8788
if ( !$ok ) {
8889
$errors = libxml_get_errors();
8990
libxml_use_internal_errors( $oldLibXmlErrors );
91+
libxml_disable_entity_loader( $oldDisable );
9092

9193
foreach ( $errors as $error ) {
9294
/** @var LibXMLError $error */
@@ -99,6 +101,7 @@ public function importFromXML( $xml ) {
99101
}
100102

101103
libxml_use_internal_errors( $oldLibXmlErrors );
104+
libxml_disable_entity_loader( $oldDisable );
102105
$this->importFromDOM( $document->documentElement );
103106
}
104107

tests/phpunit/includes/ExportTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ public function testPageByTitle() {
3737
$exporter->pageByTitle( $title );
3838
$exporter->closeStream();
3939

40+
$oldDisable = libxml_disable_entity_loader( true );
41+
4042
// This throws error if invalid xml output
4143
$xmlObject = simplexml_load_string( $sink );
4244

45+
libxml_disable_entity_loader( $oldDisable );
46+
4347
/**
4448
* Check namespaces match xml
4549
*/

0 commit comments

Comments
 (0)