Skip to content

Commit c8c1136

Browse files
swissspidyCopilot
andauthored
Update src/Search_Replace_Command.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent cf02fb8 commit c8c1136

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/Search_Replace_Command.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,21 @@ private function run_search_replace_recursively( $data, $old, $new, $serialised
12251225
// reporting of notices and warnings as well.
12261226
$error_reporting = error_reporting();
12271227
error_reporting( $error_reporting & ~E_NOTICE & ~E_WARNING );
1228-
$unserialized = is_string( $data ) ? @unserialize( $data ) : false;
1228+
$unserialized = false;
1229+
if ( is_string( $data ) ) {
1230+
// Prevent unsafe object instantiation from attacker-controlled serialized data.
1231+
if ( defined( 'PHP_VERSION_ID' ) && PHP_VERSION_ID >= 70000 ) {
1232+
$unserialized = @unserialize(
1233+
$data,
1234+
array(
1235+
'allowed_classes' => false,
1236+
)
1237+
);
1238+
} else {
1239+
// Fallback for older PHP versions without the allowed_classes option.
1240+
$unserialized = @unserialize( $data );
1241+
}
1242+
}
12291243
error_reporting( $error_reporting );
12301244

12311245
} catch ( \TypeError $exception ) { // phpcs:ignore PHPCompatibility.Classes.NewClasses.typeerrorFound

0 commit comments

Comments
 (0)