← PHP / Laravel · Contents

PHP-021 / Advanced

Object-injection gadget chains (advanced PHP deserialization)

A08:2021 Software and Data Integrity Failures · CWE-502 Deserialization of Untrusted Data

Why is this a problem?

Magic methods in libraries such as Monolog and Guzzle can be called in sequence, enabling file deletion or RCE. A phar:// stream can also trigger them.

How to fix it

php
$obj = json_decode(file_get_contents($uploadedPath), true, 512, JSON_THROW_ON_ERROR);
// PHP 8: block object creation with unserialize($s, ['allowed_classes' => false])

Further reading