Summary
MixPHP Framework 2.x through 2.2.17 contains an unsafe deserialization flaw in its sync-invoke TCP server, where data read from a localhost TCP socket is passed directly to Opis\Closure\unserialize() and then executed with call_user_func().
An attacker who can reach the bound localhost TCP port can send a crafted serialized PHP closure, leading to arbitrary code execution in the PHP process.
Affected context
This vulnerability appears in MixPHP applications that enable or deploy the sync-invoke TCP server component in versions 2.x through 2.2.17.
The server listens on 127.0.0.1 and accepts arbitrary TCP connections on its configured port without authentication or message integrity checks.
Any data received from this local TCP endpoint is treated as a serialized PHP closure, deserialized using Opis\Closure\unserialize(), and then invoked directly via call_user_func().
The risk is elevated in environments where:
- Other local processes, users, or containers can open TCP connections to the service
- The localhost boundary is not considered a strong security boundary (e.g., shared hosts, development desktops, CI runners)
Exploit preconditions
- Attack surface: Local TCP port bound to
127.0.0.1by the sync-invoke server - Required access: Ability to establish a TCP connection to the localhost port (e.g., code execution as the same OS user, another service on the host, or a container with network access to the host loopback)
- Trigger point: Sending a specially crafted serialized PHP closure payload to the listening sync-invoke TCP endpoint
- Why exploitation is possible:
- Raw socket data is trusted as if it were a legitimate serialized closure
Opis\Closure\unserialize()is invoked on untrusted bytes- The resulting callable is immediately invoked with
call_user_func()without validation, allowing attacker-controlled code to run
Why this happens
The core issue is an unsafe deserialization pattern: untrusted data from a TCP socket is directly deserialized into executable code constructs.
Specifically, the sync-invoke server:
- Treats incoming TCP data as a serialized PHP closure payload
- Uses
Opis\Closure\unserialize()on this untrusted data, enabling construction of arbitrary closure objects - Immediately executes the deserialized closure via
call_user_func()without authentication, authorization, or integrity checks
This behavior maps to CWE-502: Deserialization of Untrusted Data, where attacker-controlled serialized objects or closures are turned back into live code or objects and executed, breaking the intended trust boundary around the localhost interface.
Potential impact
- Arbitrary PHP code execution within the MixPHP application process
- Full compromise of the web application runtime and its configuration
- Access to sensitive data handled by the application, including credentials and tokens
- Lateral movement to connected databases, caches, and internal services via the compromised process
- Use of the compromised application as a pivot point for further attacks within the host or network
General mitigation guidance
Effective mitigation focuses on eliminating the direct deserialization-and-execution of untrusted data and tightening the trust boundary around local IPC.
Pattern-based defensive strategies include:
- Avoid deserializing executable constructs from untrusted sources:
- Replace
Opis\Closure\unserialize()with data-oriented serialization formats (e.g., JSON, protocol buffers) that cannot carry arbitrary code. - Design the protocol to pass identifiers and parameters, not code or closures.
- Introduce strong authentication and integrity checks:
- Require a shared secret, token, or mutual authentication on the TCP channel before processing requests.
- Use message authentication codes (MACs) or signatures to ensure messages originate from trusted components.
- Validate and constrain what can be executed:
- Map incoming requests to a fixed set of allowed operations or handlers.
- Avoid calling arbitrary callables; use whitelists and explicit dispatch tables.
- Harden the runtime environment:
- Run the sync-invoke server under a dedicated, least-privileged OS account.
- Limit file system, network, and database privileges so that compromise has constrained blast radius.
- Reconsider IPC design choices:
- Prefer well-defined, typed, and schema-validated inter-process protocols instead of arbitrary object/closure serialization.
- Treat localhost as a semi-trusted boundary and design with the assumption that other local processes may be malicious.
How teams detect issues like this
Detecting this vulnerability and similar patterns generally involves combining code-centric and runtime-centric approaches:
- Static code analysis:
- Search for calls to
unserialize(),Opis\Closure\unserialize(), or similar APIs where the input originates from network sockets or other untrusted sources. - Flag patterns where deserialized values are passed into
call_user_func(),call_user_func_array(), or other dynamic execution functions. - Enforce project-wide rules disallowing deserialization of closures or executable objects from external input.
- Manual code review:
- Inspect IPC, RPC, and "sync invoke" style components for protocols that transmit code or callables instead of data.
- Review any code paths that trust localhost as inherently safe and accept raw serialized payloads.
- Runtime and operational monitoring:
- Monitor local TCP ports for unexpected connection sources and high-frequency or anomalous traffic patterns.
- Enable application-level logging that records invocation sources, parameters, and unexpected failures in the sync-invoke server.
- Security testing and CI integration:
- Include deserialization-focused tests and fuzzing against internal endpoints, not just public HTTP interfaces.
- Integrate automated tools that detect unsafe deserialization usage into CI pipelines to catch regressions early.

