Junglewise Threat Intelligence

js-yaml code injection in load() function

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

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

Executive brief

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.

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

Related threats