diff options
| author | Sebastien Blot | 2017-09-20 10:11:01 +0200 |
|---|---|---|
| committer | Sebastien Blot | 2017-09-20 10:11:01 +0200 |
| commit | 868f96c759b6650d88ff9f4fbc5c048302134248 (patch) | |
| tree | c0de0af318bf77a8959164ef11aeeeb2b7bab294 /src/tests/disable_xxe_simplexml_oop.phpt | |
Initial import
Diffstat (limited to 'src/tests/disable_xxe_simplexml_oop.phpt')
| -rw-r--r-- | src/tests/disable_xxe_simplexml_oop.phpt | 52 |
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-- | ||
| 2 | Disable XXE | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php | ||
| 5 | if (!extension_loaded("snuffleupagus")) die "skip"; | ||
| 6 | if (!extension_loaded("simplexml")) die "skip"; | ||
| 7 | ?> | ||
| 8 | --INI-- | ||
| 9 | extension=`php-config --extension-dir`/simplexml.so | ||
| 10 | sp.configuration_file={PWD}/config/disable_xxe.ini | ||
| 11 | --FILE-- | ||
| 12 | <?php | ||
| 13 | $dir = __DIR__; | ||
| 14 | $content = 'WARNING, external entity loaded!'; | ||
| 15 | file_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> | ||
| 24 | EOD; | ||
| 25 | |||
| 26 | file_put_contents('content.xml', $xml); | ||
| 27 | |||
| 28 | libxml_disable_entity_loader(true); | ||
| 29 | $doc = simplexml_load_string($xml); | ||
| 30 | printf("libxml_disable_entity to true: %s\n", $doc->testing); | ||
| 31 | |||
| 32 | libxml_disable_entity_loader(false); | ||
| 33 | $doc = simplexml_load_string($xml); | ||
| 34 | printf("libxml_disable_entity to false: %s\n", $doc->testing); | ||
| 35 | |||
| 36 | $xml = "<test><testing>foo</testing></test>"; | ||
| 37 | file_put_contents('content.xml', $xml); | ||
| 38 | |||
| 39 | $doc = simplexml_load_string($xml); | ||
| 40 | printf("without xxe: %s", $doc->testing); | ||
| 41 | |||
| 42 | ?> | ||
| 43 | --EXPECT-- | ||
| 44 | libxml_disable_entity to true: | ||
| 45 | libxml_disable_entity to false: | ||
| 46 | without xxe: foo | ||
| 47 | --CLEAN-- | ||
| 48 | <?php | ||
| 49 | $dir = __DIR__; | ||
| 50 | unlink($dir . "/content.xml"); | ||
| 51 | unlink($dir . "/content.txt"); | ||
| 52 | ?> | ||
