/

CVE-2026-33942

Severity:

CRITICAL RISK

(9.8)

Unsafe Deserialization in Saloon AccessTokenAuthenticator

CVE-2026-33942

Analyzed

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution / PHP Object Injection

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 AccessTokenAuthenticator to 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 with allowed_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 with allowed_classes => true or 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 set allowed_classes => true or 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).

Sources

SourceLink
docs.saloon.devdocs.saloon.dev/upgrade/upgrading-from-v3-to-v4
github.comgithub.com/saloonphp/saloon/security/advisories/GHSA-rf88-776r-rcq9

Frequently asked

questions

It can be, depending on how serialized token data is stored and controlled. If an attacker can influence the storage backing the token cache (directly or via an injection flaw in another component), they may be able to exploit this purely through network interactions with the application.

Not necessarily. The key requirement is the ability to control or overwrite the serialized token data that AccessTokenAuthenticator::unserialize() consumes. In some deployments this might require authenticated access; in others, misconfigured file permissions, shared caches, or secondary vulnerabilities could provide that capability without authentication.

Remove PHP object serialization from authentication flows altogether. Store OAuth tokens as simple, structured data (such as JSON or associative arrays) and reconstruct authenticator instances manually from those primitives rather than deserializing full objects.

Adopt a design rule that untrusted or semi-trusted data should never be fed into generic object deserialization mechanisms. Prefer data-oriented formats (JSON, protocol buffers, simple arrays), restrict the use of magic methods, enforce strict schema validation for stored state, and include checks for unsafe deserialization in code review and automated security testing.

Find out what's already
exploitable in your codebase.