summaryrefslogtreecommitdiff
path: root/src/tests/disable_xxe_dom_disabled.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_disabled.phpt
Initial import
Diffstat (limited to 'src/tests/disable_xxe_dom_disabled.phpt')
-rw-r--r--src/tests/disable_xxe_dom_disabled.phpt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/tests/disable_xxe_dom_disabled.phpt b/src/tests/disable_xxe_dom_disabled.phpt
new file mode 100644
index 0000000..b89b595
--- /dev/null
+++ b/src/tests/disable_xxe_dom_disabled.phpt
@@ -0,0 +1,56 @@
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_disable.ini
11--FILE--
12<?php
13$dir = __DIR__;
14$content = '<content>WARNING, external entity loaded!</content>';
15file_put_contents($dir . '/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($dir . '/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--
48libxml_disable_entity to true: WARNING, external entity loaded!
49libxml_disable_entity to false: WARNING, external entity loaded!
50without xxe: foo
51--CLEAN--
52<?php
53$dir = __DIR__;
54unlink($dir . "/content.xml");
55unlink($dir . "/content.txt");
56?>