The vulnerability is a safe mode bypass in Keras's model deserialization process, allowing for arbitrary code execution. The root cause lies in the _retrieve_class_or_fn function within keras/src/saving/serialization_lib.py. This function was responsible for dynamically loading classes specified in a .keras model file. Before the patch, it lacked proper validation and would load any class from any module, which is a classic deserialization of untrusted data vulnerability (CWE-502).
The patch, identified in commit 713172ab56b864e59e2aa79b1a51b0e728bba858, mitigates this by introducing a strict check. It ensures that any class being deserialized is a subclass of KerasSaveable. This change restricts the types of objects that can be created during deserialization to known, safe Keras components.
The primary entry point for this vulnerability is the keras.saving.saving_lib.load_model function, which is the public API developers use to load models. An attacker would convince a victim to load a malicious model file using this function. During a runtime analysis of an exploit, both load_model and the underlying _retrieve_class_or_fn would appear in the execution profile, with the former being the trigger and the latter being the exact location of the security flaw.