Skip to content

Commit b95a83e

Browse files
committed
Fix XXE
1 parent 085062a commit b95a83e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

.extlib/simplesamlphp/vendor/simplesamlphp/saml2/src/SAML2/DOMDocumentFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@ public static function fromString(string $xml) : DOMDocument
3030
{
3131
if (trim($xml) === '') {
3232
throw InvalidArgumentException::invalidType('non-empty string', $xml);
33+
} elseif (preg_match('/<(\s*)!(\s*)DOCTYPE/', $xml)) {
34+
throw new RuntimeException(
35+
'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body'
36+
);
3337
} elseif (PHP_VERSION_ID < 80000) {
3438
$entityLoader = libxml_disable_entity_loader(true);
39+
} else {
40+
libxml_set_external_entity_loader(null);
3541
}
3642

3743
$internalErrors = libxml_use_internal_errors(true);
3844
libxml_clear_errors();
3945

4046
$domDocument = self::create();
41-
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET | LIBXML_PARSEHUGE;
47+
$options = LIBXML_NONET | LIBXML_PARSEHUGE;
48+
4249
if (defined('LIBXML_COMPACT')) {
4350
$options |= LIBXML_COMPACT;
4451
}

0 commit comments

Comments
 (0)