Arbitary Code execution in Keras load_model()
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 .h5/.hdf5 model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed.
This is achieved by crafting a special .h5 archive file that uses the Lambda layer feature of keras which allows arbitrary Python code in the form of pickled code. The vulnerability comes from the fact that the safe_mode=True option is not honored when reading .h5 archives.
Note that the .h5/.hdf5 format is a legacy format supported by Keras 3 for backwards compatibility.
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.0.0, < 3.11.3 | 3.11.3 |
Affected products
5- osv-coords4 versionspkg:apk/chainguard/tensorflow-cpu-jupyterpkg:apk/chainguard/tensorflow-gpu-jupyterpkg:apk/wolfi/tensorflow-cpu-jupyterpkg:pypi/keras
< 2.20.0-r1+ 3 more
- (no CPE)range: < 2.20.0-r1
- (no CPE)range: < 2.20.0-r1
- (no CPE)range: < 2.20.0-r1
- (no CPE)range: >= 3.0.0, < 3.11.3
- Range: 3.0.0
Patches
Vulnerability mechanics
References
5- github.com/keras-team/keras/pull/21602ghsapatchWEB
- github.com/advisories/GHSA-36rr-ww3j-vrjvghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2025-9905ghsaADVISORY
- github.com/keras-team/keras/security/advisories/GHSA-36rr-ww3j-vrjvghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/keras/PYSEC-2025-123.yamlghsaWEB
News mentions
0No linked articles in our index yet.