88use DOMException ;
99use PHPUnit \Framework \Attributes \CoversClass ;
1010use PHPUnit \Framework \Attributes \Group ;
11+ use PHPUnit \Framework \Attributes \RequiresOperatingSystemFamily ;
1112use PHPUnit \Framework \TestCase ;
1213use RuntimeException ;
1314use SimpleSAML \Assert \AssertionFailedException ;
1920use function is_file ;
2021use function mb_convert_encoding ;
2122use function random_bytes ;
23+ use function str_replace ;
2224use function strval ;
2325use function sys_get_temp_dir ;
2426
@@ -37,7 +39,7 @@ final class DOMDocumentFactoryTest extends TestCase
3739 protected function setUp (): void
3840 {
3941 $ this ->marker = 'XXE_TEST_MARKER_ ' . bin2hex (random_bytes (16 ));
40- $ this ->secretFile = sys_get_temp_dir () . ' / xml-common-xxe-test- ' . getmypid () . '.txt ' ;
42+ $ this ->secretFile = sys_get_temp_dir () . DIRECTORY_SEPARATOR . ' xml-common-xxe-test- ' . getmypid () . '.txt ' ;
4143 file_put_contents ($ this ->secretFile , $ this ->marker );
4244 }
4345
@@ -54,20 +56,19 @@ protected function tearDown(): void
5456 * Classic external-entity payload aimed at a file we control.
5557 * The factory must reject the document; the marker must never appear.
5658 */
59+ #[RequiresOperatingSystemFamily('Linux ' )]
5760 public function testExternalEntityCannotReadLocalFileUsingDefaultOptions (): void
5861 {
5962 // file:// URI pointing at our temporary secret
60- $ uri = 'file:// ' . $ this ->secretFile ;
61-
63+ $ uri = 'file:/// ' . str_replace (DIRECTORY_SEPARATOR , '/ ' , $ this ->secretFile );
6264 $ payload = <<<XML
63- <?xml version="1.0" encoding="UTF-8"?>
6465<!DOCTYPE foo [
65- <!ELEMENT foo ANY>
6666 <!ENTITY xxe SYSTEM " {$ uri }">
6767]>
6868<foo>&xxe;</foo>
6969XML ;
7070
71+ var_dump ($ payload );
7172 $ doc = Dom \XMLDocument ::createFromString ($ payload , DOMDocumentFactory ::getDefaultOptions ());
7273 // If we reach here the protection failed – check that the secret did not leak into the document.
7374 $ xml = $ doc ->saveXml ();
@@ -83,15 +84,13 @@ public function testExternalEntityCannotReadLocalFileUsingDefaultOptions(): void
8384 * Classic external-entity payload aimed at a file we control.
8485 * The factory must reject the document; the marker must never appear.
8586 */
87+ #[RequiresOperatingSystemFamily('Linux ' )]
8688 public function testExternalEntityCannotReadLocalFileUsingNonDefaultOptions (): void
8789 {
8890 // file:// URI pointing at our temporary secret
89- $ uri = 'file:// ' . $ this ->secretFile ;
90-
91+ $ uri = 'file:// ' . str_replace (DIRECTORY_SEPARATOR , '/ ' , $ this ->secretFile );
9192 $ payload = <<<XML
92- <?xml version="1.0" encoding="UTF-8"?>
9393<!DOCTYPE foo [
94- <!ELEMENT foo ANY>
9594 <!ENTITY xxe SYSTEM " {$ uri }">
9695]>
9796<foo>&xxe;</foo>
@@ -111,14 +110,13 @@ public function testExternalEntityCannotReadLocalFileUsingNonDefaultOptions(): v
111110 /**
112111 * Same idea with a UTF-16LE encoded payload.
113112 */
113+ #[RequiresOperatingSystemFamily('Linux ' )]
114114 public function testUtf16ExternalEntityCannotReadLocalFileUsingDefaultOptions (): void
115115 {
116116 $ uri = 'file:// ' . $ this ->secretFile ;
117117
118118 $ utf8 = <<<XML
119- <?xml version="1.0" encoding="UTF-16"?>
120119<!DOCTYPE foo [
121- <!ELEMENT foo ANY>
122120 <!ENTITY xxe SYSTEM " {$ uri }">
123121]>
124122<foo>&xxe;</foo>
@@ -140,14 +138,13 @@ public function testUtf16ExternalEntityCannotReadLocalFileUsingDefaultOptions():
140138 /**
141139 * Same idea with a UTF-16LE encoded payload.
142140 */
141+ #[RequiresOperatingSystemFamily('Linux ' )]
143142 public function testUtf16ExternalEntityCannotReadLocalFileUsingNonDefaultOptions (): void
144143 {
145144 $ uri = 'file:// ' . $ this ->secretFile ;
146145
147146 $ utf8 = <<<XML
148- <?xml version="1.0" encoding="UTF-16"?>
149147<!DOCTYPE foo [
150- <!ELEMENT foo ANY>
151148 <!ENTITY xxe SYSTEM " {$ uri }">
152149]>
153150<foo>&xxe;</foo>
0 commit comments