summaryrefslogtreecommitdiff
path: root/src/tests/disable_xxe_xml_parse.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_xml_parse.phpt
Initial import
Diffstat (limited to 'src/tests/disable_xxe_xml_parse.phpt')
-rw-r--r--src/tests/disable_xxe_xml_parse.phpt104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/tests/disable_xxe_xml_parse.phpt b/src/tests/disable_xxe_xml_parse.phpt
new file mode 100644
index 0000000..944bc38
--- /dev/null
+++ b/src/tests/disable_xxe_xml_parse.phpt
@@ -0,0 +1,104 @@
1--TEST--
2Disable XXE
3--SKIPIF--
4<?php
5 if (!extension_loaded("snuffleupagus")) die "skip";
6 if (!extension_loaded("xml")) die "skip";
7 ?>
8--INI--
9extension=`php-config --extension-dir`/xml.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
28function create_parser() {
29 $parser = xml_parser_create();
30 xml_set_element_handler(
31 $parser,
32 function($parser, $name, array $attributes) {
33 var_dump($name);
34 echo "\n";
35 var_dump($attributes);
36 },
37 function($parser, $name) {
38 var_dump($name);
39 }
40 );
41
42 xml_set_character_data_handler(
43 $parser,
44 function ($parser, $text){
45 echo 'text' . $text;
46 }
47 );
48
49 return $parser;
50}
51
52libxml_disable_entity_loader(true);
53$parser = create_parser();
54$doc = xml_parse($parser, $xml, true);
55xml_parser_free($parser);
56
57libxml_disable_entity_loader(false);
58$parser = create_parser();
59$doc = xml_parse($parser, $xml, true);
60xml_parser_free($parser);
61
62$xml = "<test><testing>foo</testing></test>";
63file_put_contents('content.xml', $xml);
64$parser = create_parser();
65$doc = xml_parse($parser, $xml, true);
66xml_parser_free($parser);
67
68--EXPECT--
69string(4) "TEST"
70
71array(0) {
72}
73string(7) "TESTING"
74
75array(0) {
76}
77string(7) "TESTING"
78string(4) "TEST"
79string(4) "TEST"
80
81array(0) {
82}
83string(7) "TESTING"
84
85array(0) {
86}
87string(7) "TESTING"
88string(4) "TEST"
89string(4) "TEST"
90
91array(0) {
92}
93string(7) "TESTING"
94
95array(0) {
96}
97textfoostring(7) "TESTING"
98string(4) "TEST"
99--CLEAN--
100<?php
101$dir = __DIR__;
102unlink($dir . "/content.xml");
103unlink($dir . "/content.txt");
104?>