Summary
MixPHP Framework 2.x through 2.2.17 contains an unsafe deserialization flaw where the FileHandler session and cache components invoke PHP's unserialize() on data read from the filesystem.
If an attacker can influence or control the contents of these serialized files, they may be able to trigger arbitrary object instantiation and potentially achieve remote code execution within the application context.
Affected context
This vulnerability is present in MixPHP applications that use the framework's file-based session or cache handlers.
The risk is most pronounced when:
- Session or cache storage is configured to use the vulnerable FileHandler
- File storage paths are writable and potentially exposed to other local processes, users, or compromised components
- Application code or installed libraries define PHP magic methods (e.g., __wakeup, __destruct) with side effects that can be abused when objects are unserialized
The vulnerability does not depend on a specific business feature; it is tied to how session and cache data are serialized and later deserialized from disk.
Exploit preconditions
- Attack surface: Server-side, via file-based session or cache storage that is later processed by MixPHP using unserialize().
- Required access: Ability to influence or write serialized data into files that the FileHandler will read (e.g., through session fixation/poisoning, local file write primitives, shared hosting scenarios, or compromise of an adjacent component).
- Trigger point: The next request or operation that causes MixPHP's FileHandler to load a session or cache entry and call unserialize() on its content.
- Why exploitation is possible: PHP's unserialize() treats the input as a serialized object graph without enforcing type or class constraints, allowing attacker-controlled data to instantiate arbitrary classes and invoke magic methods, matching the unsafe deserialization pattern in CWE-502.
Why this happens
The core issue is the direct use of PHP's unserialize() on data that is not strongly authenticated or constrained, in the FileHandler used for session and cache storage.
This creates a classic CWE-502: Deserialization of Untrusted Data scenario, where:
- Data stored to disk is later treated as trusted, despite potential tampering or cross-tenant write access.
- The deserialization process can instantiate arbitrary classes available in the application and its dependencies.
- Magic methods (such as __wakeup, __sleep, __destruct) or other lifecycle hooks in those classes may perform file operations, command execution, or further dynamic behavior.
Instead of treating stored session and cache entries as opaque, primitive values, the framework rehydrates full PHP object graphs from the filesystem, extending the application's trust boundary to any actor able to alter those files.
Potential impact
- Remote code execution in the context of the web server process via gadget chains in application or library classes
- Access to or modification of sensitive session data, potentially leading to account takeover or privilege escalation
- Manipulation of cached application state, impacting business logic or integrity of responses
- Lateral movement within the hosting environment by leveraging filesystem and OS-level privileges of the application
- Data disclosure through deserialization side effects that expose configuration or internal state
General mitigation guidance
Effective mitigation focuses on reducing trust in serialized data and avoiding unserialize() for session and cache storage:
- Prefer serialization formats that do not support object graphs, such as JSON or other primitive-only encodings, for session and cache values.
- Treat session and cache backends as untrusted storage, enforcing strict validation, type checks, and casting when data is read back.
- Avoid storing full object instances in sessions or cache; store only scalar values or simple arrays and reconstruct objects explicitly when needed.
- Minimize or refactor PHP classes that implement magic methods with side effects that can be triggered on object construction, wakeup, or destruction.
- Consider using signed or authenticated session/cache tokens to detect tampering, while still avoiding unserialize() for core parsing.
- Apply least-privilege for the web server and PHP processes, limiting filesystem and OS capabilities so that deserialization abuse has reduced impact.
How teams detect issues like this
Detection typically combines code-level analysis with configuration review:
- Use static analysis (SAST) rules to flag calls to unserialize(), especially within framework infrastructure like session and cache handlers.
- During code review, scrutinize any data flows where serialized data is written to and later read from disk or other storage backends, and verify that the data origin is truly trusted.
- Inventory classes across the application and dependencies that define __wakeup, __destruct, or __toString, and assess whether they perform sensitive operations that could be chained into a gadget.
- Incorporate security-focused linters or automated review tools into CI to block new uses of unserialize() and to enforce safer serialization practices.
- Monitor application logs and telemetry for anomalous session or cache behavior, such as unexpected object types found in session state or sudden changes in file sizes and access patterns in session/cache directories.

