js-yaml code injection in load() function

Severity: info · CVSS 7.5 · Published 2019-06-04

js-yaml is a popular JavaScript YAML parser library used to convert YAML files into JavaScript objects. The load() function can execute arbitrary code if given a maliciously crafted YAML file containing a function as a toString property. This allows attackers to run arbitrary JavaScript code on any system that parses untrusted YAML with the load() function, potentially leading to data theft, system compromise, or lateral movement.

Technologies: js-yaml (npm). Vendors: npm.

Quick answers

Is This vulnerability exploited in the wild?
No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.
How severe is This vulnerability?
Informational severity, with a CVSS score of 7.5, published 4 June 2019.
Which products and versions are affected?
js-yaml (npm) SEMVER:introduced=0,fixed=3.13.1.
Is there a fix for This vulnerability?
Yes. js-yaml (npm): upgrade to 3.13.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is This vulnerability attacked?
It is attacked over the network, in a software library.
Am I affected?
Check whether you run js-yaml (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • js-yaml (npm): upgrade to 3.13.1 or later
    npm install js-yaml@3.13.1

Technical details

The vulnerability is a code injection flaw (CWE-94) in the js-yaml library prior to version 3.13.1. The load() function fails to properly sanitize objects with executable toString() properties when those objects are used as explicit mapping keys in YAML. When the parser processes such a key, it invokes the toString() method, which can execute arbitrary JavaScript code injected through a specially crafted YAML tag (tag:yaml.org,2002:js/function). The attack requires the application to call load() on untrusted YAML input; safeLoad() is unaffected as it restricts the types of objects that can be parsed. The fix, merged in April 2019, prevents function execution by validating toString properties and converting them to string representations instead of invoking them.

Affected products

  • js-yaml js-yaml prior to 3.13.1

Timeline

  • 2019-06-04: disclosed
  • 2019-04-05: patched: Fix merged in PR #480

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.