Summary
OpenSTAManager's oauth2.php endpoint unsafely calls PHP's unserialize() on attacker-influenced data from the database without any class restrictions.
Because this endpoint is unauthenticated and uses a user-controlled GET parameter to select the record, an attacker who can influence the serialized access_token field may trigger arbitrary object instantiation and potentially achieve remote code execution or application compromise.
Affected context
The vulnerability occurs in the OAuth2 integration flow implemented by OpenSTAManager's oauth2.php script.
This endpoint:
- Is explicitly configured to skip permission checks (unauthenticated access)
- Selects a record from the
zz_oauth2table using the attacker-controlledstateGET parameter - Deserializes the
access_tokenfield using PHP'sunserialize()with no class restrictions
The risk is most pronounced when the stored access_token field can be influenced, directly or indirectly, by untrusted input or when dangerous gadget classes are available in the application's codebase.
Exploit preconditions
- Attack surface: Publicly reachable web endpoint
oauth2.php. - Required access: No authentication required; attacker needs HTTP access to the endpoint and a way to reference or influence records in
zz_oauth2. - Trigger point: Invocation of the OAuth2 configuration or callback flow where oauth2.php:
- Reads the
stateparameter from the query string - Loads the corresponding record from
zz_oauth2 - Calls
unserialize()on theaccess_tokencolumn. - Why exploitation is possible:
stateis used directly to select the database record, giving the attacker control over which serialized blob is deserialized.- PHP's
unserialize()is used without any class whitelist or allowed_classes restriction. - Presence of autoloaded classes and known gadget chains can allow attacker-controlled objects to execute logic during deserialization.
Why this happens
The core issue is the use of PHP's unserialize() on data that is not guaranteed to be fully trusted, with no restrictions on which classes may be instantiated.
This fits CWE-502: Deserialization of Untrusted Data, where serialized structures are treated as inherently safe and deserialized into live objects within the application's execution context.
In this pattern:
- A database field (
access_token) stores serialized PHP data. - An unauthenticated request parameter (
state) determines which record is loaded. - The application assumes the stored serialized blob is safe and invokes
unserialize()directly.
Because PHP object deserialization can trigger magic methods (__wakeup, __destruct, etc.) and other side effects, any available gadget chain in the application or its dependencies can potentially be abused by attackers to perform unauthorized actions, including remote code execution.
Potential impact
- Remote code execution via gadget chains present in application or library classes
- Execution of arbitrary application-level actions with the server's privileges
- Unauthorized access to or manipulation of application data
- Session hijacking or elevation of privileges if sensitive objects are deserialized
- Interference with OAuth2 integration, including token theft or misuse
- Denial of service by crafting payloads that cause resource exhaustion or fatal errors during deserialization
General mitigation guidance
Effective mitigation focuses on eliminating unsafe deserialization and tightening trust boundaries around serialized data:
- Avoid using
unserialize()for application data where possible; prefer safer data formats such as JSON that do not carry code or object behavior. - If deserialization is unavoidable, use mechanisms that:
- Restrict allowed classes (e.g., allowed_classes) to a minimal, well-reviewed set of simple value objects.
- Store only primitive data structures and reconstruct objects explicitly in application logic.
- Treat all data loaded from external systems or databases that may be influenced by users as untrusted:
- Validate and sanitize inputs that determine which records are loaded (such as
state). - Ensure that the records being deserialized cannot be modified by low-privilege or unauthenticated users.
- Reduce the power of gadget chains by:
- Reviewing classes with dangerous side effects in magic methods and refactoring them to avoid network, filesystem, or command execution in those methods.
- Apply least-privilege principles to the web server and application runtime, so that a successful exploit has reduced impact.
How teams detect issues like this
Organizations can identify and monitor unsafe deserialization patterns using several complementary approaches:
- Static analysis:
- Define rules to flag uses of
unserialize()and similar APIs across the codebase. - Highlight cases where deserialization sources are database fields or request-driven selections.
- Look for absence of allowed class restrictions or explicit checks on data being deserialized.
- Code review practices:
- Treat any usage of serialization/deserialization APIs as high-risk and require security-focused review.
- Inspect OAuth2 and other integration flows for unauthenticated endpoints that process dynamic or indirect input from users.
- Review magic methods (
__wakeup,__sleep,__destruct) for side effects that could form gadget chains. - Runtime and logging:
- Add logging around deserialization operations to capture unexpected or malformed payloads.
- Monitor for anomalies such as unusual
stateparameter values or repeated failed OAuth2 flows. - Automated tooling:
- Integrate SAST tools that detect unsafe deserialization patterns into CI/CD pipelines.
- Use dependency and configuration scanners to identify known gadget-prone libraries or prior unsafe deserialization issues.

