PHP Object Injection

Passing attacker-controlled input to unserialize() (or a wrapper like WordPress maybe_unserialize(), or the implicit phar:// 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 is a:<n>:{...}; base64 of an object begins Tzo, of an array YTo. 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 __wakeup searches 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 direct unserialize() 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: or a: (or Tzo/YTo in base64) is a PHP serialized value.
  • A malformed copy that yields unserialize(): Error at offset N of M bytes proves 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. phpggc carries POP chains for Laravel, Symfony, Monolog, Guzzle, WordPress and others for defender validation.

Notable cases

CVE / advisoryTargetNote
CVE-2022-21663WordPress coreObject injection reference case
CVE-2026-7647Profile Builder ProUnauth; chained a novel Monolog POP chain from another plugin
CVE-2026-59192CakePHP TwigViewunserialize Twig filter
GHSA-5xv5-3557-x7h5Masteriyo LMSmaybe_unserialize() in course importer
CVE-2026-124969 / variousOptimole, WPvivid, WP STAGING, QA Assistants, Document Library Pro, Testimonial SliderWordPress plugin object injection / untrusted-data deserialization
CVE-2026-126714 “PHPAfterShell”PHP file-session handlerNon-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 mismatchphp_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-135692rConfig Core <8.2.17 / Pro <8.4.0app/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-131782ProfileGrid ≤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-131754APCu Manager (WordPress plugin) ≤4.6.1Critical 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(). Prefer json_decode/json_encode for data-only interchange.
  • If unavoidable, pass ['allowed_classes' => [...]] (or false for 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.enabled unless needed, in php.ini or the FPM pool: an application ini_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 sets session.upload_progress.enabled=1 explicitly. 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 (== / loose strcmp) — see Insecure Deserialization.

Sources