marked content injection in autolink

Severity: info · CVSS 0 · Published 2021-02-25

marked is a JavaScript library for converting Markdown to HTML. When mangling is disabled, the library fails to escape URLs in autolinks, allowing attackers to inject arbitrary HTML event handlers (such as onclick) into generated links. This can lead to cross-site scripting (XSS) attacks when user-supplied Markdown is rendered.

Technologies: marked (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 0, published 25 February 2021.
Which products and versions are affected?
marked (npm) SEMVER:introduced=0,fixed=0.3.9.
Is there a fix for This vulnerability?
Yes. marked (npm): upgrade to 0.3.9 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.
Am I affected?
Check whether you run marked (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

  • marked (npm): upgrade to 0.3.9 or later
    npm install marked@0.3.9

Technical details

The vulnerability is an XSS injection in marked's autolink handling when the `mangle` option is set to false. The root cause is insufficient escaping of href attributes in generated anchor tags. When processing email autolinks (e.g., `<user@example.com>`), if mangling is disabled, the library does not properly escape special characters in the href target, allowing an attacker to break out of the href attribute and inject arbitrary HTML event handlers. The attack requires the attacker to control the Markdown input and the application to have mangling disabled. The fix escapes non-mangled hrefs to prevent the injection. Affected versions: 0.3.7 and earlier; fixed in 0.3.9.

Affected products

  • marked marked 0.3.7 and earlier

Timeline

  • 2017-08-15: disclosed: Issue #926 filed on GitHub
  • 2019-06-05: patched: Reviewed and fixed in commit cb72584
  • 2021-02-25: advisory: GHSA published

References

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