CVE-2017-18342: PyYAML insecurely deserializes YAML strings leading to arbitrary code execution

pyyaml Updated 02 Oct 2025

Summary

04/01/2019
Yes i
Critical
9.8

CVE-2017-18342: PyYAML insecurely deserializes YAML strings leading to arbitrary code execution. Affects pyyaml versions < 4.1. Fixed in 4.1. How to fix ↓

Also tracked for

The same CVE-2017-18342 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 MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

PyYAML is a Python library that allows developers to parse and manipulate YAML (YAML Ain't Markup Language) files. It provides functionality for loading YAML data into Python objects and vice versa. PyYAML is widely used in various Python projects and applications.

Vulnerability Detail

The vulnerability (CVE-2017-18342) in PyYAML versions before 4.1 arises from the insecure deserialization of YAML strings. The yaml.load() API, which is used to load YAML data, can execute arbitrary code. This means that an attacker can craft a malicious YAML file that, when loaded using yaml.load(), can lead to arbitrary code execution on the system. The safe_load() function, which is intended to load YAML data safely, is not used, exacerbating the issue. The vulnerability has a CVSS score of 9.8 (Critical severity) according to the CVSS v3.1 scoring system.

How To Fix

Minimum fixed version

4.1

This is the first release that contains the fix.

pip install --upgrade "pyyaml==4.1"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a workaround, developers can use the safe_load() function instead of yaml.load() to load YAML data. safe_load() is designed to mitigate the risk of code execution by only allowing the deserialization of simple Python objects. However, it is still recommended to upgrade to the latest version of PyYAML to fully address the vulnerability.

Conclusion

In conclusion, the CVE-2017-18342 vulnerability in PyYAML allows for the insecure deserialization of YAML strings, leading to arbitrary code execution. It is crucial to upgrade to PyYAML version 4.1 or later to mitigate this vulnerability. Developers should also consider using the safe_load() function as a temporary workaround until the upgrade can be applied. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for pyyaml →

Share this vulnerability

FAQ

PyYAML is a Python library for parsing and manipulating YAML files.

The vulnerability allows an attacker to execute arbitrary code by crafting a malicious YAML file.

Upgrade PyYAML to version 4.1 or later.

Developers can use the safe_load() function instead of yaml.load() as a temporary workaround.

The vulnerability has a CVSS score of 9.8 (Critical severity).

Related vulnerabilities

Recent vulnerabilities recorded for pyyaml.

How To Fix

Minimum fixed version

4.1

This is the first release that contains the fix.

pip install --upgrade "pyyaml==4.1"

Tip — Not sure which version your app runs? Vulert can match this fix to it. 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