PHP Object Injection
Introduction
This article covers ways to secure the code from PHP Object Injection vulnerability. This includes applying a proper function to check for the userβs input.
How to secure
We do not recommend doing the deserialization using the unserialize
or maybe_unserialize
functions. For more complex data, we can use other data formats such as JSON.
If the unserialize
or maybe_unserialize
functions are still needed, the best approach we can take to prevent PHP Object Injection is to set the allowed_classes
parameter to a false
value on the function options parameter. This approach will not accept class objects in the deserialization process and usually can prevent the worst from happening: