Summary
Apache Spark's History Server contains an unsafe Jackson deserialization flaw in how it parses event log JSON, allowing arbitrary class instantiation via polymorphic deserialization.
If an attacker can write to the Spark event logs directory, they can inject malicious JSON that triggers execution of unintended classes during deserialization, potentially leading to command execution on the host running the History Server.
Affected context
The issue appears in Apache Spark deployments that:
- Enable event logging and persist logs to a filesystem or object store
- Run the Spark History Server to load and analyze those event logs
- Use versions of Spark where SparkListenerEvent objects are deserialized with Jackson polymorphic typing (e.g., 3.5.4 and earlier 3.x / affected 4.0 releases)
The vulnerability is relevant when the event log storage location is writable by users or processes that are not fully trusted, including shared clusters, multi-tenant environments, or misconfigured storage permissions.
Exploit preconditions
- Attack surface: Spark History Web UI / History Server backend, specifically the event log loading/deserialization logic.
- Required access: Ability to create, overwrite, or modify Spark event log files in the directory (or bucket) that the History Server reads from.
- Trigger point: When the History Server starts or reloads/parses an event log file, it deserializes the injected JSON as SparkListenerEvent data.
- Why exploitation is possible: Jackson is configured with
@JsonTypeInfo.Id.CLASSfor polymorphic deserialization of SparkListenerEvent objects, allowing the JSON payload to specify arbitrary class names. This enables construction of unexpected classes whose constructors or initialization logic can perform network calls or other side effects, effectively granting code execution capabilities.
Why this happens
The root cause is the use of overly permissive polymorphic deserialization in Jackson for untrusted event log data.
By using @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) or equivalent configuration on SparkListenerEvent, the deserializer trusts a class/type field from JSON to determine which Java class to instantiate. When this mechanism is applied to data that can be influenced by attackers (event logs), it becomes a classic CWE-502: Unsafe Deserialization scenario. Instead of restricting deserialization to a fixed, known set of event types, the system allows arbitrary class names, some of which may execute external calls or perform other actions during construction or initialization. This design ties data parsing directly to execution-capable behavior, which is the core unsafe pattern.
Potential impact
- Remote code execution on the host running the Spark History Server via gadget chains or classes with side-effectful initialization.
- Outbound network connections to attacker-controlled endpoints (e.g., JDBC, HTTP, RPC) enabling data exfiltration or pivoting.
- Unauthorized access to sensitive cluster metadata, job information, or credentials accessible to the History Server process.
- Use of the compromised History Server as a foothold for lateral movement across the Spark cluster or wider infrastructure.
- Denial of service of the History Server process through malicious payloads that crash or hang deserialization.
General mitigation guidance
Effective mitigation centers on removing unsafe deserialization patterns and hardening the event log trust boundary:
- Replace Jackson polymorphic deserialization based on
Id.CLASSwith a closed set of allowed subtypes (e.g.,Id.NAMEwith explicit type mappings, or explicit DTOs). - Treat event logs as untrusted input, even when produced by Spark itself, and avoid tying deserialization directly to executable or side-effectful classes.
- Introduce a strict schema for event log JSON and validate incoming data against that schema before deserialization.
- Use dedicated, side-effect-free data structures for event representation instead of reusing classes that perform I/O, network access, or system operations in constructors or deserialization callbacks.
- Apply least privilege to the History Server process (reduced OS permissions, no unnecessary credentials, network egress controls) to limit damage from a successful exploit.
- Restrict write permissions to the event log directory or bucket to trusted principals only, and avoid sharing it broadly across tenants or untrusted jobs.
How teams detect issues like this
Detection can focus on both code-level patterns and operational indicators:
- Use static analysis or code review to flag Jackson usage with:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)or equivalent polymorphic typing based on fully qualified class names.- Deserialization of data originating from files, logs, or network sources without prior validation.
- During manual review, look for:
- Event log or audit log parsers that deserialize directly into domain objects or connection-related classes.
- Reuse of driver or connector classes (e.g., JDBC connection classes) as deserialization targets instead of pure data containers.
- Employ SAST/IAST tools configured with rules for unsafe deserialization and dangerous Jackson configurations.
- Monitor runtime behavior of the History Server for:
- Unexpected outbound connections (e.g., JDBC connections to unrecognized hosts).
- Crashes or exceptions related to Jackson deserialization when loading event logs.
- Implement operational controls such as:
- File integrity monitoring or checksums on event log directories to detect tampering.
- Logging and alerting on changes to event log storage locations in multi-tenant or shared environments.

