/

CVE-2026-31072

Severity:

CRITICAL RISK

(9.8)

Unsafe Deserialization in APScheduler JSONSerializer and

CVE-2026-31072

Deferred

Vulnerability type

Category:

Unsafe Deserialization

CWE:

CWE-502

Impact:

Remote Code Execution

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

APScheduler's JSONSerializer and CBORSerializer perform insecure deserialization that can instantiate arbitrary Python classes and inject attacker-controlled state.

Any application that accepts untrusted JSON or CBOR data and passes it into these serializers may allow a remote attacker to achieve code execution within the application process.

Affected context

This vulnerability arises in Python applications that embed APScheduler and configure it to use the JSONSerializer or CBORSerializer with data that can be influenced by external users.

It is most relevant when:

  • Job definitions, job metadata, or scheduler messages are serialized/deserialized across trust boundaries (e.g., APIs, message queues, webhooks).
  • Untrusted or partially trusted JSON/CBOR payloads are passed directly into APScheduler's serializer.
  • The runtime environment exposes sensitive classes whose initialization or __setstate__ logic can perform side effects.

Exploit preconditions

  • Attack surface: Any endpoint, message queue consumer, RPC interface, or background worker that:
  • Accepts JSON or CBOR input, and
  • Deserializes it via APScheduler's JSONSerializer or CBORSerializer.
  • Required access: Ability to supply or control serialized job data or scheduler payloads (remote network access is sufficient if such interfaces are exposed).
  • Trigger point: Invocation of unmarshal_object during deserialization of attacker-supplied JSON/CBOR.
  • Why exploitation is possible: The deserializer:
  • Dynamically imports modules and looks up arbitrary classes referenced in the payload.
  • Instantiates those classes and calls __setstate__ with attacker-controlled data.
  • Does not enforce an allow-list of types or perform robust validation on the deserialized structure, matching the pattern described by CWE-502 (Unsafe Deserialization).

Why this happens

The underlying flaw is the use of a general-purpose object deserialization mechanism that implicitly trusts type information embedded in serialized data.

APScheduler's unmarshal_object reconstructs Python objects by:

  • Interpreting type metadata in the incoming JSON/CBOR payload.
  • Dynamically importing modules and resolving arbitrary classes available in the environment.
  • Calling special methods such as __setstate__ with attacker-controlled state.

This design couples data with executable behavior and treats serialized input as instructions for what code to run and which objects to create.

In CWE-502 terms, untrusted data is deserialized into live objects without applying strict type constraints, schema validation, or a safe object mapping, enabling remote code execution or other unintended side effects.

Potential impact

  • Remote execution of arbitrary code within the APScheduler-hosting process.
  • Execution of attacker-controlled logic during object construction or state restoration.
  • Compromise of application data, including reading or modifying database contents handled by scheduled jobs.
  • Lateral movement within the environment by abusing credentials, tokens, or network access available to the compromised process.
  • Denial of service by instantiating large or expensive objects, exhausting memory, CPU, or other resources.
  • Integrity loss of scheduled workflows, including the injection, modification, or deletion of jobs.

General mitigation guidance

Effective mitigation focuses on breaking the trust between untrusted serialized data and arbitrary object construction:

  • Prefer data-only serialization:
  • Use safe serializers that map incoming JSON/CBOR to primitive types and well-defined data structures, not arbitrary Python objects.
  • Represent jobs and scheduler configuration as explicit schemas or simple dictionaries, then manually construct objects from validated data.
  • Apply strict type allow-listing:
  • If object reconstruction is required, maintain an explicit list of allowed types and reject any payload referencing types outside this list.
  • Avoid dynamic module imports based on attacker-controllable input.
  • Enforce input validation and schema checks:
  • Validate JSON/CBOR against a strict schema before any deserialization logic that may create objects.
  • Reject unexpected fields, nested structures, or type metadata embedded in the payload.
  • Reduce privilege and side effects:
  • Run APScheduler and associated workers with the least privileges needed (filesystem, network, and credentials).
  • Separate high-privilege operations out of deserialization paths; avoid performing I/O or security-sensitive work in constructors or __setstate__.
  • Restrict exposure of serialization endpoints:
  • Avoid exposing internal scheduler serialization interfaces directly to the public internet.
  • Ensure that only trusted components (internal services, authenticated backends) can feed data into these serializers.

How teams detect issues like this

Identifying and monitoring this class of issue typically involves multiple layers of analysis:

  • Static analysis and code scanning:
  • Search for usage of APScheduler's JSONSerializer, CBORSerializer, or unmarshal_object in application code.
  • Flag patterns where these serializers are passed data originating from HTTP request bodies, message queues, or other untrusted channels.
  • Enforce rules that prevent dynamic type loading or module import based on deserialized content.
  • Code review cues:
  • During review, look for:
  • Deserialization of complex objects from JSON/CBOR instead of simple, schema-validated structures.
  • Logic that directly trusts type information or module paths from input data.
  • Constructors and __setstate__ implementations that perform I/O, system calls, or security-sensitive operations.
  • Runtime monitoring and logging:
  • Instrument deserialization paths to log unexpected class names, module imports, or unusual job definitions.
  • Monitor for anomalies such as:
  • Jobs that execute unfamiliar functions or modules.
  • Sudden spikes in scheduler activity or resource usage during deserialization.
  • Policy and CI/CD enforcement:
  • Incorporate security checks in CI pipelines that block new uses of unsafe object deserialization patterns.
  • Optionally use automated review tools configured to detect CWE-502 patterns and enforce organization-wide serialization guidelines.

Sources

SourceLink
gist.github.comgist.github.com/nedlir/11fb77f35a59cbba73392a086b02a9c6
github.comgithub.com/agronholm/apscheduler
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-31072
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2479907
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-31072.json

Frequently asked

questions

Yes, it can be remotely exploitable if an attacker can send JSON or CBOR payloads that the application passes into APScheduler's JSONSerializer or CBORSerializer without strict validation or type restrictions.

An attacker needs the ability to influence the serialized data that APScheduler deserializes—this might be via public HTTP endpoints, authenticated APIs, message queues, or any integration point that feeds user-controlled data into the scheduler's serializers.

The safest pattern is to avoid deserializing untrusted data into arbitrary Python objects. Use data-only serialization with explicit schemas, map incoming data to simple structures, and construct necessary objects manually after validation. If object deserialization is required, enforce a strict allow-list of permissible types.

Establish organization-wide guidelines that prohibit unsafe object deserialization from untrusted inputs, favor schema-based data formats, and require code review checks or automated tools to flag CWE-502 patterns. Additionally, keep constructors and __setstate__ methods free from security-sensitive side effects to reduce the blast radius of any serialization flaws.

Find out what's already
exploitable in your codebase.