summaryrefslogtreecommitdiff
path: root/src/tests/disable_xxe_xml_parse.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/disable_xxe_xml_parse.phpt')
-rw-r--r--src/tests/disable_xxe_xml_parse.phpt106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/tests/disable_xxe_xml_parse.phpt b/src/tests/disable_xxe_xml_parse.phpt
deleted file mode 100644
index ca77729..0000000
--- a/src/tests/disable_xxe_xml_parse.phpt
+++ /dev/null
@@ -1,106 +0,0 @@
1--TEST--
2Disable XXE in xml_parse
3--SKIPIF--
4<?php
5 if (!extension_loaded("snuffleupagus")) {
6 echo "skip because snuffleupagus isn't loaded";
7} elseif (!extension_loaded("xml")) {
8 echo "skip because the `xml` extension isn't loaded";
9}
10 ?>
11--INI--
12sp.configuration_file={PWD}/config/disable_xxe.ini
13--FILE--
14<?php
15$dir = __DIR__;
16$content = 'WARNING, external entity loaded!';
17file_put_contents('content.txt', $content);
18
19$xml = <<<EOD
20<?xml version="1.0"?>
21<!DOCTYPE root
22[
23<!ENTITY foo SYSTEM "file://$dir/content.txt">
24]>
25<test><testing>&foo;</testing></test>
26EOD;
27
28file_put_contents('content.xml', $xml);
29
30function create_parser() {
31 $parser = xml_parser_create();
32 xml_set_element_handler(
33 $parser,
34 function($parser, $name, array $attributes) {
35 var_dump($name);
36 echo "\n";
37 var_dump($attributes);
38 },
39 function($parser, $name) {
40 var_dump($name);
41 }
42 );
43
44 xml_set_character_data_handler(
45 $parser,
46 function ($parser, $text){
47 echo 'text' . $text;
48 }
49 );
50
51 return $parser;
52}
53
54libxml_disable_entity_loader(true);
55$parser = create_parser();
56$doc = xml_parse($parser, $xml, true);
57xml_parser_free($parser);
58
59libxml_disable_entity_loader(false);
60$parser = create_parser();
61$doc = xml_parse($parser, $xml, true);
62xml_parser_free($parser);
63
64$xml = "<test><testing>foo</testing></test>";
65file_put_contents('content.xml', $xml);
66$parser = create_parser();
67$doc = xml_parse($parser, $xml, true);
68xml_parser_free($parser);
69
70--EXPECT--
71string(4) "TEST"
72
73array(0) {
74}
75string(7) "TESTING"
76
77array(0) {
78}
79string(7) "TESTING"
80string(4) "TEST"
81string(4) "TEST"
82
83array(0) {
84}
85string(7) "TESTING"
86
87array(0) {
88}
89string(7) "TESTING"
90string(4) "TEST"
91string(4) "TEST"
92
93array(0) {
94}
95string(7) "TESTING"
96
97array(0) {
98}
99textfoostring(7) "TESTING"
100string(4) "TEST"
101--CLEAN--
102<?php
103$dir = __DIR__;
104unlink($dir . "/content.xml");
105unlink($dir . "/content.txt");
106?>