# CVE-2025-12058: Vulnerability in Keras Model.load_model Leading to Arbitrary Local File Loading and SSRF

> Attackers can exploit Keras model loading to read local files or trigger SSRF, bypassing safe_mode protections.

- **Severity:** Medium 5.9 (`CVSS:4.0/AV:A/AC:H/AT:P/PR:L/UI:P/VC:H/VI:L/VA:L/SC:H/SI:L/SA:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 29 Oct 2025
- **Updated:** 29 Oct 2025
- **Also known as:** AZL-69021, AZL-69583, DEBIAN-CVE-2025-12058, GHSA-mq84-hjqx-cwf2, GHSA-qg93-c7p6-gg7f, MINI-vv29-78q5-cvm9, OESA-2025-2689, OESA-2025-2690, OESA-2025-2691, PYSEC-2026-1487, UBUNTU-CVE-2025-12058

## What is CVE-2025-12058?

CVE-2025-12058 is a medium-severity server-side request forgery vulnerability in Keras, published on 29 Oct 2025. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

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.

Weakness: CWE-502 (Deserialization of Untrusted Data)

## Which versions are affected by CVE-2025-12058?

3 open source packages ship an affected version, including keras.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `keras` | PyPI | All versions | 3.12.0 |
| `keras` | PyPI | All versions | 3.12.0 |
| `keras` | PyPI | All versions | 3.12.0 |

## How do I fix CVE-2025-12058?

Upgrade keras to 3.12.0 or later.

## Is CVE-2025-12058 being exploited?

There is no known exploitation of CVE-2025-12058 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-12058 and fix it if it is affected.

What it is: CVE-2025-12058 is a medium-severity server-side request forgery vulnerability in Keras, published on 29 Oct 2025. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2025-12058 in the wild and no public exploit code.

Affected packages and fixed versions:
- keras (PyPI): affected all versions; fixed in 3.12.0
- keras (PyPI): affected all versions; fixed in 3.12.0
- keras (PyPI): affected all versions; fixed in 3.12.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2025-12058/ (Markdown: https://insights.sbomify.com/CVE-2025-12058/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2025-12058
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2025-12058
- OSV: https://osv.dev/vulnerability/CVE-2025-12058

---
From sbomify Insights: https://insights.sbomify.com/CVE-2025-12058/
Summaries are generated and may contain mistakes; the official description above is the record.
