Skip to content
KerasGHSA-36rr-ww3j-vrjv

The Keras `Model.load_model` method **silently** ignores `safe_mode=True` and allows arbitrary code execution when a `.h5`/`.hdf5` file is loaded.

HighCVE-2025-9905 · Published Sep 19, 2025 · updated Sep 10, 2026

GitHub advisory

Affected versions

PackageAffectedFixed in
keras
PyPI
>= 3.0.0, < 3.11.33.11.3
Details and references

**Note:** This report has already been discussed with the Google OSS VRP team, who recommended that I reach out directly to the Keras team. I’ve chosen to do so privately rather than opening a public issue, due to the potential security implications. I also attempted to use the email address listed in your `SECURITY.md`, but received no response. --- ## Summary When a model in the `.h5` (or `.hdf5`) format is loaded using the Keras `Model.load_model` method, the `safe_mode=True` setting is **silently** ignored without any warning or error. This allows an attacker to execute arbitrary code on the victim’s machine with the same privileges as the Keras application. This report is specific to the `.h5`/`.hdf5` file format. The attack works regardless of the other parameters passed to `load_model` and does not require any sophisticated technique, `.h5` and `.hdf5` files are simply not checked for unsafe code execution. From this point on, I will refer only to the `.h5` file format, though everything equally applies to `.hdf5`. ## Details ### Intended behaviour According to the official Keras documentation, `safe_mode` is defined as: ``` safe_mode: Boolean, whether to disallow unsafe lambda deserialization. When safe_mode=False, loading an object has the potential to trigger arbitrary code execution. This argument is only applicable to the Keras v3 model format. Defaults to True. ``` I understand that the behavior described in this report is somehow **intentional**, as `safe_mode` is only applicable to `.keras` models. However, in practice, this behavior is misleading for users who are unaware of the internal Keras implementation. `.h5` files can still be loaded seamlessly using `load_model` with `safe_mode=True`, and the absence of any warning or error creates a **false sense of security**. Whether intended or not, I believe silently ignoring a security-related parameter is not the best possible design decision. At a minimum, if `safe_mode` cannot be applied to a given file format, an explicit error should be raised to alert the user. This issue is particularly critical given the widespread use of the `.h5` format, despite the introduction of newer formats. As a small anecdotal test, I asked several of my colleagues what they would expect when loading a `.h5` file with `safe_mode=True`. None of them expected the setting to be **silently** ignored, even after reading the documentation. While this is a small sample, all of these colleagues are cybersecurity researchers, experts in binary or ML security, and regular participants in DEF CON finals. I was careful not to give any hints about the vulnerability in our discussion. ### Technical Details Examining the implementation of `load_model` in `keras/src/saving/saving_api.py`, we can see that the `safe_mode` parameter is completely ignored when loading `.h5` files. Here's the relevant snippet: ```python def load_model(filepath, custom_objects=None, compile=True, safe_mode=True): is_keras_zip = ... is_keras_dir = ... is_hf = ... # Support for remote zip files if ( file_utils.is_remote_path(filepath) and not file_utils.isdir(filepath) and not is_keras_zip and not is_hf ): ... if is_keras_zip or is_keras_dir or is_hf: ... if str(filepath).endswith((".h5", ".hdf5")): return legacy_h5_format.load_model_from_hdf5( filepath, custom_objects=custom_objects, compile=compile ) ``` As shown, when the file format is `.h5` or `.hdf5`, the method delegates to `legacy_h5_format.load_model_from_hdf5`, which does not use or check the `safe_mode` parameter at all. ### Solution Since the release of the new `.keras` format, I believe the simplest and most effective way to address this misleading behavior, and to improve security in Keras, is to have the `safe_mode` parameter raise an **explicit error** when `safe_mode=True` is used with `.h5`/`.hdf5` files. This error should be

CVSS 4.0
CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H
Severity from
GitHub (reviewed advisory)
Weakness
CWE-913
Also known as
CVE-2025-9905, PYSEC-2025-123

More Keras advisories

All Keras
DateAdvisory
Sep 192025Keras is vulnerable to Deserialization of Untrusted Data
CVE-2025-9906High7.3fixed in 3.11.0
Oct 172025Keras framework vulnerable to deserialization of untrusted data
CVE-2025-49655Critical9.8fixed in 3.11.3
Aug 122025Keras vulnerable to CVE-2025-1550 bypass via reuse of internal functionality
CVE-2025-8747High8.8fixed in 3.11.0
Oct 292025Keras is vulnerable to arbitrary local file loading and Server-Side Request Forgery
CVE-2025-12058Mediumfixed in 3.12.0
Dec 22025Keras Directory Traversal Vulnerability
CVE-2025-12060High9.8fixed in 3.12.0
Feb 18Keras has a Local File Disclosure via HDF5 External Storage During Keras Weight Loading
CVE-2026-1669High7.1fixed in 3.12.1, 3.13.2

Critical advisories by email

Wednesdays: the week’s critical and high advisories in the AI and data stack, with the fixed versions. Only in weeks that have some.

Double opt-in. Unsubscribe any time.