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

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** MEDIUM 4.1
- **CVSS:** 4.1 (v3.1, CNA) `CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:N/A:N`
- **CVSS metrics:** Attack vector: Network; Attack complexity: Low; Privileges required: Low; User interaction: Required; Scope: Changed (impact reaches other components); Confidentiality impact: Low; Integrity impact: None; Availability impact: None
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Remote, login needed
- **EPSS:** 0.86% (percentile 56, 2026-11-26)
- **CWE:** CWE-74
- **Aliases:** GHSA-x3vm-38hw-55wf
- **Published:** 2022-06-28T18:35:11.000Z
- **Modified:** 2026-06-17T04:44:48.970Z

## Who should check

- Projects that depend on npm package mermaid (\>= 8.0.0, \< 9.1.2)
- Anyone running mermaid-js mermaid \>= 8.0.0, \< 9.1.3

## 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.

## Affected and fixed versions

- npm `mermaid`: affected \>= 8.0.0, \< 9.1.2; fixed 9.1.2 (osv)
- mermaid-js mermaid: \>= 8.0.0, \< 9.1.3 (cvelist)

## Mitigation

- Upgrade mermaid to 9.1.2 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2022-31108. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2022-31108.md
Affected: mermaid >= 8.0.0, < 9.1.2
Fixed in: 9.1.2

Steps:
1. Search this machine and project for mermaid (npm), mermaid-js mermaid: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2022-31108 being exploited?

There is no confirmed exploitation: CVE-2022-31108 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.86% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2022-31108?

Medium: CVSS 4.1 (v3.1, scored by CNA). Remote, login needed. A user has to take an action, such as opening a link, for the attack to work.

### Which versions are affected by CVE-2022-31108?

mermaid \>= 8.0.0, \< 9.1.2.

### Is there a fix for CVE-2022-31108?

Yes. Fixed in 9.1.2. Upgrade mermaid to 9.1.2 or later.

### How do I check if I'm affected by CVE-2022-31108?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/mermaid-js/mermaid/security/advisories/GHSA-x3vm-38hw-55wf>
- vendor: <https://nvd.nist.gov/vuln/detail/CVE-2022-31108>
- patch: <https://github.com/mermaid-js/mermaid/commit/0ae1bdb61adff1cd485caff8c62ec6b8ac57b225>
- other: <https://github.com/mermaid-js/mermaid>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2022-31108>
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/GHSA-x3vm-38hw-55wf> (license: <https://creativecommons.org/licenses/by/4.0/>)

HTML: <https://flawdb.com/CVE-2022-31108> · JSON: <https://flawdb.com/api/v1/entries/CVE-2022-31108>
