File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55namespace SimpleSAML \XML ;
66
77use DOMDocument ;
8- use RuntimeException ;
98use SimpleSAML \Assert \Assert ;
109use SimpleSAML \XML \Exception \IOException ;
10+ use SimpleSAML \XML \Exception \RuntimeException ;
1111use SimpleSAML \XML \Exception \UnparseableXMLException ;
1212
1313use function defined ;
@@ -33,6 +33,12 @@ public static function fromString(string $xml): DOMDocument
3333 {
3434 libxml_set_external_entity_loader (null );
3535 Assert::notWhitespaceOnly ($ xml );
36+ Assert::notRegex (
37+ $ xml ,
38+ '/<(\s*)!(\s*)DOCTYPE/ ' ,
39+ 'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body ' ,
40+ RuntimeException::class,
41+ );
3642
3743 $ internalErrors = libxml_use_internal_errors (true );
3844 libxml_clear_errors ();
@@ -57,14 +63,6 @@ public static function fromString(string $xml): DOMDocument
5763
5864 libxml_clear_errors ();
5965
60- foreach ($ domDocument ->childNodes as $ child ) {
61- if ($ child ->nodeType === XML_DOCUMENT_TYPE_NODE ) {
62- throw new RuntimeException (
63- 'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body ' ,
64- );
65- }
66- }
67-
6866 return $ domDocument ;
6967 }
7068
You can’t perform that action at this time.
0 commit comments