# CVE-2025-9906: Keras arbitrary code execution via untrusted model deserialization

Source: https://junglewise.ai/threats/cve-2025-9906-keras-arbitrary-code-execution-via-untrusted-model-deserialization  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2025-09-19. Updated: 2026-05-29  
License: CC BY 4.0 with a link back

CVE-2025-9906 · Severity: high · CVSS 7.3 · Published 2025-09-19

Keras, a popular deep learning library, is vulnerable to a security flaw that allows for arbitrary code execution when loading a specially crafted model file. Even if 'safe mode' is enabled, a malicious model can bypass these protections and run unauthorized commands on the user's system. This could lead to a complete system compromise or data theft if a user is tricked into opening an untrusted model file.

Technologies: [keras (PyPI)](https://junglewise.ai/threats/technologies/keras). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2025-9906 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2025-9906 being exploited in the wild.

**How severe is CVE-2025-9906?** High severity, with a CVSS score of 7.3, published 19 September 2025.

**Which products and versions are affected?** keras (PyPI) < 3.11.0, ECOSYSTEM:introduced=0,fixed=3.11.0.

**Is there a fix for CVE-2025-9906?** Yes. keras (PyPI): upgrade to 3.11.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2025-9906 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2025-9906?** Check whether you run keras (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- keras (PyPI): upgrade to 3.11.0 or later

  ```sh
  pip install "keras>=3.11.0"
  ```


## Technical details

A deserialization vulnerability exists in Keras versions prior to 3.11.0 due to the order in which model archives are processed. The archive's 'config.json' is parsed before layer deserialization, allowing a crafted configuration to invoke 'keras.config.enable_unsafe_deserialization()', which disables safe mode. An attacker can then include a 'Lambda' layer with a pickled function that executes arbitrary Python code upon loading. This bypasses the 'safe_mode=True' setting. The vulnerability is addressed in version 3.11.0 by enforcing safe-mode semantics before reading user-controlled configurations.

## Affected products

- Keras Team Keras < 3.11.0

## Identifiers

- CVE-2025-9906
- GHSA-36fq-jgmw-4r9c
- PYSEC-2025-76

## Timeline

- 2025-09-19: disclosed: Vulnerability disclosed and CVE-2025-9906 assigned.
- 2025-09-19: advisory: GitHub Advisory GHSA-36fq-jgmw-4r9c published.
- 2025-09-19: patched: Fixed in Keras version 3.11.0.

## References

- [https://api.github.com/users/cai0duque](https://api.github.com/users/cai0duque)
- [https://github.com/cai0duque](https://github.com/cai0duque)
- [https://api.github.com/users/cai0duque/gists%7B/gist_id%7D](https://api.github.com/users/cai0duque/gists%7B/gist_id%7D)
- [https://api.github.com/users/cai0duque/repos](https://api.github.com/users/cai0duque/repos)
- [https://avatars.githubusercontent.com/u/147485273?v=4](https://avatars.githubusercontent.com/u/147485273?v=4)
- [https://api.github.com/users/cai0duque/events%7B/privacy%7D](https://api.github.com/users/cai0duque/events%7B/privacy%7D)

## Related threats

- [Keras model loading denial of service via HDF5 shape bombs](https://junglewise.ai/threats/cve-2026-12570-keras-model-loading-denial-of-service-via-hdf5-shape-bombs)
- [Keras HDF5 arbitrary file disclosure via ExternalLinks](https://junglewise.ai/threats/cve-2026-9335-keras-hdf5-arbitrary-file-disclosure-via-externallinks)
- [Keras unsafe deserialization in TorchModuleWrapper](https://junglewise.ai/threats/cve-2026-12484-keras-unsafe-deserialization-in-torchmodulewrapper)
- [Keras path traversal via symlink in filter_safe_tarinfos](https://junglewise.ai/threats/cve-2026-12482-keras-path-traversal-via-symlink-in-filter-safe-tarinfos)
- [Keras Team Keras arbitrary code execution in Lambda layer](https://junglewise.ai/threats/cve-2026-12481-keras-team-keras-arbitrary-code-execution-in-lambda-layer)
