CVE-2021-37678: Arbitrary code execution due to YAML deserialization in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

25/08/2021
Yes i
High
9.3

CVE-2021-37678: Arbitrary code execution due to YAML deserialization. Affects tensorflow across 3 version ranges.

< 2.3.4 >= 2.4.0, < 2.4.3 >= 2.5.0, < 2.5.1

Fixed in 2.3.4, 2.4.3 or 2.5.1, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-37678 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

TensorFlow is an open-source machine learning framework that is widely used for developing and training deep learning models. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning applications. TensorFlow includes a module called Keras, which is a high-level neural networks API. Keras allows users to define and train deep learning models using a simple and intuitive interface. However, a vulnerability has been discovered in TensorFlow and Keras that can lead to arbitrary code execution when deserializing a Keras model from YAML format.

Vulnerability Detail

The vulnerability in TensorFlow and Keras arises from the use of yaml.unsafe_load when deserializing a Keras model from YAML format. An attacker can craft a malicious YAML payload that, when deserialized, can execute arbitrary code on the system. This can lead to various security risks, including unauthorized access, data leakage, and remote code execution. The impact of this vulnerability is critical, with a CVSS score of 9.3.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow==2.21.0"

Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.

If you can't move to the latest

The minimum fixed version depends on the release line you run.

  • < 2.3.4 2.3.4
    pip install --upgrade "tensorflow==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow==2.4.3"
  • >= 2.5.0, < 2.5.1 2.5.1
    pip install --upgrade "tensorflow==2.5.1"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

As a workaround, users can avoid using YAML format for serializing and deserializing Keras models in TensorFlow. Instead, alternative serialization formats like JSON can be used. Here is an example of serializing and deserializing a Keras model using JSON:

from tensorflow.keras import models
import json

model = models.Sequential()
# Build and compile the model

# Serialize the model to JSON
model_json = model.to_json()

# Save the JSON to a file
with open('model.json', 'w') as json_file:
    json_file.write(model_json)

# Load the JSON from the file
with open('model.json', 'r') as json_file:
    loaded_model_json = json_file.read()

# Deserialize the JSON to a model
loaded_model = models.model_from_json(loaded_model_json)

By using JSON instead of YAML, the vulnerability can be mitigated.

Conclusion

The vulnerability in TensorFlow and Keras that allows for arbitrary code execution when deserializing Keras models from YAML format has been addressed by the TensorFlow team. Users are advised to update their TensorFlow installations to the patched versions and avoid using YAML format for serialization and deserialization. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open-source machine learning framework used for developing and training deep learning models.

Keras is a high-level neural networks API included in TensorFlow, which provides a simple and intuitive interface for defining and training deep learning models.

YAML deserialization is the process of converting YAML data into an object or data structure in a programming language. In the context of TensorFlow and Keras, it is used to deserialize Keras models stored in YAML format.

The vulnerability allows for arbitrary code execution, which can lead to unauthorized access, data leakage, and remote code execution.

To mitigate this vulnerability, it is recommended to update TensorFlow to the patched versions (2.6.0, 2.5.1, 2.4.3, or 2.3.4) that remove YAML format support. Additionally, using alternative serialization formats like JSON can help mitigate the risk.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow==2.21.0"

Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.

If you can't move to the latest

The minimum fixed version depends on the release line you run.

  • < 2.3.4 2.3.4
    pip install --upgrade "tensorflow==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow==2.4.3"
  • >= 2.5.0, < 2.5.1 2.5.1
    pip install --upgrade "tensorflow==2.5.1"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback