Prevent unintended behavior when certain objects are unserialized.

Props ehtis, xknown.

Built from https://develop.svn.wordpress.org/trunk@56835


git-svn-id: http://core.svn.wordpress.org/trunk@56347 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2023-10-12 12:34:33 +00:00
parent 3f1e6a6a50
commit 0b35c4e2bf
7 changed files with 86 additions and 1 deletions

View File

@ -96,4 +96,8 @@ class Hooks implements HookManager {
return true;
}
public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}

View File

@ -717,6 +717,20 @@ class Iri {
return true;
}
public function __wakeup() {
$class_props = get_class_vars( __CLASS__ );
$string_props = array( 'scheme', 'iuserinfo', 'ihost', 'port', 'ipath', 'iquery', 'ifragment' );
$array_props = array( 'normalization' );
foreach ( $class_props as $prop => $default_value ) {
if ( in_array( $prop, $string_props, true ) && ! is_string( $this->$prop ) ) {
throw new UnexpectedValueException();
} elseif ( in_array( $prop, $array_props, true ) && ! is_array( $this->$prop ) ) {
throw new UnexpectedValueException();
}
$this->$prop = null;
}
}
/**
* Set the entire IRI. Returns true on success, false on failure (if there
* are any invalid characters).

View File

@ -265,6 +265,10 @@ class Session {
return Requests::request_multiple($requests, $options);
}
public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
/**
* Merge a request's data with the default data
*

View File

@ -230,6 +230,21 @@ final class WP_Block_Patterns_Registry {
return isset( $this->registered_patterns[ $pattern_name ] );
}
public function __wakeup() {
if ( ! $this->registered_patterns ) {
return;
}
if ( ! is_array( $this->registered_patterns ) ) {
throw new UnexpectedValueException();
}
foreach ( $this->registered_patterns as $value ) {
if ( ! is_array( $value ) ) {
throw new UnexpectedValueException();
}
}
$this->registered_patterns_outside_init = array();
}
/**
* Utility method to retrieve the main instance of the class.
*

View File

@ -168,6 +168,20 @@ final class WP_Block_Type_Registry {
return isset( $this->registered_block_types[ $name ] );
}
public function __wakeup() {
if ( ! $this->registered_block_types ) {
return;
}
if ( ! is_array( $this->registered_block_types ) ) {
throw new UnexpectedValueException();
}
foreach ( $this->registered_block_types as $value ) {
if ( ! $value instanceof WP_Block_Type ) {
throw new UnexpectedValueException();
}
}
}
/**
* Utility method to retrieve the main instance of the class.
*

View File

@ -772,6 +772,28 @@ final class WP_Theme implements ArrayAccess {
return isset( $this->parent ) ? $this->parent : false;
}
/**
* Perform reinitialization tasks.
*
* Prevents a callback from being injected during unserialization of an object.
*
* @return void
*/
public function __wakeup() {
if ( $this->parent && ! $this->parent instanceof self ) {
throw new UnexpectedValueException();
}
if ( $this->headers && ! is_array( $this->headers ) ) {
throw new UnexpectedValueException();
}
foreach ( $this->headers as $value ) {
if ( ! is_string( $value ) ) {
throw new UnexpectedValueException();
}
}
$this->headers_sanitized = array();
}
/**
* Adds theme data to cache.
*
@ -1918,4 +1940,16 @@ final class WP_Theme implements ArrayAccess {
private static function _name_sort_i18n( $a, $b ) {
return strnatcasecmp( $a->name_translated, $b->name_translated );
}
private static function _check_headers_property_has_correct_type( $headers ) {
if ( ! is_array( $headers ) ) {
return false;
}
foreach ( $headers as $key => $value ) {
if ( ! is_string( $key ) || ! is_string( $value ) ) {
return false;
}
}
return true;
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-beta3-56834';
$wp_version = '6.4-beta3-56835';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.