summaryrefslogtreecommitdiff
path: root/src/tests/disable_xxe_dom.phpt
diff options
context:
space:
mode:
authorSebastien Blot2017-09-20 10:11:01 +0200
committerSebastien Blot2017-09-20 10:11:01 +0200
commit868f96c759b6650d88ff9f4fbc5c048302134248 (patch)
treec0de0af318bf77a8959164ef11aeeeb2b7bab294 /src/tests/disable_xxe_dom.phpt
Initial import
Diffstat (limited to 'src/tests/disable_xxe_dom.phpt')
-rw-r--r--src/tests/disable_xxe_dom.phpt71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/tests/disable_xxe_dom.phpt b/src/tests/disable_xxe_dom.phpt
new file mode 100644
index 0000000..47f3db3
--- /dev/null
+++ b/src/tests/disable_xxe_dom.phpt
@@ -0,0 +1,71 @@
1--TEST--
2Disable XXE
3--SKIPIF--
4<?php
5 if (!extension_loaded("snuffleupagus")) die "skip";
6 if (!extension_loaded("dom")) die "skip";
7 ?>
8--INI--
9extension=`php-config --extension-dir`/dom.so
10sp.configuration_file={PWD}/config/disable_xxe.ini
11--FILE--
12<?php
13$dir = __DIR__;
14$content = 'WARNING, external entity loaded!';
15file_put_contents('content.txt', $content);
16
17$xml = <<<EOD
18<?xml version="1.0"?>
19<!DOCTYPE root
20[
21<!ENTITY foo SYSTEM "file://$dir/content.txt">
22]>
23<test><testing>&foo;</testing></test>
24EOD;
25
26file_put_contents('content.xml', $xml);
27
28libxml_disable_entity_loader(true);
29$dom = new DOMDocument('1.0');
30$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
31printf("libxml_disable_entity to true: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
32
33libxml_disable_entity_loader(false);
34$dom = new DOMDocument('1.0');
35$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
36printf("libxml_disable_entity to false: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
37
38$xml = "<test><testing>foo</testing></test>";
39file_put_contents('content.xml', $xml);
40
41libxml_disable_entity_loader(false);
42$dom = new DOMDocument('1.0');
43$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
44printf("without xxe: %s", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
45
46?>
47--EXPECTF--
48Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file://%a/content.txt" in %a/disable_xxe_dom.php on line %d
49
50Warning: DOMDocument::loadXML(): Failure to process entity foo in Entity, line: %d in %a/disable_xxe_dom.php on line %d
51
52Warning: DOMDocument::loadXML(): Entity 'foo' not defined in Entity, line: %d in %a/disable_xxe_dom.php on line %d
53
54Notice: Trying to get property of non-object in %a/disable_xxe_dom.php on line %d
55libxml_disable_entity to true:
56
57Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file://%a/content.txt" in %a/disable_xxe_dom.php on line %d
58
59Warning: DOMDocument::loadXML(): Failure to process entity foo in Entity, line: %d in %a/disable_xxe_dom.php on line %d
60
61Warning: DOMDocument::loadXML(): Entity 'foo' not defined in Entity, line: %d in %a/disable_xxe_dom.php on line %d
62
63Notice: Trying to get property of non-object in %a/disable_xxe_dom.php on line %d
64libxml_disable_entity to false:
65without xxe: foo
66--CLEAN--
67<?php
68$dir = __DIR__;
69unlink($dir . "content.xml");
70unlink($dir . "content.txt");
71?>