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.

Risk Assessment

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.

Affected Systems

Package Ecosystem Vulnerable Range Patched
tensorflow pip No patch
195.0K OpenSSF 7.2 3.7K dependents Pushed 6d ago 4% patched ~1372d to patch Full package profile →
tensorflow pip < 2.3.4 2.3.4
195.0K OpenSSF 7.2 3.7K dependents Pushed 6d ago 4% patched ~1372d to patch Full package profile →
tensorflow-cpu pip < 2.3.4 2.3.4
195.0K OpenSSF 7.2 3.7K dependents Pushed 6d ago 4% patched ~1372d to patch Full package profile →
tensorflow-gpu pip < 2.3.4 2.3.4
195.0K OpenSSF 7.2 3.7K dependents Pushed 6d ago 4% patched ~1372d to patch Full package profile →

Severity & Risk

CVSS 3.1
8.8 / 10
EPSS
1.0%
chance of exploitation in 30 days
Higher than 77% 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, CISA SSVC, EPSS, trickest/cve, and Nuclei templates.

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

Recommended Action

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.

Classification

Compliance Impact

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 1.02%.

Technical Details

NVD Description

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.

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