PHP Object Injection
Passing attacker-controlled input to
unserialize()(or a wrapper like WordPressmaybe_unserialize(), or the implicitphar://metadata path), letting an attacker instantiate arbitrary already-defined classes whose magic methods run during or after deserialization.
How it works
- Serialized syntax is plaintext and self-describing. An object is
O:<len>:"ClassName":<n>:{ <props> }; an array isa:<n>:{...}; base64 of an object beginsTzo, of an arrayYTo. The leading letter is the type tag (O,a,s,i,b,N). - Object injection, not code injection.
unserialize()does not run attacker code directly; it reconstructs objects of classes the application can load, and PHP then calls their magic methods.__wakeup()runs during deserialization;__destruct()runs when the object is freed (at latest at request end), so rejecting the object after the fact does not prevent it. Other reachable magic methods include__toString,__call,__get,__set,__unserialize. - Property-Oriented Programming (POP). Impact comes from chaining class methods already present in the app and its dependencies — see Gadget Chains. The gadget often lives in a plugin or library the developer never references directly; an autoloader will load it on demand, so auditing only your own controllers for
__wakeupsearches the wrong place (DedSec/Sonar). phar://path. Reading a crafted PHAR archive through almost any file function (file_exists,getimagesize,fopen,file_get_contents) deserializes the archive’s serialized metadata — turning a file-path primitive into object injection without a directunserialize()call (Sam Thomas, BH US-18). Requires getting the archive onto disk; file-upload filters (getimagesize, MIME, extension) are frequently satisfiable.
Where to find it
unserialize() on cookies, POST fields, import files, cache/session stores; framework wrappers (WordPress maybe_unserialize on postmeta); phar:// reachable via file functions. WordPress plugins are a steady source because option/postmeta values are serialized by design.
Detection
- Decode cookies/params; a value beginning
O:ora:(orTzo/YToin base64) is a PHP serialized value. - A malformed copy that yields
unserialize(): Error at offset N of M bytesproves a deserializer ran; note that a warning can be emitted while the HTTP status stays 200 if output was already sent. A generic error proves nothing. Out-of-band evidence is the reliable confirmation — see Insecure Deserialization and Out-of-Band Detection. - Static tools (SonarQube, Semgrep) flag
unserialize()on tainted input and the magic-method sinks.phpggccarries POP chains for Laravel, Symfony, Monolog, Guzzle, WordPress and others for defender validation.
Notable cases
| CVE / advisory | Target | Note |
|---|---|---|
| CVE-2022-21663 | WordPress core | Object injection reference case |
| CVE-2026-7647 | Profile Builder Pro | Unauth; chained a novel Monolog POP chain from another plugin |
| CVE-2026-59192 | CakePHP TwigView | unserialize Twig filter |
| GHSA-5xv5-3557-x7h5 | Masteriyo LMS | maybe_unserialize() in course importer |
| CVE-2026-124969 / various | Optimole, WPvivid, WP STAGING, QA Assistants, Document Library Pro, Testimonial Slider | WordPress plugin object injection / untrusted-data deserialization |
| CVE-2026-126714 “PHPAfterShell” | PHP file-session handler | Non-atomic pwrite()/ftruncate() in ps_files_write splices session files so leftover bytes reach php_var_unserialize(). Preconditions: file sessions, a planting route (upload progress or large user strings in the session; in threaded builds a memory-limit failure in another thread can kill the write), an interruption, a later session_start(), and a gadget path. Revives PHP2Shell’s path: that fix restricted which objects the upload-progress callback could create but left the read-modify-rewrite of the file unchanged (SecurityWeek) |
| CVE-2026-115560 (GHSA-658j-r8rw-q6mx) “phpAfterShell” | PHP session serializer mismatch | php_binary/php_serialize writer vs php reader via session upload progress smuggles object bytes into a session key; fixed in 8.2.36/8.3.37/8.4.28/8.5.13 (NetSPI) |
| CVE-2026-135692 | rConfig Core <8.2.17 / Pro <8.4.0 | app/Casts/EncryptStringCast.php unserializes decrypted attributes with no class restriction; an authenticated user stores a gadget in an encrypted field (device password) that fires as the web user on GET /api/devices (advisory) |
| CVE-2026-131707 / CVE-2026-129039 / CVE-2026-131782 | ProfileGrid ≤6.0.0.6, Tribulant Newsletters ≤4.18.2, Simple Shopping Cart ≤5.3.3 (WordPress) | Object injection from untrusted data. The SDM note’s excerpt attributes the last to Simple Download Monitor’s AJAX restore_settings (contributor+), but the advisory body names Simple Shopping Cart (ProfileGrid, Tribulant, GHSA-mvjg-64jh-vxm6) |
| CVE-2026-131754 | APCu Manager (WordPress plugin) ≤4.6.1 | Critical object injection from untrusted data (GHSA-7jwg-jc4p-j4xh) |
Mautic (GHSA-5r63-8h35-j3mw), Shiyi-blog (CVE-2025-12305) and OpenEMR (<8.3.0) are further app-level cases. Vanilla Forums’ historical getimagesize/splitHash unserialize bugs are classic phar:// and type-juggling examples.
Prevention
- Never pass user input to
unserialize(). Preferjson_decode/json_encodefor data-only interchange. - If unavoidable, pass
['allowed_classes' => [...]](orfalsefor arrays/scalars only); in testing this neutralised gadgets and even suppressed the autoloader call. Allowed classes still run their magic methods, so audit them. - Keep the session serializer consistent across every reader/writer of a shared session store (FPM pools, vhosts, app overrides, CLI jobs); isolate session storage where apps need different formats, and expire or migrate session files written under a previous format. Patch PHP for the Fall-2026 session CVEs and disable
session.upload_progress.enabledunless needed, in php.ini or the FPM pool: an applicationini_set()runs too late (NetSPI). After upgrading, restart the FPM master/Apache so every worker loads the new binary, and check no pool or vhost still setssession.upload_progress.enabled=1explicitly. A WAF rule only blocks the planting request, not the unserialize of the spliced file (Cloudflare). - Encrypting a stored value doesn’t make it safe to unserialize: if users choose the plaintext, the decrypted bytes are still attacker data (rConfig).
- Watch for type-juggling in comparisons on deserialized values (
==/ loosestrcmp) — see Insecure Deserialization.
Related
Sources
- rConfig PHP object injection · original
- ProfileGrid deserialization of untrusted data · original
- Tribulant Newsletters deserialization of untrusted data (critical) · original
- Simple Download Monitor deserialization of untrusted data (critical) · original
- phpAfterShell Vulnerability Revives PHP2Shell's Attack Path · original
- How Cloudflare WAF helps protect against phpAfterShell and other critical PHP flaws · original
- Exploiting a PHP object injection in Profile Builder Pro · original
- PHPAfterShell (CVE-2026-126714) · original
- phpAfterShell: interrupted session writes to RCE · original
- 247CTF Meme Upload Service — Hand-Built Phar Meets XXE · original
- APCu Manager deserialization of untrusted data (critical) · original
- CakePHP TwigView unserialize filter · original
- Masteriyo LMS WordPress PHP object injection · original
- Mautic insecure deserialization · original
- PayloadsAllTheThings - PHP Deserialization Payloads · original
- php-src: session serializer mismatch · original
- WP STAGING PHP Object Injection · original
- What is PHP Object Injection? An In-Depth Guide · original
- Exploiting PHP Deserialization with POP Chains · original
- phpAfterShell: Critical PHP Vulnerabilities (CVE-2026-115560 & CVE-2026-126714) · original
- How to Exploit PHAR Deserialization Vulnerability · original
- PHP Object Injection Research · original