CVE-2021-37678: TensorFlow/Keras: RCE via YAML model deserialization

GHSA-r6jx-9g48-2r5r HIGH PoC AVAILABLE
Published August 12, 2021
CISO Take

Any pipeline loading Keras models from YAML—including automated MLOps workflows—is exposed to arbitrary code execution with service-level privileges. Upgrade TensorFlow to 2.6.0+ or apply backport patches (2.3.4/2.4.3/2.5.1) immediately. Audit all model-loading code for model_from_yaml() calls and replace with JSON-based serialization—YAML support has been removed entirely in the fix.

What is the risk?

CVSS 8.8 with low complexity and no user interaction makes crafting a payload trivial—any developer familiar with PyYAML object injection can exploit this. The local attack vector prevents mass internet exploitation but underestimates real-world risk: ML pipelines routinely load model files from shared storage, model registries, and third-party repositories, all of which are plausible delivery channels. EPSS at 1.08% reflects limited observed exploitation, but the barrier to entry is extremely low for a targeted attacker with access to a model upload path.

What systems are affected?

Package Ecosystem Vulnerable Range Patched
TensorFlow pip No patch
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →
TensorFlow pip < 2.3.4 2.3.4
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →
TensorFlow pip < 2.3.4 2.3.4
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →
TensorFlow pip < 2.3.4 2.3.4
195.8K OpenSSF 7.1 3.7K dependents Pushed 2d ago 4% patched ~1372d to patch Full package profile →

How severe is it?

CVSS 3.1
8.8 / 10
EPSS
0.5%
chance of exploitation in 30 days
Higher than 36% of all CVEs
Exploitation Status
Exploit Available
Exploitation: MEDIUM
Sophistication
Trivial
Exploitation Confidence
medium
Public PoC indexed (trickest/cve)
Composite signal derived from CISA KEV, VulnCheck KEV, CISA SSVC, EPSS, Metasploit, Exploit-DB, trickest/cve, Nuclei templates, and inthewild.io exploitation reports.

What is the attack surface?

AV AC PR UI S C I A
AV Local
AC Low
PR Low
UI None
S Changed
C High
I High
A High

What should I do?

5 steps
  1. PATCH

    Upgrade to TensorFlow 2.6.0+, or backports 2.5.1/2.4.3/2.3.4. The fix removes YAML deserialization entirely.

  2. AUDIT

    Grep codebases for 'model_from_yaml', 'yaml.unsafe_load', and Keras YAML imports. Replace all instances with JSON-based model serialization (model_from_json/model.to_json).

  3. INPUT CONTROLS

    Enforce cryptographic signing for model files loaded from external sources. Never load model artifacts from untrusted registries without integrity verification.

  4. DETECT

    Monitor ML service processes for unexpected child process spawns or outbound network connections. Alert on yaml.unsafe_load calls in ML process memory.

  5. LEAST PRIVILEGE

    ML service accounts should be scoped to inference/training only—no cloud IAM write access, no access to secrets outside their specific pipeline.

How is it classified?

Which compliance frameworks are affected?

This CVE is relevant to:

EU AI Act
Article 9 - Risk Management System
ISO 42001
A.8.4 - Third-party AI system components and services
NIST AI RMF
MANAGE-2.2 - Mechanisms to sustain AI risk management post-deployment
OWASP LLM Top 10
LLM05:2025 - Supply Chain Vulnerabilities

Frequently Asked Questions

What is CVE-2021-37678?

Any pipeline loading Keras models from YAML—including automated MLOps workflows—is exposed to arbitrary code execution with service-level privileges. Upgrade TensorFlow to 2.6.0+ or apply backport patches (2.3.4/2.4.3/2.5.1) immediately. Audit all model-loading code for model_from_yaml() calls and replace with JSON-based serialization—YAML support has been removed entirely in the fix.

Is CVE-2021-37678 actively exploited?

Proof-of-concept exploit code is publicly available for CVE-2021-37678, increasing the risk of exploitation.

How to fix CVE-2021-37678?

1. PATCH: Upgrade to TensorFlow 2.6.0+, or backports 2.5.1/2.4.3/2.3.4. The fix removes YAML deserialization entirely. 2. AUDIT: Grep codebases for 'model_from_yaml', 'yaml.unsafe_load', and Keras YAML imports. Replace all instances with JSON-based model serialization (model_from_json/model.to_json). 3. INPUT CONTROLS: Enforce cryptographic signing for model files loaded from external sources. Never load model artifacts from untrusted registries without integrity verification. 4. DETECT: Monitor ML service processes for unexpected child process spawns or outbound network connections. Alert on yaml.unsafe_load calls in ML process memory. 5. LEAST PRIVILEGE: ML service accounts should be scoped to inference/training only—no cloud IAM write access, no access to secrets outside their specific pipeline.

What systems are affected by CVE-2021-37678?

This vulnerability affects the following AI/ML architecture patterns: training pipelines, model serving, MLOps pipelines, model registries, collaborative ML environments.

What is the CVSS score for CVE-2021-37678?

CVE-2021-37678 has a CVSS v3.1 base score of 8.8 (HIGH). The EPSS exploitation probability is 0.45%.

What is the AI security impact?

Affected AI Architectures

training pipelinesmodel servingMLOps pipelinesmodel registriescollaborative ML environments

MITRE ATLAS Techniques

AML.T0010.001 AI Software
AML.T0011.000 Unsafe AI Artifacts
AML.T0018.002 Embed Malware
AML.T0050 Command and Scripting Interpreter

Compliance Controls Affected

EU AI Act: Article 9
ISO 42001: A.8.4
NIST AI RMF: MANAGE-2.2
OWASP LLM Top 10: LLM05:2025

What are the technical details?

Original Advisory

TensorFlow is an end-to-end open source platform for machine learning. In affected versions TensorFlow and Keras can be tricked to perform arbitrary code execution when deserializing a Keras model from YAML format. The [implementation](https://github.com/tensorflow/tensorflow/blob/460e000de3a83278fb00b61a16d161b1964f15f4/tensorflow/python/keras/saving/model_config.py#L66-L104) uses `yaml.unsafe_load` which can perform arbitrary code execution on the input. Given that YAML format support requires a significant amount of work, we have removed it for now. We have patched the issue in GitHub commit 23d6383eb6c14084a8fc3bdf164043b974818012. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

Exploitation Scenario

An adversary with write access to a shared model registry (S3, NFS, or internal model hub) uploads a crafted Keras YAML config embedding a PyYAML deserialization payload using !!python/object/apply: constructs. When an automated training pipeline or data scientist runs model_from_yaml() on this file during model loading or validation, the payload executes—exfiltrating AWS credentials from environment variables, establishing a reverse shell, or accessing training datasets. In multi-tenant MLaaS environments, a malicious user could upload the file through a legitimate model submission interface.

Weaknesses (CWE)

CWE-502 — Deserialization of Untrusted Data: The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.

  • [Architecture and Design, Implementation] If available, use the signing/sealing features of the programming language to assure that deserialized data has not been tainted. For example, a hash-based message authentication code (HMAC) could be used to ensure that data has not been modified.
  • [Implementation] When deserializing data, populate a new object rather than just deserializing. The result is that the data flows through safe input validation and that the functions are safe.

Source: MITRE CWE corpus.

CVSS Vector

CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H

Timeline

Published
August 12, 2021
Last Modified
November 21, 2024
First Seen
August 12, 2021

Related Vulnerabilities