Skip to content

Commit

Permalink
Bump libxml version requirement 2.7.6 => 2.9.0
Browse files Browse the repository at this point in the history
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
Dik Takken authored and nikic committed Aug 3, 2020
1 parent 44c7128 commit 691a09f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,11 @@ PHP 8.0 UPGRADE NOTES
- PDO:
. PDOStatement now implements IteratorAggregate (instead of Traversable).

- LibXML:
. The minimum required libxml version is now 2.9.0. This means that external
entity loading is now guaranteed to be disabled by default, and no extra
steps need to be taken to protect against XXE attacks.

- MySQLi / PDO MySQL:
. When mysqlnd is not used (which is the default and recommended option),
the minimum supported libmysqlclient version is now 5.1.
Expand Down
2 changes: 1 addition & 1 deletion build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ dnl
dnl Common setup macro for libxml.
dnl
AC_DEFUN([PHP_SETUP_LIBXML], [
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.7.6])
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.9.0])
PHP_EVAL_INCLINE($LIBXML_CFLAGS)
PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
Expand Down
24 changes: 0 additions & 24 deletions ext/libxml/tests/bug54138_1.phpt

This file was deleted.

53 changes: 53 additions & 0 deletions ext/libxml/tests/libxml_entity_loading_disabled_by_default.phpt
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

0 comments on commit 691a09f

Please sign in to comment.