summaryrefslogtreecommitdiff
path: root/src/tests/disable_xxe_simplexml_oop.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/disable_xxe_simplexml_oop.phpt')
-rw-r--r--src/tests/disable_xxe_simplexml_oop.phpt52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/tests/disable_xxe_simplexml_oop.phpt b/src/tests/disable_xxe_simplexml_oop.phpt
new file mode 100644
index 0000000..62762eb
--- /dev/null
+++ b/src/tests/disable_xxe_simplexml_oop.phpt
@@ -0,0 +1,52 @@
1--TEST--
2Disable XXE
3--SKIPIF--
4<?php
5 if (!extension_loaded("snuffleupagus")) die "skip";
6 if (!extension_loaded("simplexml")) die "skip";
7 ?>
8--INI--
9extension=`php-config --extension-dir`/simplexml.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$doc = simplexml_load_string($xml);
30printf("libxml_disable_entity to true: %s\n", $doc->testing);
31
32libxml_disable_entity_loader(false);
33$doc = simplexml_load_string($xml);
34printf("libxml_disable_entity to false: %s\n", $doc->testing);
35
36$xml = "<test><testing>foo</testing></test>";
37file_put_contents('content.xml', $xml);
38
39$doc = simplexml_load_string($xml);
40printf("without xxe: %s", $doc->testing);
41
42?>
43--EXPECT--
44libxml_disable_entity to true:
45libxml_disable_entity to false:
46without xxe: foo
47--CLEAN--
48<?php
49$dir = __DIR__;
50unlink($dir . "/content.xml");
51unlink($dir . "/content.txt");
52?>