Arbitrary Code execution in Keras Safe Mode
Description
The Keras Model.load_model method can be exploited to achieve arbitrary code execution, even with safe_mode=True.
One can create a specially crafted .keras model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special config.json (a file within the .keras archive) that will invoke keras.config.enable_unsafe_deserialization() to disable safe mode. Once safe mode is disable, one can use the Lambda layer feature of keras, which allows arbitrary Python code in the form of pickled code. Both can appear in the same archive. Simply the keras.config.enable_unsafe_deserialization() needs to appear first in the archive and the Lambda with arbitrary code needs to be second.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
kerasPyPI | < 3.11.0 | 3.11.0 |
Affected products
2- Range: 3.0.0
Patches
Vulnerability mechanics
References
7- github.com/keras-team/keras/pull/21429ghsapatchWEB
- github.com/advisories/GHSA-36fq-jgmw-4r9cghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2025-9906ghsaADVISORY
- github.com/keras-team/keras/commit/713172ab56b864e59e2aa79b1a51b0e728bba858ghsaWEB
- github.com/keras-team/keras/releases/tag/v3.11.0ghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/keras/PYSEC-2025-76.yamlghsaWEB
- osv.dev/vulnerability/CVE-2025-9906ghsaWEB
News mentions
0No linked articles in our index yet.