Harden unserialize() with allowed_classes => ['stdClass'] and add override hook#230
Draft
Harden unserialize() with allowed_classes => ['stdClass'] and add override hook#230
unserialize() with allowed_classes => ['stdClass'] and add override hook#230Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…e default Agent-Logs-Url: https://github.com/wp-cli/search-replace-command/sessions/00af441b-87d8-4c9e-83f9-25a04393eb6e Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add hook to provide allowed_classes for unserialize usage
Harden Apr 27, 2026
unserialize() with allowed_classes => false and add override hook
This comment was marked as resolved.
This comment was marked as resolved.
…ion scenarios Agent-Logs-Url: https://github.com/wp-cli/search-replace-command/sessions/59e4a42c-8f86-450d-b2b6-ee493abb4b19 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…tent Agent-Logs-Url: https://github.com/wp-cli/search-replace-command/sessions/0832cf35-01cd-463e-8334-064918206a6c Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Agent-Logs-Url: https://github.com/wp-cli/search-replace-command/sessions/599c39d4-de3e-4bc3-a371-0e93ec6c6a78 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Harden
Harden Apr 28, 2026
unserialize() with allowed_classes => false and add override hookunserialize() with allowed_classes => ['stdClass'] and add override hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wp search-replacecalledunserialize()without restricting class instantiation, allowing arbitrary magic methods to execute on data retrieved from the database. This adds['allowed_classes' => ['stdClass']]as the default, blocking instantiation of arbitrary user-defined classes while still allowingstdClass— a built-in PHP type with no magic methods that WordPress uses extensively for theme mods, widget data, and other serialized options.Changes
src/WP_CLI/SearchReplacer.php: Passes['allowed_classes' => ['stdClass']]tounserialize()by default. The value is resolved once perSearchReplacerinstance via a new filter hook:features/search-replace.feature:MyClassobject stored directly via SQL to demonstrate that custom classes are converted to__PHP_Incomplete_Classby default (warning + 0 replacements), and the hook can allow them (1 replacement).mysqli_resultscenarios — previously each PHP version triggered a different error path during object iteration/deserialization; with custom classes blocked by default,mysqli_resultis never instantiated on any version, so all three now expect the same"Skipping an uninitialized class"warning and 1 replacement (from the malformedcereal_isation_2entry which falls through to raw string replacement).