CVE-2021-37678: TensorFlow Keras Model YAML Deserialization Arbitrary Code Execution

tensorflow-cpu Updated 02 Oct 2025

Summary

12/08/2021
Yes i
Unrated
Not published

CVE-2021-37678: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu across 3 version ranges.

>= 2.3.0, < 2.3.4 >= 2.4.0, < 2.4.3 < 23d6383eb6c14084a8fc3bdf164043b974818012

Fixed in 2.3.4 or 2.4.3, 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 Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow includes a high-level API called Keras, which simplifies the process of building and training deep learning models. Keras models can be serialized and deserialized using various formats, including YAML. However, a vulnerability in the deserialization process of Keras models from YAML format allows for arbitrary code execution.

Vulnerability Detail

The vulnerability (CVE-2021-37678) arises from the usage of yaml.unsafe_load in the implementation of deserializing Keras models from YAML format. This function can execute arbitrary code provided as input, leading to potential remote code execution. An attacker could craft a malicious YAML file that, when deserialized, triggers the execution of arbitrary code on the target system. This could result in unauthorized access, data leakage, or further compromise of the affected machine. The vulnerability affects TensorFlow versions 2.3.0 to 2.5.0, as well as the tensorflow-cpu package on PyPI.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.0, < 2.3.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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 temporary workaround, users can switch to alternative serialization formats, such as JSON, until the patched versions of TensorFlow are released. Here is an example of how to serialize and deserialize a Keras model using JSON:

import json

# Serialize the Keras 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 a file
with open('model.json', 'r') as json_file:
    loaded_model_json = json_file.read()

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

Conclusion

The vulnerability (CVE-2021-37678) in TensorFlow and Keras models allows for arbitrary code execution when deserializing Keras models from YAML format. This can lead to unauthorized access, data leakage, or further compromise of the affected system. It is crucial to update to the patched versions of TensorFlow and avoid deserializing models from untrusted sources. For further assistance and support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow-cpu →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and libraries for building and deploying machine learning models.

Keras is a high-level API included in TensorFlow that simplifies the process of building and training deep learning models.

The vulnerability arises from the usage of yaml.unsafe_load in the deserialization process of Keras models from YAML format. This function can execute arbitrary code provided as input, leading to potential remote code execution.

The vulnerability could allow an attacker to execute arbitrary code on the target system, potentially leading to unauthorized access, data leakage, or further compromise of the affected machine.

To protect your system, it is recommended to update to the patched versions of TensorFlow as soon as they become available. Additionally, avoid deserializing Keras models from untrusted or unknown sources.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow-cpu.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.0, < 2.3.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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