Web application security research on PHP insecure deserialization and object injection
WEB APPLICATION SECURITY RESEARCH

PHP Insecure
Deserialization

How PHP object injection, unsafe application state, and gadget chains create exploitable web application security risks.
November 10, 2026
10 Minute Read
Redbot Security Research

PHP insecure deserialization remains a serious application security risk because untrusted data can influence the creation and behavior of application objects. In the wrong circumstances, a simple data-processing routine becomes a path to unauthorized file operations, sensitive data exposure, or remote code execution.

The underlying weakness is not serialization itself. It is allowing attacker-controlled input to shape executable object state across a trust boundary. Actual impact depends on the classes the application loads, the methods available, and the privileges of the application process.

At Redbot Security, our manual application testing focuses on this distinction: identifying a risky code pattern is not the same as proving an exploitable attack path.

Find the weakness.
Validate the exposure.

Follow the technical evidence from unsafe input handling to practical business impact. Explore related research and the services that validate exploitability.

What is PHP insecure deserialization?

Serialization converts a value or object into a form suitable for storage or transmission. Deserialization reconstructs it. PHP offers native serialize() and unserialize() functions for this purpose.

The risk appears when data from a request, cookie, message queue, or other untrusted source reaches unserialize(). Unlike a data-only parser, native PHP deserialization can reconstruct objects associated with application classes, potentially invoking lifecycle behavior that developers did not intend to expose to external users.

PHP's own documentation warns against passing untrusted user input to unserialize(), regardless of the allowed_classes option.

Restricting classes is not a general-purpose safety guarantee for untrusted serialized data.

Consider this simplified anti-pattern:

<?php
// Unsafe when the request value can be controlled externally.
$data = unserialize($_POST['data']);

This alone does not establish remote code execution. It establishes an unsafe trust decision that must be analyzed in the context of the application's available classes, data flows, and privileges.

How PHP object injection develops into an attack

PHP object injection occurs when an attacker can submit a serialized representation that influences the objects an application reconstructs. The resulting attack can proceed through several stages.

1. Find a reachable input

An assessor identifies cookies, parameters, hidden form values, API requests, cached content, or other inputs that may flow into a deserialization routine. A successful test establishes that the input actually reaches the relevant code path.

2. Influence object properties

Serialized PHP objects can carry class information and property values. If the application accepts these from an untrusted source, an attacker may shape internal state in a way normal application workflows never permit.

3. Reach automatically invoked methods

PHP supports object lifecycle methods such as __wakeup(), __unserialize(), __destruct(), and __toString(). Their existence is not a vulnerability. The danger arises when reachable methods perform sensitive operations using properties controlled by an attacker.

4. Chain existing application behavior

A property-oriented programming (POP) chain combines existing classes and methods to produce an unintended result. An attacker may not need to upload new executable code; the relevant behavior might already exist in a framework, dependency, or custom application class.

The difference between a suspicious input and a serious security finding is whether these conditions produce a demonstrable breach of confidentiality, integrity, or availability.

What makes the vulnerability exploitable?

Not every application using unserialize() can be compromised in the same way. Manual validation is needed to establish the practical exposure.

  • Reachability: Can an untrusted party control the value deserialized by the application?
  • Available classes: Are exploitable methods reachable through loaded classes or autoloaded dependencies?
  • Property control: Which object fields can the attacker change, and how are they used after reconstruction?
  • Sensitive operations: Do methods interact with files, shell commands, databases, external services, or other privileged functions?
  • Execution privileges: What can the application process read, modify, or reach on the network?
  • Existing safeguards: Do input validation, integrity checks, isolation, or permissions meaningfully interrupt the chain?
A scanner finding is a starting point, not proof of an exploitable object-injection chain.

The security impact must be validated in the context of the deployed application.

Potential impact on enterprise applications

Insecure deserialization can lead to different outcomes depending on the codebase and privileges available. These are possible consequences, not results that occur in every case.

  • Remote code execution: A suitable method chain may eventually reach a privileged execution primitive.
  • Sensitive data disclosure: Object behavior may expose files, configuration, or data accessible to the application.
  • Integrity compromise: An attacker may modify files, application state, or stored information.
  • Service disruption: Resource-intensive or unsafe object handling can contribute to crashes and availability loss.
  • Downstream compromise: Exposed application credentials may create additional attack paths into connected infrastructure.

The presence of authenticated access or a perimeter control does not settle these questions. A trusted session may still reach an unsafe deserialization routine, and a web application firewall cannot always determine how application objects behave internally.

How Redbot validates deserialization risk

Redbot's manual penetration-testing approach is designed to establish whether an unsafe processing pattern translates into meaningful exposure within an authorized testing scope.

Trace the data flow

Identify relevant deserialization functions and determine whether a user, API client, external integration, or stored value can influence the data supplied to them.

Evaluate application classes and dependencies

Review the class graph for dangerous lifecycle behavior, including operations that use properties without sufficient validation or authorization.

Demonstrate impact safely

Use controlled, non-destructive proof-of-concept validation where explicitly authorized. Document the precise condition that crosses a security boundary, rather than relying only on theoretical exploit potential.

Assess business exposure

Determine how privileges, sensitive data access, identity context, and network reach affect the severity of the demonstrated weakness.

Retest the remediation

Confirm that untrusted values can no longer reach unsafe object reconstruction and that alternate routes, APIs, or processing paths do not reintroduce the vulnerability.

Prevention and secure implementation

  • Avoid native object deserialization for untrusted data. Prefer data-only formats such as JSON, with explicit schema and type validation.
  • Treat allowed_classes as a constraint, not a complete defense. PHP's guidance still warns against untrusted data being passed to unserialize().
  • Protect trusted serialized values. If a trusted system must exchange serialized objects, use strong origin and integrity verification before processing them.
  • Review third-party components. Dependencies may contain methods that enable unintended chains through ordinary lifecycle behavior.
  • Enforce least privilege. Restrict filesystem access, secrets, command execution, and network privileges for the application process.
  • Test regressions and alternate paths. Verify that fixes cover relevant roles, API routes, caches, queues, and background processing.

Where integrity controls are required, a properly implemented message authentication code can help detect tampering with trusted serialized data. This does not make arbitrary untrusted object input safe.

Why this still matters in modern PHP applications

PHP remains common in content management systems, customer portals, custom business applications, and integrations. Legacy serialization patterns can survive migrations and redesigns because they continue to function as expected under normal use.

The risk is that an unsafe entry point may be hidden behind a seemingly routine feature. Organizations need to examine both the vulnerable code path and the operational context that determines the consequence of exploiting it.

Manual validation provides a clearer answer than a checklist result: what can the attacker influence, which behavior can be triggered, and what business resource is ultimately exposed?

Validate beyond the finding

PHP insecure deserialization is a clear example of the gap between detecting suspicious code and proving a real security exposure. Understanding the reachable method chain, execution context, and affected resources is essential to prioritizing remediation.

Redbot Security performs manual web application and API penetration testing focused on reproducible attack paths and practical evidence.

Finding Vulnerabilities Is Not the Same as Validating Exposure.
Get a Testing Quote Explore Web App Testing

Common questions

Is every use of unserialize() exploitable?

No. Exploitability depends on whether the data is attacker-controlled, which classes and methods are available, and the actions the application can perform. PHP nonetheless advises against using it with untrusted input.

Does allowed_classes make untrusted input safe?

No. It can restrict object reconstruction, but it does not replace secure data handling or make arbitrary untrusted serialized input safe.

How is PHP object injection different from SQL injection?

SQL injection abuses the construction or execution of database queries. PHP object injection manipulates serialized objects and may trigger unintended application method behavior. The attack surfaces and prerequisites differ.

Can an automated scanner prove remote code execution?

A scanner may flag a suspected deserialization entry point or a known pattern. Confirming code execution requires additional application-specific evidence and authorized testing.

Technical references

PHP Manual — unserialize() · OWASP — PHP Object Injection · OWASP Deserialization Cheat Sheet · OWASP Web Security Testing Guide.

Technical guidance and enterprise implications are Redbot Security's analysis. Examples are illustrative; no specific third-party compromise is alleged.