CVE-2017-18342: PyYAML PyYAML Insecurely Deserializes YAML Strings Vulnerability

CRITICAL
Advisory Identifier: GHSA-rprw-h62v-c2w7
CVSS 9.8
CWE-502
Published
Advisory Summary

CVE-2017-18342 is a CRITICAL (CVSS 9.8) pyyaml insecurely deserializes yaml strings vulnerability (CWE-502: Deserialization of Untrusted Data) affecting PyYAML libraries in the PyPI ecosystem. The issue involves pyyaml insecurely deserializes yaml strings leading to arbitrary code execution. Remediation is available by upgrading affected packages to version 5.1.

CVE-2017-18342 at a Glance

CVE Identifier CVE-2017-18342
GHSA Identifier GHSA-rprw-h62v-c2w7
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product PyYAML
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2017-18342

To remediate this vulnerability, upgrade all affected PyYAML dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

PyYAML fixed: 5.1
pip install PyYAML>=5.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show PyYAML

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2017-18342, inspect your installed packages using pip:

pip show PyYAML

Analyze the terminal output to locate any version of PyYAML in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.1), your application is affected.

Note: The pip show PyYAML command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In PyYAML, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

In PyYAML before 5.1, the `yaml.load()` API could execute arbitrary code. In other words, `yaml.safe_load` is not used. This was intended to be fixed in 4.1, but due to [breaking changes](https://github.com/yaml/pyyaml/issues/192#issuecomment-401491470), 4.1 was yanked and 5.1 [contains](https://github.com/yaml/pyyaml/issues/207#issuecomment-472520007) the patch for CVE-2017-18342.

CVE-2017-18342 Affected PyYAML Versions

1 component(s)
Fixed Versions:
5.1
Product / Package Ecosystem Affected Versions Fixed Version
PyYAML
PyPI
< 5.1
5.1

References

NVD — CVE-2017-18342 NVD
https://nvd.nist.gov/vuln/detail/CVE-2017-18342
PyYAML Source Repository REPOSITORY
https://github.com/marshmallow-code/apispec/issues/278
PyYAML Source Repository REPOSITORY
https://github.com/yaml/pyyaml/issues/193
PyYAML Source Repository REPOSITORY
https://github.com/yaml/pyyaml/issues/207#issuecomment-472520007
PyYAML Source Repository REPOSITORY
https://github.com/yaml/pyyaml/pull/74
Security Fix Commit FIX COMMIT
https://github.com/yaml/pyyaml/commit/7b68405c81db889f83c32846462b238ccae5be80
PyYAML Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/pyyaml/PYSEC-2018-49.yaml
PyYAML Source Repository REPOSITORY
https://github.com/yaml/pyyaml
PyYAML Source Repository REPOSITORY
https://github.com/yaml/pyyaml/blob/master/CHANGES
GitHub Advisory / Wiki ADVISORY
https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/JEX7IPV5P2QJITAMA5Z63GQCZA5I6NVZ
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/KSQQMRUQSXBSUXLCRD3TSZYQ7SEZRKCE
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/M6JCFGEIEOFMWWIXGHSELMKQDD4CV2BA
PyYAML Security Information SECURITY
https://security.gentoo.org/glsa/202003-45

Frequently Asked Questions

What is CVE-2017-18342?
CVE-2017-18342 is a security vulnerability in PyYAML involving PyYAML insecurely deserializes YAML strings leading to arbitrary code execution under CWE-502: Deserialization of Untrusted Data.
Which PyYAML versions are affected?
Affected versions include releases prior to 5.1 across affected packages: PyYAML.
What version fixes CVE-2017-18342?
Upgrading to 5.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is PyYAML affected?
Yes, PyYAML is affected in releases prior to 5.1. Upgrade your dependency to 5.1 or later.
What is the CVSS score of CVE-2017-18342?
CVE-2017-18342 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2017-18342?
CVE-2017-18342 is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check PyPI dependencies for CVE-2017-18342?
Run the dependency tree command: 'pip show PyYAML'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-rprw-h62v-c2w7",
  "modified" : "2026-07-01T17:39:14Z",
  "published" : "2019-01-04T17:45:26Z",
  "aliases" : [ "CVE-2017-18342" ],
  "summary" : "PyYAML insecurely deserializes YAML strings leading to arbitrary code execution",
  "details" : "In PyYAML before 5.1, the `yaml.load()` API could execute arbitrary code. In other words, `yaml.safe_load` is not used.\n\nThis was intended to be fixed in 4.1, but due to [breaking changes](https://github.com/yaml/pyyaml/issues/192#issuecomment-401491470), 4.1 was yanked and 5.1 [contains](https://github.com/yaml/pyyaml/issues/207#issuecomment-472520007) the patch for CVE-2017-18342.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "PyYAML"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2017-18342"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/marshmallow-code/apispec/issues/278"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/issues/193"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/issues/207#issuecomment-472520007"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/pull/74"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/commit/7b68405c81db889f83c32846462b238ccae5be80"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/pyyaml/PYSEC-2018-49.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/yaml/pyyaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/blob/master/CHANGES"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/JEX7IPV5P2QJITAMA5Z63GQCZA5I6NVZ"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/KSQQMRUQSXBSUXLCRD3TSZYQ7SEZRKCE"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/M6JCFGEIEOFMWWIXGHSELMKQDD4CV2BA"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202003-45"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-16T21:55:26Z",
    "nvd_published_at" : null
  }
}