Summary
Saloon versions prior to 4.0.0 used PHP's unserialize() in AccessTokenAuthenticator::unserialize() with allowed_classes => true to restore OAuth token state from cache or storage.
If an attacker can control the serialized token string (for example, by overwriting a cached token file or injecting into storage), they can supply a gadget object that triggers PHP magic methods and, in common dependency stacks, potentially achieve remote code execution.
Affected context
This vulnerability affects Saloon-based PHP applications that:
- Use
AccessTokenAuthenticatorto persist and restore OAuth tokens - Store serialized authenticator/token data in cache, files, or other shared storage
- Load this state back using
unserialize()with broadly allowed classes
The risk materializes when an attacker can influence or overwrite the serialized token data before it is restored in the application process.
Exploit preconditions
- Attack surface: Application code paths that restore OAuth token/authenticator state via
AccessTokenAuthenticator::unserialize(). - Required access: Ability to control or tamper with the serialized data source (e.g., cached token files, cache keys/values, or other storage where serialized authenticators are kept).
- Trigger point: Any request or background job that causes the application to read the attacker-controlled serialized string and pass it to
unserialize(). - Why exploitation is possible:
unserialize()is invoked withallowed_classes => true, enabling arbitrary class instantiation.- PHP magic methods like
__wakeup()or__destruct()may execute application or library code during object hydration or destruction. - In environments with common gadget chains (such as those introduced by libraries like Monolog), this behavior can be combined to execute attacker-controlled logic, potentially leading to RCE.
Why this happens
The core issue is the use of PHP's generic unserialize() function on data that may not be fully trusted, combined with permissive class allowances.
This aligns with CWE-502: Deserialization of Untrusted Data, where serialized input is treated as a safe representation of application objects.
By allowing arbitrary classes to be instantiated during deserialization, the code opens the door to PHP Object Injection: attackers can craft serialized payloads that construct objects whose magic methods trigger unintended behavior.
The AccessTokenAuthenticator design couples token persistence with automatic object restoration, implicitly trusting the serialized bytes rather than separating token data from executable object behavior.
Potential impact
- Execution of arbitrary PHP code in the context of the vulnerable application (when a suitable gadget chain exists).
- Complete compromise of the affected web application, including access to application data and credentials.
- Privilege escalation within the hosting environment if the application has elevated permissions.
- Lateral movement to connected systems or services via stolen tokens or credentials.
- Manipulation or theft of OAuth access tokens, leading to unauthorized API calls on behalf of legitimate users or services.
General mitigation guidance
Effective mitigation focuses on eliminating unsafe deserialization and decoupling token state from executable PHP objects:
- Avoid using
unserialize()for restoring authentication or session-related state, especially withallowed_classes => trueor other permissive options. - Represent OAuth tokens and related state as simple, serializable data structures (arrays, JSON, or scalar fields) rather than as full PHP objects with behavior.
- Implement explicit, minimal data models for cached tokens (e.g., token string, expiry time, scopes) and reconstruct authenticator objects using these primitives at runtime.
- Treat all cached or stored authentication artifacts as untrusted input: validate format, enforce strict schemas, and reject unexpected fields.
- Apply least-privilege principles to application processes and storage backends so that compromise of a single component does not automatically grant broad system access.
- Where legacy code must still use serialization, restrict deserialization to a narrow set of allowed classes and centralize that logic under strict review.
How teams detect issues like this
Organizations can identify and monitor this class of vulnerability using a combination of static and operational techniques:
- Static analysis: Search for
unserialize()calls in the codebase, especially where input originates from cache, files, databases, user-controlled storage, or network sources. Flag uses that setallowed_classes => trueor omit the option entirely. - Code review: Treat any use of PHP serialization in authentication, session handling, or caching logic as a security-relevant hotspot. Review for assumptions about input trust and presence of magic methods on involved classes.
- Dependency review: Examine common libraries (e.g., logging frameworks, ORM, templating systems) for known gadget chains and assess where serialized data might instantiate those classes.
- Runtime monitoring: Instrument logging around token restoration and cache misses/hits, watching for anomalous token payload sizes or unexpected serialization formats that might indicate probing or exploitation attempts.
- Automated tooling: Integrate SAST or security linters into CI pipelines with rules that flag generic
unserialize()usage and encourage safer data-serialization primitives (such as JSON).

