Keras Framework Arbitrary Code Execution Vulnerability in TorchModuleWrapper Class

Vulnerability

A vulnerability allowing arbitrary code execution exists in the Keras framework, specifically in versions 3.11.0 prior to 3.11.3. The issue arises in the TorchModuleWrapper class, where the from_config method deserializes model data using torch.load() with the weights_only parameter set to False. This configuration causes Torch to rely on Python's pickle module for deserialization, which is inherently unsafe and can execute arbitrary code. A maliciously crafted Keras model file could exploit this behavior, executing unauthorized commands on the user's system when the model is loaded, even with safe mode enabled. The vulnerability can be triggered with both local and remote files.

Impact

Exploitation of this vulnerability allows for arbitrary code execution on the user's system.

Reproduction

The vulnerability can be reproduced by creating a Keras model file that includes a malicious payload designed to execute code when the model is deserialized. This can be done by embedding the payload into the model's configuration and then saving it as a .keras file. Once the file is created, it can be loaded in Keras, triggering the execution of the embedded code. This vulnerability can also be reproduced with remote files by using the hf: link to load a malicious model from a private repository.

Remediation

Users can upgrade to Keras version 3.11.3, which disables the unsafe deserialization in the TorchModuleWrapper class when safe mode is enabled.

Added: Oct 17, 2025, 4:21 PM
Updated: Oct 17, 2025, 4:21 PM

Vulnerability Rating

Custom Algorithm
spread
0.0
impact
10.0
exploitability
8.7
remediation
7.7
relevance
0.8
threat
6.4
urgency
2.9
incentive
5.8

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.