{
    "title": "Insecure deserialization",
    "seo_title": "Insecure deserialization: definition and PHP prevention",
    "h1": "Insecure deserialization",
    "description": "Insecure deserialization and PHP object injection: how it works, a real WordPress example, unserialize vs maybe_unserialize and best practices.",
    "lead": "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.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/insecure-deserialization/",
    "canonical": "https://www.wp-feint.com/glossary/insecure-deserialization/",
    "markdown": "https://www.wp-feint.com/glossary/insecure-deserialization/index.md",
    "json": "https://www.wp-feint.com/glossary/insecure-deserialization/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:07:06+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "Insecure deserialization",
            "url": "https://www.wp-feint.com/glossary/insecure-deserialization/",
            "markdown": "https://www.wp-feint.com/glossary/insecure-deserialization/index.md",
            "json": "https://www.wp-feint.com/glossary/insecure-deserialization/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Désérialisation non sûre",
            "url": "https://www.wp-feint.com/fr/definitions/deserialisation-non-sure/",
            "markdown": "https://www.wp-feint.com/fr/definitions/deserialisation-non-sure/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/deserialisation-non-sure/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Deserialización insegura",
            "url": "https://www.wp-feint.com/es/glosario/deserializacion-insegura/",
            "markdown": "https://www.wp-feint.com/es/glosario/deserializacion-insegura/index.md",
            "json": "https://www.wp-feint.com/es/glosario/deserializacion-insegura/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Unsichere Deserialisierung",
            "url": "https://www.wp-feint.com/de/glossar/unsichere-deserialisierung/",
            "markdown": "https://www.wp-feint.com/de/glossar/unsichere-deserialisierung/index.md",
            "json": "https://www.wp-feint.com/de/glossar/unsichere-deserialisierung/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Deserializzazione insicura",
            "url": "https://www.wp-feint.com/it/glossario/deserializzazione-insicura/",
            "markdown": "https://www.wp-feint.com/it/glossario/deserializzazione-insicura/index.md",
            "json": "https://www.wp-feint.com/it/glossario/deserializzazione-insicura/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Desserialização insegura",
            "url": "https://www.wp-feint.com/pt/glossario/desserializacao-insegura/",
            "markdown": "https://www.wp-feint.com/pt/glossario/desserializacao-insegura/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/desserializacao-insegura/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Onveilige deserialisatie",
            "url": "https://www.wp-feint.com/nl/woordenlijst/onveilige-deserialisatie/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/onveilige-deserialisatie/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/onveilige-deserialisatie/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "Insecure deserialization"
        },
        {
            "level": 2,
            "text": "How the attack works in PHP"
        },
        {
            "level": 2,
            "text": "A WordPress example: GiveWP"
        },
        {
            "level": 2,
            "text": "For WordPress: unserialize and maybe_unserialize"
        }
    ],
    "body": "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.\n\n## How the attack works in PHP\n\nA 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.\n\nThat 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/).\n\n![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)\n\n## A WordPress example: GiveWP\n\nVulnerability 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.\n\nDeserialization 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.\n\n*Video: “Insecure Deserialization Attack Explained” (PwnFunction)*\n\n## For WordPress: unserialize and maybe_unserialize\n\nWordPress 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.\n\n- **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.\n- **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.\n- **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.\n- **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.\n\nOn 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.\n\n## Related terms\n\n- [Remote code execution (RCE)](https://www.wp-feint.com/glossary/remote-code-execution/)\n- [File inclusion (LFI / RFI)](https://www.wp-feint.com/glossary/file-inclusion/)\n- [WAF (web application firewall)](https://www.wp-feint.com/glossary/waf/)\n- [SQL injection](https://www.wp-feint.com/glossary/sql-injection/)\n\n\n## Sources\n\n- [MITRE CWE-502 : Deserialization of Untrusted Data](https://cwe.mitre.org/data/definitions/502.html)\n- [PHP Manual : unserialize()](https://www.php.net/manual/en/function.unserialize.php)\n- [WordPress Developer Resources : maybe_unserialize()](https://developer.wordpress.org/reference/functions/maybe_unserialize/)\n- [CVE Record : CVE-2024-5932](https://www.cve.org/CVERecord?id=CVE-2024-5932)",
    "definition": "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.",
    "group": "Web security",
    "aka": [
        "PHP object injection",
        "object injection",
        "unsafe deserialization",
        "CWE-502"
    ],
    "related": [
        {
            "title": "Remote code execution (RCE)",
            "url": "https://www.wp-feint.com/glossary/remote-code-execution/",
            "markdown": "https://www.wp-feint.com/glossary/remote-code-execution/index.md"
        },
        {
            "title": "File inclusion (LFI / RFI)",
            "url": "https://www.wp-feint.com/glossary/file-inclusion/",
            "markdown": "https://www.wp-feint.com/glossary/file-inclusion/index.md"
        },
        {
            "title": "WAF (web application firewall)",
            "url": "https://www.wp-feint.com/glossary/waf/",
            "markdown": "https://www.wp-feint.com/glossary/waf/index.md"
        },
        {
            "title": "SQL injection",
            "url": "https://www.wp-feint.com/glossary/sql-injection/",
            "markdown": "https://www.wp-feint.com/glossary/sql-injection/index.md"
        }
    ],
    "sources": [
        {
            "title": "MITRE CWE-502 : Deserialization of Untrusted Data",
            "url": "https://cwe.mitre.org/data/definitions/502.html"
        },
        {
            "title": "PHP Manual : unserialize()",
            "url": "https://www.php.net/manual/en/function.unserialize.php"
        },
        {
            "title": "WordPress Developer Resources : maybe_unserialize()",
            "url": "https://developer.wordpress.org/reference/functions/maybe_unserialize/"
        },
        {
            "title": "CVE Record : CVE-2024-5932",
            "url": "https://www.cve.org/CVERecord?id=CVE-2024-5932"
        }
    ],
    "format": "application/json"
}