Skip to content
Heist/ feed
Back to feed
High

Arbitrary Code execution in Keras Safe Mode

Type: advisorySources: OSV

The Keras Model.load_model method can be exploited to achieve arbitrary code execution, even with safe_mode=True. One can create a specially crafted .keras model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special config.json (a file within the .keras archive) that will invoke keras.config.enable_unsafe_deserialization() to disable safe mode. Once safe mode is disable, one can use the Lambda layer feature of keras, which allows arbitrary Python code in the form of pickled code. Both can appear in the same archive. Simply the keras.config.enable_unsafe_deserialization() needs to appear first in the archive and the Lambda with arbitrary code needs to be second.

Products
Not specified
Affected versions
Not specified
Fixed versions
Not specified
CVEs
CVE-2025-9906
Confirmed fixed CVEs
Not specified
Updated in this feed
3 Nov 2026, 10:26 UTC · Revision 1

Source evidence

Arbitrary Code execution in Keras Safe Mode

core-osv · Original source

Published 19 Sept 2025, 08:15 UTC

The Keras Model.load_model method can be exploited to achieve arbitrary code execution, even with safe_mode=True. One can create a specially crafted .keras model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special config.json (a file within the .keras archive) that will invoke keras.config.enable_unsafe_deserialization() to disable safe mode. Once safe mode is disable, one can use the Lambda layer feature of keras, which allows arbitrary Python code in the form of pickled code. Both can appear in the same archive. Simply the keras.config.enable_unsafe_deserialization() needs to appear first in the archive and the Lambda with arbitrary code needs to be second.

osv:CVE-2025-9906
Complete source record
{
  "id": "1d41d12a2bf79e36d93c904dec7a40f0cb89d83fd1c2951f77e9d7fe10d0a7e4",
  "url": "https://osv.dev/vulnerability/CVE-2025-9906",
  "method": "structured",
  "payload": {
    "kind": "advisory",
    "title": "Arbitrary Code execution in Keras Safe Mode",
    "summary": "The Keras Model.load_model method can be exploited to achieve arbitrary code execution, even with safe_mode=True. One can create a specially crafted .keras model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special config.json (a file within the .keras archive) that will invoke keras.config.enable_unsafe_deserialization() to disable safe mode. Once safe mode is disable, one can use the Lambda layer feature of keras, which allows arbitrary Python code in the form of pickled code. Both can appear in the same archive. Simply the keras.config.enable_unsafe_deserialization() needs to appear first in the archive and the Lambda with arbitrary code needs to be second.",
    "evidence": "osv:CVE-2025-9906",
    "products": [],
    "severity": "high",
    "structured": {
      "id": "CVE-2025-9906",
      "aliases": [
        "CVE-2025-9906",
        "GHSA-36fq-jgmw-4r9c",
        "PYSEC-2025-76"
      ],
      "metrics": [
        {
          "type": "CVSS_V4",
          "score": "CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:P/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/AU:Y/R:A"
        }
      ],
      "affected": [
        {
          "ranges": [
            {
              "repo": "https://github.com/keras-team/keras",
              "type": "GIT",
              "events": [
                {
                  "introduced": "9c675a9a45e5e8244163fea82efc6066722608a1"
                },
                {
                  "fixed": "7bf852c211ea41dc58bbc740c3fe64d091d37511"
                }
              ],
              "database_specific": {
                "extracted_events": [
                  {
                    "range": [
                      {
                        "introduced": "3.0.0"
                      },
                      {
                        "fixed": "3.11.0"
                      }
                    ],
                    "source": "AFFECTED_FIELD",
                    "strategy": "StandardRange"
                  },
                  {
                    "cpe": "cpe:2.3:a:keras:keras:*:*:*:*:*:*:*:*",
                    "range": [
                      {
                        "introduced": "3.0.0"
                      },
                      {
                        "fixed": "3.11.0"
                      }
                    ],
                    "source": "CPE_RANGE"
                  }
                ]
              }
            }
          ],
          "versions": [
            "v3.10.0",
            "v3.9.0",
            "v3.8.0",
            "v3.7.0",
            "v3.6.0",
            "v3.5.0",
            "v3.4.1",
            "v3.4.0",
            "v3.3.3",
            "v3.3.2",
            "v3.3.1",
            "v3.3.0",
            "v3.2.1",
            "v3.2.0",
            "v3.1.1",
            "v3.1.0",
            "v3.0.5",
            "v3.0.4",
            "v3.0.3",
            "v3.0.2",
            "v3.0.1",
            "v3.0.0"
          ],
          "database_specific": {
            "source": "https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2025-9906.json"
          }
        }
      ],
      "modified": "2026-10-28T02:30:27.868505194Z",
      "provider": "osv",
      "references": [
        "https://github.com/CVEProject/cvelistV5/tree/main/cves/2025/9xxx/CVE-2025-9906.json",
        "https://nvd.nist.gov/vuln/detail/CVE-2025-9906",
        "https://github.com/keras-team/keras/pull/21429",
        "https://github.com/keras-team/keras"
      ],
      "provider_metadata": {
        "cwe_ids": [
          "CWE-502"
        ],
        "cna_assigner": "Google",
        "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2025/9xxx/CVE-2025-9906.json"
      }
    },
    "related_cves": [
      {
        "value": "CVE-2025-9906",
        "evidence": "/id"
      }
    ],
    "security_relevant": true,
    "severity_evidence": "/severity/0/score"
  },
  "source_id": "core-osv",
  "document_id": 494500,
  "published_at": "2025-09-19T08:15:04.349+00:00"
}