CVE-2025-9906: Keras Keras Is Vulnerable To Deserialization Vulnerability

HIGH
Advisory Identifier: GHSA-36fq-jgmw-4r9c
CVSS 7.3
CWE-502
Published
Advisory Summary

CVE-2025-9906 is a HIGH (CVSS 7.3) keras is vulnerable to deserialization vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Keras libraries in the PyPI ecosystem. The issue involves keras is vulnerable to deserialization of untrusted data. Remediation is available by upgrading affected packages to version 3.11.0.

CVE-2025-9906 at a Glance

CVE Identifier CVE-2025-9906
GHSA Identifier GHSA-36fq-jgmw-4r9c
Severity HIGH
CVSS v3.1 Base Score 7.3
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product Keras
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2025-9906

To remediate this vulnerability, upgrade all affected Keras dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

keras fixed: 3.11.0
pip install keras>=3.11.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show keras

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2025-9906, inspect your installed packages using pip:

pip show keras

Analyze the terminal output to locate any version of Keras in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.11.0), your application is affected.

Note: The pip show keras command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In Keras, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Arbitrary Code Execution in Keras Keras versions prior to 3.11.0 allow for arbitrary code execution when loading a crafted `.keras` model archive, even when `safe_mode=True`. The issue arises because the archive’s `config.json` is parsed before layer deserialization. This can invoke `keras.config.enable_unsafe_deserialization()`, effectively disabling safe mode from within the loading process itself. An attacker can place this call first in the archive and then include a `Lambda` layer whose function is deserialized from a pickle, leading to the execution of attacker-controlled Python code as soon as a victim loads the model file. Exploitation requires a user to open an untrusted model; no additional privileges are needed. The fix in version 3.11.0 enforces safe-mode semantics *before* reading any user-controlled configuration and prevents the toggling of unsafe deserialization via the config file. **Affected versions:** < 3.11.0 **Patched version:** 3.11.0 It is recommended to upgrade to version 3.11.0 or later and to avoid opening untrusted model files.

CVE-2025-9906 Affected Keras Versions

1 component(s)
Fixed Versions:
3.11.0
Product / Package Ecosystem Affected Versions Fixed Version
keras
PyPI
< 3.11.0
3.11.0

References

Frequently Asked Questions

What is CVE-2025-9906?
CVE-2025-9906 is a security vulnerability in Keras involving Keras is vulnerable to Deserialization of Untrusted Data under CWE-502: Deserialization of Untrusted Data.
Which Keras versions are affected?
Affected versions include releases prior to 3.11.0 across affected packages: keras.
What version fixes CVE-2025-9906?
Upgrading to 3.11.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is keras affected?
Yes, keras is affected in releases prior to 3.11.0. Upgrade your dependency to 3.11.0 or later.
What is the CVSS score of CVE-2025-9906?
CVE-2025-9906 has a CVSS v3.1 base score of 7.3 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2025-9906?
CVE-2025-9906 is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check PyPI dependencies for CVE-2025-9906?
Run the dependency tree command: 'pip show keras'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-36fq-jgmw-4r9c",
  "modified" : "2026-05-29T20:50:12Z",
  "published" : "2025-09-19T09:31:14Z",
  "aliases" : [ "CVE-2025-9906" ],
  "summary" : "Keras is vulnerable to Deserialization of Untrusted Data",
  "details" : "### Arbitrary Code Execution in Keras\n\nKeras versions prior to 3.11.0 allow for arbitrary code execution when loading a crafted `.keras` model archive, even when `safe_mode=True`.\n\nThe issue arises because the archive’s `config.json` is parsed before layer deserialization. This can invoke `keras.config.enable_unsafe_deserialization()`, effectively disabling safe mode from within the loading process itself. An attacker can place this call first in the archive and then include a `Lambda` layer whose function is deserialized from a pickle, leading to the execution of attacker-controlled Python code as soon as a victim loads the model file.\n\nExploitation requires a user to open an untrusted model; no additional privileges are needed. The fix in version 3.11.0 enforces safe-mode semantics *before* reading any user-controlled configuration and prevents the toggling of unsafe deserialization via the config file.\n\n**Affected versions:** < 3.11.0\n**Patched version:** 3.11.0\n\nIt is recommended to upgrade to version 3.11.0 or later and to avoid opening untrusted model files.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "keras"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.11.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-9906"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/keras-team/keras/pull/21429"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/keras-team/keras/commit/713172ab56b864e59e2aa79b1a51b0e728bba858"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/keras-team/keras"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/keras-team/keras/releases/tag/v3.11.0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/keras/PYSEC-2025-76.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://osv.dev/vulnerability/CVE-2025-9906"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-09-19T17:16:44Z",
    "nvd_published_at" : "2025-09-19T09:15:36Z"
  }
}