CVE-2021-37678: TensorFlow/Keras: RCE via YAML model deserialization
GHSA-r6jx-9g48-2r5r HIGH PoC AVAILABLEAny 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 |
| TensorFlow | pip | < 2.3.4 | 2.3.4 |
| TensorFlow | pip | < 2.3.4 | 2.3.4 |
| TensorFlow | pip | < 2.3.4 | 2.3.4 |
How severe is it?
What is the attack surface?
What should I do?
5 steps-
PATCH
Upgrade to TensorFlow 2.6.0+, or backports 2.5.1/2.4.3/2.3.4. The fix removes YAML deserialization entirely.
-
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).
-
INPUT CONTROLS
Enforce cryptographic signing for model files loaded from external sources. Never load model artifacts from untrusted registries without integrity verification.
-
DETECT
Monitor ML service processes for unexpected child process spawns or outbound network connections. Alert on yaml.unsafe_load calls in ML process memory.
-
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:
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
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
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 References
- github.com/advisories/GHSA-r6jx-9g48-2r5r
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-591.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-789.yaml
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-300.yaml
- github.com/tensorflow/tensorflow/commit/1df5a69e9f1a18a937e7907223066e606bf466b9
- github.com/tensorflow/tensorflow/commit/8e47a685785bef8f81bcb996048921dfde08a9ab
- github.com/tensorflow/tensorflow/commit/a09ab4e77afdcc6e1e045c9d41d5edab63aafc1a
- nvd.nist.gov/vuln/detail/CVE-2021-37678
- github.com/tensorflow/tensorflow/commit/23d6383eb6c14084a8fc3bdf164043b974818012 Patch 3rd Party
- github.com/tensorflow/tensorflow/security/advisories/GHSA-r6jx-9g48-2r5r 3rd Party
- github.com/ARPSyndicate/cvemon Exploit
- github.com/fran-CICS/ExploitTensorflowCVE-2021-37678 Exploit
- github.com/n0-traces/cve_monitor Exploit
- github.com/nomi-sec/PoC-in-GitHub Exploit
- github.com/soosmile/POC Exploit
Timeline
Related Vulnerabilities
CVE-2020-15196 9.9 TensorFlow: heap OOB read in sparse/ragged count ops
Same package: tensorflow CVE-2020-15205 9.8 TensorFlow: heap overflow in StringNGrams, ASLR bypass
Same package: tensorflow CVE-2020-15208 9.8 TFLite: OOB read/write via tensor dimension mismatch
Same package: tensorflow CVE-2019-16778 9.8 TensorFlow: heap overflow in UnsortedSegmentSum op
Same package: tensorflow CVE-2022-23587 9.8 TensorFlow: integer overflow in Grappler enables RCE
Same package: tensorflow