Skip to content
XSS Disclosed report Intermediate

Stored XSS via Mermaid (stateDiagram-v2)

A stored cross-site scripting vulnerability existed in GitLab's Mermaid diagram rendering, where state diagram labels could contain HTML that was not sanitised. An attacker could inject malicious HTML into a markdown field, leading to script execution when other users viewed the diagram.

GitLab

Originally disclosed on GitLab

  • Fixed in 26 days
  • Disclosed after 26 days

HackerOne report #1390805 by solov9ev on 2021-11-03, assigned to @ngeorge1:

Report | Attachments | How To Reproduce

Report

Summary

Hi, Security Team!
I discovered a stored xss vulnerability via Mermaid (stateDiagram-v2).

Steps to reproduce
  • Run Gitlab docker run --detach --hostname gitlab.example.com --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab gitlab/gitlab-ce:latest (GitLab Enterprise Edition 14.4.1-ee)
  • Insert into any field that supports markdown with using Mermaid the following payload (stateDiagram-v2):
stateDiagram-v2  
    s2 : This is a state description{{media:2}}  

and

stateDiagram-v2  
    s1 --> s2: A{{media:3}}  
1.png
1.png From the original on GitLab

There is another option:

stateDiagram-v2  
    state if_state <<choice>>  
    [*] --> IsPositive  
    IsPositive --> if_state  
    if_state --> False: if n < 0{{media:4}}  
    if_state --> True : if n >= 0  
2.png
2.png From the original on GitLab

Impact

With this vulnerability, an attacker can for example steal users cookies or redirect users on malicious website.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

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

Root cause

Likely the Mermaid rendering library did not sanitise HTML in state diagram labels before inserting them into the page.

Impact

An attacker could steal users' cookies or redirect them to a malicious website.

What the attacker needed

GitLab instance with Mermaid support; Attacker can insert markdown; Victim views the diagram

How it was found

  1. Run a GitLab instance using the provided Docker command.
  2. Insert a Mermaid state diagram with a malicious label into any markdown field.
  3. View the rendered diagram to trigger the script.

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.

Mermaid is a tool that turns text into diagrams. GitLab allows users to include Mermaid diagrams in markdown fields. The problem was that the text inside certain diagram labels was not properly cleaned, so an attacker could put HTML code there that runs JavaScript when someone views the diagram. This lets the attacker run code in the victim's browser.

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.