← PHP / Laravel · Contents

PHP-010 / Advanced

Passing user input to unserialize()

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

Why is this a problem?

Object injection can execute gadget chains through magic methods (__destruct, __wakeup) and lead to RCE.

How to fix it

php
$data = json_decode(base64_decode($request->cookie('prefs')), true, 512, JSON_THROW_ON_ERROR);
// Use only signed cookies or encrypted values (Laravel's default EncryptCookies)

Further reading