Summary
Seroval versions 1.4.0 and below contain an unsafe JSON deserialization flaw that can lead to arbitrary JavaScript code execution when processing specially crafted serialized values.
In client-to-server transmission scenarios, an attacker who can influence serialized payloads and understand how they are later used can abuse constant value and error deserialization logic to indirectly trigger unsafe JS evaluation.
Affected context
This issue arises in applications that use Seroval (≤1.4.0) to stringify and then deserialize complex JavaScript values across a client–server boundary, particularly via the fromJSON and fromCrossJSON APIs.
The vulnerability tends to surface where:
- Client-controlled or partially untrusted data is serialized with Seroval on one side and deserialized on the other, and
- The reconstructed objects or errors are later passed into higher-privilege logic (for example, evaluation paths, error handling frameworks, or dynamic dispatch) without strict validation.
It does not affect deployments that never deserialize attacker-controlled Seroval payloads or only use Seroval for purely local, trusted state.
Exploit preconditions
- Attack surface: Client-to-server (or cross-context) interfaces that accept Seroval-encoded JSON and invoke
fromJSONorfromCrossJSON. - Required access: Ability to submit or influence serialized payloads over at least four separate requests to the same deserialization entry point, along with some understanding of how the resulting values are consumed.
- Trigger point: Deserialization of crafted data followed by runtime processing that reaches the unsafe evaluation paths exposed via constant value or error reconstruction.
- Why exploitation is possible: The deserialization logic implicitly trusts structural metadata in the serialized form and allows overriding of constant values and error representations in ways that can be coerced into indirect code execution, matching the unsafe deserialization pattern described in CWE-502.
Why this happens
The root cause is an unsafe deserialization design in which JSON data is treated as a fully trusted description of complex JavaScript values, including constants and error objects.
Seroval's fromJSON and fromCrossJSON accept structured input that can control how certain internal constructs are reconstructed, effectively granting the data the authority to influence program behavior beyond plain data assignment.
Because there is no strong boundary between "data" and "behavior" in these reconstruction routines, an attacker can craft payload sequences that steer deserialization toward internal evaluation-like mechanisms or dangerous code paths.
This maps directly to CWE-502: Unsafe Deserialization, where serialized input can cause the creation or activation of objects with side effects that were not intended by the receiving code.
Potential impact
- Execution of arbitrary JavaScript code in the server or privileged runtime context that processes the deserialized objects
- Bypass of application-level security checks that assume serialized data is passive and non-executable
- Unauthorized access to in-memory data accessible from the exploited execution context
- Escalation of privileges within the application, such as impersonating other users or tampering with protected state
- Facilitation of secondary attacks, such as data exfiltration or logic manipulation in downstream components
General mitigation guidance
Effective mitigation focuses on tightening deserialization boundaries and reducing the expressive power of incoming data:
- Prefer data-only serialization formats for untrusted inputs, restricting deserialization to primitives and plain objects without special constructors or error semantics.
- Treat all cross-boundary Seroval payloads as untrusted; validate structure and whitelisted fields before passing them into any deserialization routine.
- Avoid patterns where deserialized values can influence dynamic code execution, such as feeding reconstructed objects into evaluators, interpreters, or reflection-heavy dispatch mechanisms.
- Isolate deserialization and subsequent processing into low-privilege components or sandboxes, ensuring that a compromised deserialization path cannot impact the broader application.
- Apply the principle of least privilege to any code that processes or routes deserialized data, limiting the capabilities of routines that operate directly on reconstructed objects or errors.
Adopting secure-by-default serialization choices and keeping behavioral logic separate from data reconstruction significantly reduces the risk of similar flaws.
How teams detect issues like this
Organizations can approach detection by targeting both code patterns and runtime behavior:
- Static analysis: Flag usages of
fromJSON,fromCrossJSON, or similar Seroval deserializers where the source data originates from HTTP requests, message queues, or other untrusted channels. - Code review: Look for deserialization sites that:
- Accept data from clients or external services without robust validation,
- Reconstruct complex objects, errors, or constants, and
- Forward deserialized values into dynamic dispatch, plugin systems, or any form of indirect evaluation.
- Policy enforcement: Introduce guidelines that prohibit deserializing rich objects from untrusted input and require explicit justification for using advanced Seroval features over simpler JSON-based data structures.
- Automated tooling: Integrate linters or SAST tools that understand common unsafe deserialization APIs and can surface their use in CI, especially in request handlers and RPC endpoints.
- Runtime monitoring: Add logging or telemetry around deserialization endpoints to detect unusual patterns such as repeated crafted requests or unexpected object shapes emerging from deserialization.

