summaryrefslogtreecommitdiff
path: root/src/tests/xxe
diff options
context:
space:
mode:
authorjvoisin2022-03-20 18:20:45 +0100
committerjvoisin2022-03-20 18:20:45 +0100
commit81dd7f2ef07af306fe83d7755cbac4529aa9fc8d (patch)
tree32cc44c6231b30db5ac7b15699297863460784aa /src/tests/xxe
parent83b01942dfc80474cc05e09aeef4b44307a7120b (diff)
parentc38df1077a6c1dfbca1baca049214d053e2e7684 (diff)
Merge remote-tracking branch 'sektioneins/master'
Diffstat (limited to 'src/tests/xxe')
-rw-r--r--src/tests/xxe/config/disable_xxe.ini2
-rw-r--r--src/tests/xxe/config/disable_xxe_disable.ini2
-rw-r--r--src/tests/xxe/disable_xxe_dom_disabled.phpt4
-rw-r--r--src/tests/xxe/disable_xxe_dom_disabled_php8.phpt57
-rw-r--r--src/tests/xxe/disable_xxe_dom_php8.phpt59
-rw-r--r--src/tests/xxe/disable_xxe_simplexml.phpt3
-rw-r--r--src/tests/xxe/disable_xxe_simplexml_oop.phpt3
-rw-r--r--src/tests/xxe/disable_xxe_xml_parse.phpt5
8 files changed, 128 insertions, 7 deletions
diff --git a/src/tests/xxe/config/disable_xxe.ini b/src/tests/xxe/config/disable_xxe.ini
index bc9d1f2..a50a3b9 100644
--- a/src/tests/xxe/config/disable_xxe.ini
+++ b/src/tests/xxe/config/disable_xxe.ini
@@ -1 +1 @@
sp.disable_xxe.enable(); sp.xxe_protection.enable();
diff --git a/src/tests/xxe/config/disable_xxe_disable.ini b/src/tests/xxe/config/disable_xxe_disable.ini
index bb1e432..eaf5755 100644
--- a/src/tests/xxe/config/disable_xxe_disable.ini
+++ b/src/tests/xxe/config/disable_xxe_disable.ini
@@ -1 +1 @@
sp.disable_xxe.disable(); sp.xxe_protection.disable();
diff --git a/src/tests/xxe/disable_xxe_dom_disabled.phpt b/src/tests/xxe/disable_xxe_dom_disabled.phpt
index a49e094..107171c 100644
--- a/src/tests/xxe/disable_xxe_dom_disabled.phpt
+++ b/src/tests/xxe/disable_xxe_dom_disabled.phpt
@@ -1,10 +1,10 @@
1--TEST-- 1--TEST--
2Disable XXE 2Disable XXE (feature enabled)
3--SKIPIF-- 3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("dom")) print("skip"); ?> 4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("dom")) print("skip"); ?>
5<?php if (PHP_VERSION_ID >= 80000) print "skip"; ?> 5<?php if (PHP_VERSION_ID >= 80000) print "skip"; ?>
6--INI-- 6--INI--
7sp.configuration_file={PWD}/config/disable_xxe_disable.ini 7sp.configuration_file={PWD}/config/disable_xxe.ini
8--EXTENSIONS-- 8--EXTENSIONS--
9dom 9dom
10--FILE-- 10--FILE--
diff --git a/src/tests/xxe/disable_xxe_dom_disabled_php8.phpt b/src/tests/xxe/disable_xxe_dom_disabled_php8.phpt
new file mode 100644
index 0000000..01e3349
--- /dev/null
+++ b/src/tests/xxe/disable_xxe_dom_disabled_php8.phpt
@@ -0,0 +1,57 @@
1--TEST--
2Disable XXE (feature disabled)
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("dom")) print("skip"); ?>
5<?php if (PHP_VERSION_ID < 80000) print "skip"; ?>
6--INI--
7sp.configuration_file={PWD}/config/disable_xxe_disable.ini
8--EXTENSIONS--
9dom
10--FILE--
11<?php
12$dir = __DIR__;
13$content = '<content>WARNING, external entity loaded!</content>';
14file_put_contents($dir . '/content.txt', $content);
15
16$xml = <<<EOD
17<?xml version="1.0"?>
18<!DOCTYPE root
19[
20<!ENTITY foo SYSTEM "file://$dir/content.txt">
21]>
22<test><testing>&foo;</testing></test>
23EOD;
24
25file_put_contents($dir . '/content.xml', $xml);
26
27
28$dom = new DOMDocument('1.0');
29$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
30printf("default setting with LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
31
32$dom = new DOMDocument('1.0');
33$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD);
34printf("default setting without LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
35
36libxml_set_external_entity_loader(null);
37
38$dom = new DOMDocument('1.0');
39$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
40printf("disabled entity loader with LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
41
42$dom = new DOMDocument('1.0');
43$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD);
44printf("disabled entity loader without LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
45
46?>
47--EXPECTF--
48default setting with LIBXML_NOENT: WARNING, external entity loaded!
49default setting without LIBXML_NOENT:
50disabled entity loader with LIBXML_NOENT: WARNING, external entity loaded!
51disabled entity loader without LIBXML_NOENT:
52--CLEAN--
53<?php
54$dir = __DIR__;
55unlink($dir . "/content.xml");
56unlink($dir . "/content.txt");
57?>
diff --git a/src/tests/xxe/disable_xxe_dom_php8.phpt b/src/tests/xxe/disable_xxe_dom_php8.phpt
new file mode 100644
index 0000000..485828f
--- /dev/null
+++ b/src/tests/xxe/disable_xxe_dom_php8.phpt
@@ -0,0 +1,59 @@
1--TEST--
2Disable XXE (feature enabled)
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("dom")) print("skip"); ?>
5<?php if (PHP_VERSION_ID < 80000) print "skip"; ?>
6--INI--
7sp.configuration_file={PWD}/config/disable_xxe.ini
8--EXTENSIONS--
9dom
10--FILE--
11<?php
12$dir = __DIR__;
13$content = '<content>WARNING, external entity loaded!</content>';
14file_put_contents($dir . '/content.txt', $content);
15
16$xml = <<<EOD
17<?xml version="1.0"?>
18<!DOCTYPE root
19[
20<!ENTITY foo SYSTEM "file://$dir/content.txt">
21]>
22<test><testing>&foo;</testing></test>
23EOD;
24
25file_put_contents($dir . '/content.xml', $xml);
26
27
28$dom = new DOMDocument('1.0');
29$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
30printf("default setting with LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
31
32$dom = new DOMDocument('1.0');
33$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD);
34printf("default setting without LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
35
36libxml_set_external_entity_loader(null);
37
38$dom = new DOMDocument('1.0');
39$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD|LIBXML_NOENT);
40printf("disabled entity loader with LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
41
42$dom = new DOMDocument('1.0');
43$dom->loadXML($xml, LIBXML_DTDATTR|LIBXML_DTDLOAD);
44printf("disabled entity loader without LIBXML_NOENT: %s\n", $dom->getElementsByTagName('testing')->item(0)->nodeValue);
45
46?>
47--EXPECTF--
48default setting with LIBXML_NOENT: WARNING, external entity loaded!
49default setting without LIBXML_NOENT:
50
51Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_set_external_entity_loader was tried and nopped in %a.php on line 26
52disabled entity loader with LIBXML_NOENT: WARNING, external entity loaded!
53disabled entity loader without LIBXML_NOENT:
54--CLEAN--
55<?php
56$dir = __DIR__;
57unlink($dir . "/content.xml");
58unlink($dir . "/content.txt");
59?>
diff --git a/src/tests/xxe/disable_xxe_simplexml.phpt b/src/tests/xxe/disable_xxe_simplexml.phpt
index 1d3ef4c..9560156 100644
--- a/src/tests/xxe/disable_xxe_simplexml.phpt
+++ b/src/tests/xxe/disable_xxe_simplexml.phpt
@@ -2,8 +2,9 @@
2Disable XXE 2Disable XXE
3--SKIPIF-- 3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("simplexml") || getenv('TRAVIS')) print("skip"); ?> 4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("simplexml") || getenv('TRAVIS')) print("skip"); ?>
5<?php if (PHP_VERSION_ID >= 80000) print "skip"; ?>
5--INI-- 6--INI--
6sp.configuration_file={PWD}/config/disable_xxe.ini 7sp.configuration_file={PWD}/config/disable_xxe_disable.ini
7--EXTENSIONS-- 8--EXTENSIONS--
8simplexml 9simplexml
9--XFAIL-- 10--XFAIL--
diff --git a/src/tests/xxe/disable_xxe_simplexml_oop.phpt b/src/tests/xxe/disable_xxe_simplexml_oop.phpt
index e101337..1b2c4ca 100644
--- a/src/tests/xxe/disable_xxe_simplexml_oop.phpt
+++ b/src/tests/xxe/disable_xxe_simplexml_oop.phpt
@@ -2,8 +2,9 @@
2Disable XXE 2Disable XXE
3--SKIPIF-- 3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("simplexml") || getenv('TRAVIS')) print("skip"); ?> 4<?php if (!extension_loaded("snuffleupagus") || !extension_loaded("simplexml") || getenv('TRAVIS')) print("skip"); ?>
5<?php if (PHP_VERSION_ID >= 80000) print "skip"; ?>
5--INI-- 6--INI--
6sp.configuration_file={PWD}/config/disable_xxe.ini 7sp.configuration_file={PWD}/config/disable_xxe_disable.ini
7--EXTENSIONS-- 8--EXTENSIONS--
8simplexml 9simplexml
9--XFAIL-- 10--XFAIL--
diff --git a/src/tests/xxe/disable_xxe_xml_parse.phpt b/src/tests/xxe/disable_xxe_xml_parse.phpt
index 6b48bea..bc7e338 100644
--- a/src/tests/xxe/disable_xxe_xml_parse.phpt
+++ b/src/tests/xxe/disable_xxe_xml_parse.phpt
@@ -70,7 +70,8 @@ $parser = create_parser();
70$doc = xml_parse($parser, $xml, true); 70$doc = xml_parse($parser, $xml, true);
71xml_parser_free($parser); 71xml_parser_free($parser);
72 72
73--EXPECT-- 73--EXPECTF--
74Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_disable_entity_loader was tried and nopped in %a.php on line 41
74string(4) "TEST" 75string(4) "TEST"
75 76
76array(0) { 77array(0) {
@@ -81,6 +82,8 @@ array(0) {
81} 82}
82string(7) "TESTING" 83string(7) "TESTING"
83string(4) "TEST" 84string(4) "TEST"
85
86Warning: [snuffleupagus][0.0.0.0][xxe][log] A call to libxml_disable_entity_loader was tried and nopped in %a.php on line 46
84string(4) "TEST" 87string(4) "TEST"
85 88
86array(0) { 89array(0) {