blob: 62762eb1a9976bb623b1bb3352a9a49d214cad10 (
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
50
51
52
|
--TEST--
Disable XXE
--SKIPIF--
<?php
if (!extension_loaded("snuffleupagus")) die "skip";
if (!extension_loaded("simplexml")) die "skip";
?>
--INI--
extension=`php-config --extension-dir`/simplexml.so
sp.configuration_file={PWD}/config/disable_xxe.ini
--FILE--
<?php
$dir = __DIR__;
$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 = simplexml_load_string($xml);
printf("libxml_disable_entity to true: %s\n", $doc->testing);
libxml_disable_entity_loader(false);
$doc = simplexml_load_string($xml);
printf("libxml_disable_entity to false: %s\n", $doc->testing);
$xml = "<test><testing>foo</testing></test>";
file_put_contents('content.xml', $xml);
$doc = simplexml_load_string($xml);
printf("without xxe: %s", $doc->testing);
?>
--EXPECT--
libxml_disable_entity to true:
libxml_disable_entity to false:
without xxe: foo
--CLEAN--
<?php
$dir = __DIR__;
unlink($dir . "/content.xml");
unlink($dir . "/content.txt");
?>
|