From 7523ee8bc346b80ec0c02e6db5a82f78f8b07bba Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 25 Nov 2024 23:23:49 +0100 Subject: [PATCH] Set new default of we can --- src/DOMDocumentFactory.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DOMDocumentFactory.php b/src/DOMDocumentFactory.php index 1d0fe0a..1447483 100644 --- a/src/DOMDocumentFactory.php +++ b/src/DOMDocumentFactory.php @@ -11,6 +11,7 @@ use SimpleSAML\XML\Exception\UnparseableXMLException; use function file_get_contents; +use function func_num_args; use function libxml_clear_errors; use function libxml_get_last_error; use function libxml_set_external_entity_loader; @@ -51,6 +52,11 @@ public static function fromString( $internalErrors = libxml_use_internal_errors(true); libxml_clear_errors(); + // If LIBXML_NO_XXE is available and option not set + if (func_num_args() === 1 && defined('LIBXML_NO_XXE')) { + $options != LIBXML_NO_XXE; + } + $domDocument = self::create(); $loaded = $domDocument->loadXML($xml, $options); @@ -95,7 +101,7 @@ public static function fromFile(string $file, int $options = self::DEFAULT_OPTIO } Assert::notWhitespaceOnly($xml, sprintf('File "%s" does not have content', $file), RuntimeException::class); - return static::fromString($xml, $options); + return (func_num_args() === 1) ? static::fromString($xml) : static::fromString($xml, $options); }