Security: change PhpSerializeOptions $allowedClasses default to false - #98
Open
XananasX7 wants to merge 4 commits into
Open
Security: change PhpSerializeOptions $allowedClasses default to false#98XananasX7 wants to merge 4 commits into
XananasX7 wants to merge 4 commits into
Conversation
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Previously, $allowedClasses defaulted to true, allowing any PHP class to
be instantiated during unserialize(). This is unsafe when the serialized
data originates from an untrusted source (e.g. user-controlled cache keys
or session data): an attacker who can control the serialized payload can
trigger PHP Object Injection via available gadget chains.
Change the default to false (deny all classes). Callers that legitimately
need to deserialize objects must now opt in by explicitly setting:
$options->setAllowedClasses(true); // allow all (legacy)
$options->setAllowedClasses([Foo::class]); // allow specific classes
This is a breaking change for any consumer that relies on the old default
and deserializes objects without configuring allowed_classes — update
those call sites to pass an explicit allowlist.
Member
|
@XananasX7 Thanks for your contribution! After discussing this with the maintainer, we'd like to target this for the 4.0 release. Could you please change the base branch to target |
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.
Summary
Change the default value of
PhpSerializeOptions::$allowedClassesfromtruetofalse.Security Motivation
The current default (
true) means that whenPhpSerialize::unserialize()is called without explicitallowed_classesconfiguration, PHP will happily instantiate any class available in the autoloader during deserialization. This is the vector for PHP Object Injection (POI) attacks — an attacker who controls the serialized payload can exploit available gadget chains.This is especially dangerous in the common usage pattern where:
allowed_classesallowlistChange
Migration
Applications that legitimately deserialize objects must now opt in explicitly:
Impact
This is a breaking change for callers that:
PhpSerializewithout configuringallowed_classes, ANDThe fix is to add an explicit allowlist at the call site.
Related