-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump libxml version requirement 2.7.6 => 2.9.0
Since libxml version 2.9.0 external entity loading is disabled by default. Bumping the version requirement means that XML processing in PHP is no longer vulnerable to XXE processing attacks by default.
- Loading branch information
Showing
4 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
ext/libxml/tests/libxml_entity_loading_disabled_by_default.phpt
This file contains 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,53 @@ | ||
--TEST-- | ||
libxml_disable_entity_loader() | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('libxml')) die('skip libxml extension not available'); | ||
if (!extension_loaded('dom')) die('skip dom extension not available'); | ||
--FILE-- | ||
<?php | ||
|
||
$xml = <<<EOT | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE test [<!ENTITY xxe SYSTEM "XXE_URI">]> | ||
<foo>&xxe;</foo> | ||
EOT; | ||
|
||
$dir = str_replace('\\', '/', __DIR__); | ||
$xml = str_replace('XXE_URI', $dir . '/libxml_disable_entity_loader_payload.txt', $xml); | ||
|
||
function parseXML1($xml) { | ||
$doc = new DOMDocument(); | ||
$doc->loadXML($xml, 0); | ||
return $doc->saveXML(); | ||
} | ||
|
||
function parseXML2($xml) { | ||
return simplexml_load_string($xml); | ||
} | ||
|
||
function parseXML3($xml) { | ||
$p = xml_parser_create(); | ||
xml_parse_into_struct($p, $xml, $vals, $index); | ||
xml_parser_free($p); | ||
return var_export($vals, true); | ||
} | ||
|
||
function parseXML4($xml) { | ||
// This is the only time we enable external entity loading. | ||
return simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOENT); | ||
} | ||
|
||
var_dump(strpos(parseXML1($xml), 'SECRET_DATA') === false); | ||
var_dump(strpos(parseXML2($xml), 'SECRET_DATA') === false); | ||
var_dump(strpos(parseXML3($xml), 'SECRET_DATA') === false); | ||
var_dump(strpos(parseXML4($xml), 'SECRET_DATA') === false); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(false) | ||
Done |