---
title: "Insecure deserialization"
description: "Insecure deserialization and PHP object injection: how it works, a real WordPress example, unserialize vs maybe_unserialize and best practices."
language: "en"
locale: "en-US"
type: "definition"
canonical: "https://www.wp-feint.com/glossary/insecure-deserialization/"
published: "2026-10-28T08:00:00+00:00"
modified: "2026-11-22T12:07:06+00:00"
translations:
  en-US: "https://www.wp-feint.com/glossary/insecure-deserialization/index.md"
  fr-FR: "https://www.wp-feint.com/fr/definitions/deserialisation-non-sure/index.md"
  es-ES: "https://www.wp-feint.com/es/glosario/deserializacion-insegura/index.md"
  de-DE: "https://www.wp-feint.com/de/glossar/unsichere-deserialisierung/index.md"
  it-IT: "https://www.wp-feint.com/it/glossario/deserializzazione-insicura/index.md"
  pt-BR: "https://www.wp-feint.com/pt/glossario/desserializacao-insegura/index.md"
  nl-NL: "https://www.wp-feint.com/nl/woordenlijst/onveilige-deserialisatie/index.md"
---

# Insecure deserialization

Insecure deserialization is a vulnerability that occurs when an application rebuilds objects from attacker-controlled data, for example with unserialize() in PHP. The methods triggered automatically during this rebuilding can lead to file deletion or code execution.

Serializing means turning structured data (an array, an object) into text so it can be stored or transmitted; deserializing is the reverse operation. The problem arises when the data to rebuild comes from the outside: a cookie, a form field, a URL parameter. MITRE classifies this weakness as CWE-502, “Deserialization of Untrusted Data”; in PHP, it is also called PHP Object Injection.

## How the attack works in PHP

A PHP serialized string describes the type of what it contains. For example, `O:4:"User":1:{s:4:"name";s:3:"Bob";}` refers to an object of the `User` class with a `name` property. An attacker who controls this string can therefore ask `unserialize()` to create an object of any class loaded by the site, with whatever values they want.

That object becomes dangerous thanks to the magic methods PHP calls automatically: `__wakeup()` on reconstruction, `__destruct()` on destruction, `__toString()` when the object is used as text. By chaining classes already present in the site's code, whose methods call one another, the attacker builds a gadget chain (POP chain) that ends in a dangerous action: deleting a file, writing a PHP file, [remote code execution](https://www.wp-feint.com/glossary/remote-code-execution/).

![Five-step PHP object injection: the attacker sends a forged serialized string in a cookie or a field, the application calls unserialize() and rebuilds an object of the chosen class, PHP automatically runs the __wakeup, __destruct or __toString magic methods, existing classes chain together into a POP gadget chain, and the final effect is file deletion, a PHP file being written or code execution](https://www.wp-feint.com/media/2026/10/deserialisation-chaine-en.webp)

## A WordPress example: GiveWP

Vulnerability CVE-2024-5932 in the GiveWP donation plugin, up to and including version 3.14.1, allowed an unauthenticated attacker to inject a PHP object through the `give_title` parameter. A gadget chain present in the plugin led to code execution and file deletion; the published CVSS 3.1 score is 10. [Our article on PHP object injection](https://www.wp-feint.com/php-deserialization-object-injection/) covers this case and the mechanism in detail.

Deserialization is also useful to attackers once they are inside: the backdoor added in 2025 to the EssentialPlugin plugin portfolio relied on `unserialize`, as our article on supply chain attacks points out.

*Video: “Insecure Deserialization Attack Explained” (PwnFunction)*

## For WordPress: unserialize and maybe_unserialize

WordPress stores a lot of serialized data, especially in the options table and in metadata. The `maybe_unserialize()` function is used to read it back: if the data looks serialized (`is_serialized()`), it calls `unserialize()`, without restricting the allowed classes. It therefore provides no protection and must never receive data that comes from a visitor.

- **Exchange data as JSON**: the PHP documentation recommends `json_encode()` and `json_decode()` for any data that passes through the user. JSON never creates objects of arbitrary classes.
- **Don't expect too much from `allowed_classes`**: this `unserialize()` option limits which classes get instantiated, but the PHP manual states that untrusted data should not be passed to this function, whatever its value.
- **Sign whatever has to make the round trip**: if serialized data really must travel through the browser, an HMAC signature verified before any reading prevents it from being tampered with.
- **Keep PHP up to date**: since PHP 8.0, phar archive metadata is no longer deserialized automatically, which closed an attack path linked to [file inclusion](https://www.wp-feint.com/glossary/file-inclusion/) and wrappers.

On the administrator's side, the main defense is still updating the affected plugins, since the flaw is in their code. A [web application firewall](https://www.wp-feint.com/glossary/waf/) can block suspicious serialized strings in the meantime, and [WP Feint Pro's vulnerability alerts](https://www.wp-feint.com/features/vulnerable-plugin-alerts/) tell you when an installed plugin is among the affected versions. WP Feint doesn't filter requests itself.

## Related terms

- [Remote code execution (RCE)](https://www.wp-feint.com/glossary/remote-code-execution/)
- [File inclusion (LFI / RFI)](https://www.wp-feint.com/glossary/file-inclusion/)
- [WAF (web application firewall)](https://www.wp-feint.com/glossary/waf/)
- [SQL injection](https://www.wp-feint.com/glossary/sql-injection/)


## Sources

- [MITRE CWE-502 : Deserialization of Untrusted Data](https://cwe.mitre.org/data/definitions/502.html)
- [PHP Manual : unserialize()](https://www.php.net/manual/en/function.unserialize.php)
- [WordPress Developer Resources : maybe_unserialize()](https://developer.wordpress.org/reference/functions/maybe_unserialize/)
- [CVE Record : CVE-2024-5932](https://www.cve.org/CVERecord?id=CVE-2024-5932)
