CVE-2022-31108 Arbitrary `CSS` injection into the generated graph affecting the container HTML in mermaid.js

Medium 4.1 Published Updated

Attackers can inject CSS to exfiltrate data or manipulate UI, affecting users of the mermaid.js diagramming library.

Exploited in the wild
Not known
Login needed
Any signed-in user
Attackable
Over the internet
Victim action needed
A user has to click or open something
Fix
Available

What is CVE-2022-31108?

CVE-2022-31108 is a medium-severity cross-site scripting vulnerability in mermaid-js mermaid, published on 28 Jun 2022. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

Official description

Mermaid is a JavaScript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. An attacker is able to inject arbitrary `CSS` into the generated graph allowing them to change the styling of elements outside of the generated graph, and potentially exfiltrate sensitive information by using specially crafted `CSS` selectors. The following example shows how an attacker can exfiltrate the contents of an input field by bruteforcing the `value` attribute one character at a time. Whenever there is an actual match, an `http` request will be made by the browser in order to "load" a background image that will let an attacker know what's the value of the character. This issue may lead to `Information Disclosure` via CSS selectors and functions able to generate HTTP requests. This also allows an attacker to change the document in ways which may lead a user to perform unintended actions, such as clicking on a link, etc. This issue has been resolved in version 9.1.3. Users are advised to upgrade. Users unable to upgrade should ensure that user input is adequately escaped before embedding it in CSS blocks.

Weakness: CWE-79, CWE-74

Which versions are affected by CVE-2022-31108?

2 open source packages ship an affected version, including mermaid. It affects 1 product.

PackageAffectedFixed in
mermaid npmFrom 8.0.09.1.2
mermaid npmFrom 8.0.09.1.2

Products include Mermaid Project Mermaid.

How do I fix CVE-2022-31108?

Upgrade mermaid to 9.1.2 or later.

Escape output for the context it lands in and set a strict Content Security Policy. Upgrading the affected component is the real fix. More about Cross-site scripting.

Is CVE-2022-31108 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31108 exists.

Sources

Also known as DEBIAN-CVE-2022-31108, GHSA-x3vm-38hw-55wf, UBUNTU-CVE-2022-31108.

Is CVE-2022-31108 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free