# CVE-2025-12058: PYSEC-2026-1487 - Keras is vulnerable to arbitrary local file loading and Server-Side Request Forgery

Source: https://junglewise.ai/threats/cve-2025-12058-keras-is-vulnerable-to-arbitrary-local-file-loading-and-server  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2025-10-29  
License: CC BY 4.0 with a link back

CVE-2025-12058 · Severity: medium · CVSS 4 · Published 2025-10-29

The Keras.Model.load_model method, including when executed with the intended security mitigation safe_mode=True, is vulnerable to arbitrary local file loading and Server-Side Request Forgery (SSRF).


This vulnerability stems from the way the StringLookup layer is handled during model loading from a specially crafted .keras archive. The constructor for the StringLookup layer accepts a vocabulary argument that can specify a local file path or a remote file path.

  *  Arbitrary Local File Read: An attacker can create a malicious .keras file that embeds a local path in the StringLookup layer's configuration. When the model is loaded, Keras will attempt to read the content of the specified local file and incorporate it into the model state (e.g., retrievable via get_vocabulary()), allowing an attacker to read arbitrary local files on the hosting system.


  *  Server-Side Request Forgery (SSRF): Keras utilizes tf.io.gfile for file operations. Since tf.io.gfile supports remote filesystem handlers (such as GCS and HDFS) and HTTP/HTTPS protocols, the same mechanism can be leveraged to fetch content from arbitrary network endpoints on the server's behalf, resulting in an SSRF condition.


The security issue is that the feature allowing external path loading was not properly restricted by the safe_mode=True flag, which was intended to prevent such unintended data access.

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

## Quick answers

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

**How severe is CVE-2025-12058?** Medium severity, with a CVSS score of 4, published 29 October 2025.

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

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

**Am I affected by CVE-2025-12058?** 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.12.0 or later

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


## Affected products

- keras (PyPI) ECOSYSTEM:introduced=0,fixed=3.12.0

## Identifiers

- CVE-2025-12058
- GHSA-mq84-hjqx-cwf2
- PYSEC-2026-1487

## 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)
