@@ -60,7 +60,7 @@ public function testXMLAttacks()
6060 $ res = Utils::loadXML ($ dom , $ attackXXE );
6161 $ this ->fail ('Exception was not raised ' );
6262 } catch (Exception $ e ) {
63- $ this ->assertEquals ('Detected use of ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
63+ $ this ->assertEquals ('Detected use of DOCTYPE/ ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
6464 }
6565
6666 $ xmlWithDTD = '<?xml version="1.0"?>
@@ -71,8 +71,12 @@ public function testXMLAttacks()
7171 <results>
7272 <result>test</result>
7373 </results> ' ;
74- $ res2 = Utils::loadXML ($ dom , $ xmlWithDTD );
75- $ this ->assertTrue ($ res2 instanceof DOMDocument);
74+ try {
75+ $ res2 = Utils::loadXML ($ dom , $ xmlWithDTD );
76+ $ this ->assertFalse ($ res2 );
77+ } catch (Exception $ e ) {
78+ $ this ->assertEquals ('Detected use of DOCTYPE/ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
79+ }
7680
7781 $ attackXEE = '<?xml version="1.0"?>
7882 <!DOCTYPE results [<!ENTITY harmless "completely harmless">]>
@@ -81,9 +85,21 @@ public function testXMLAttacks()
8185 </results> ' ;
8286 try {
8387 $ res3 = Utils::loadXML ($ dom , $ attackXEE );
84- $ this ->fail ('Exception was not raised ' );
88+ $ this ->assertFalse ($ res3 );
89+ } catch (Exception $ e ) {
90+ $ this ->assertEquals ('Detected use of DOCTYPE/ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
91+ }
92+
93+ $ attackXEEutf16 = mb_convert_encoding ('<?xml version="1.0" encoding="UTF-16"?>
94+ <!DOCTYPE results [<!ENTITY harmless "completely harmless">]>
95+ <results>
96+ <result>This result is &harmless;</result>
97+ </results> ' , 'UTF-16 ' );
98+ try {
99+ $ res4 = Utils::loadXML ($ dom , $ attackXEEutf16 );
100+ $ this ->assertFalse ($ res4 );
85101 } catch (Exception $ e ) {
86- $ this ->assertEquals ('Detected use of ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
102+ $ this ->assertEquals ('Detected use of DOCTYPE/ ENTITY in XML, disabled to prevent XXE/XEE attacks ' , $ e ->getMessage ());
87103 }
88104 }
89105
0 commit comments