phanalist

E0053: Unserialize Without allowed_classes

In plain English: unserialize() can create objects of classes named inside the input. If an attacker controls that input, they may choose a class with dangerous __wakeup() or __destruct() methods. This is called object injection.

Why it matters: Object injection can lead to file writes, command execution, or other side effects depending on which classes the application loads.

Bad

$cart = unserialize($_COOKIE['cart']);
$cart = unserialize($payload, []);
$cart = unserialize($payload, ['allowed_classes' => true]);

Good

$cart = unserialize($payload, ['allowed_classes' => false]);

$dto = unserialize($payload, [
    'allowed_classes' => [Cart::class, CartItem::class],
]);

allowed_classes => false prevents object creation and allows only arrays and scalars. A list allows only the classes you name.

What the rule checks

When it does not report

How to fix

Model limits

Configuration

E0053 has no configuration options and is enabled by default.