blob: d33e206ec91dfca561e851e852d53c4352f1039e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
--TEST--
Disable XXE
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("simplexml")) print("skip"); ?>
<?php if (PHP_VERSION_ID >= 80000) print "skip Not applicable for PHP 8+"; ?>
--INI--
sp.configuration_file={PWD}/config/disable_xxe_disable.ini
--EXTENSIONS--
simplexml
--XFAIL--
--FILE--
<?php
$dir = __DIR__;
@unlink($dir . "/content.xml");
@unlink($dir . "/content.txt");
$content = 'WARNING, external entity loaded!';
file_put_contents('content.txt', $content);
$xml = <<<EOD
<?xml version="1.0"?>
<!DOCTYPE root
[
<!ENTITY foo SYSTEM "file://$dir/content.txt">
]>
<test><testing>&foo;</testing></test>
EOD;
file_put_contents('content.xml', $xml);
libxml_disable_entity_loader(true);
$doc = new SimpleXMLElement($xml);
printf("libxml_disable_entity to true: %s\n", $doc->testing);
libxml_disable_entity_loader(false);
$doc = new SimpleXMLElement($xml);
printf("libxml_disable_entity to false: %s\n", $doc->testing);
$xml = "<test><testing>foo</testing></test>";
file_put_contents('content.xml', $xml);
$doc = new SimpleXMLElement($xml);
printf("without xxe: %s", $doc->testing);
?>
--EXPECT--
libxml_disable_entity to true:
libxml_disable_entity to false:
without xxe: foo
|