Skip to content

Commit ab9aee8

Browse files
Code Modernization: Only call libxml_disable_entity_loader() in PHP < 8.
This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is disabled by default, so this function is no longer needed to protect against XXE attacks. Props jrf. Fixes #50898. git-svn-id: https://develop.svn.wordpress.org/trunk@48789 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1bf0a78 commit ab9aee8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/wp-includes/class-wp-oembed.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,23 @@ private function _parse_xml( $response_body ) {
597597
return false;
598598
}
599599

600-
$loader = libxml_disable_entity_loader( true );
600+
if ( PHP_VERSION_ID < 80000 ) {
601+
// This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading
602+
// is disabled by default, so this function is no longer needed to protect against XXE attacks.
603+
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated
604+
$loader = libxml_disable_entity_loader( true );
605+
}
606+
601607
$errors = libxml_use_internal_errors( true );
602608

603609
$return = $this->_parse_xml_body( $response_body );
604610

605611
libxml_use_internal_errors( $errors );
606-
libxml_disable_entity_loader( $loader );
612+
613+
if ( PHP_VERSION_ID < 80000 && isset( $loader ) ) {
614+
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated
615+
libxml_disable_entity_loader( $loader );
616+
}
607617

608618
return $return;
609619
}

0 commit comments

Comments
 (0)