The vulnerability exists within the custom object serialization/deserialization logic implemented in APScheduler's JSONSerializer and CBORSerializer. The root cause is the unmarshal_object function in src/apscheduler/_marshalling.py. This function insecurely reconstructs Python objects from serialized data. It dynamically resolves a class from a string reference provided in the payload, instantiates it, and then calls its __setstate__ method with attacker-controlled data. This pattern is a classic example of CWE-502: Deserialization of Untrusted Data.
The JSONSerializer and CBORSerializer use this vulnerable unmarshal_object function within their respective deserialization hooks (_object_hook for JSON and _tag_hook for CBOR). When an application using these serializers deserializes a specially crafted payload, the hooks identify a special marker (a key for JSON, a tag for CBOR) and divert the data to unmarshal_object. This allows an attacker to instantiate any class available in the application's scope and call its __setstate__ method, leading to Remote Code Execution if a suitable gadget class (e.g., one that executes system commands) is present.