Skip to content
XSS Disclosed report Intermediate

Stored XSS in repository file viewer

GitLab's OpenAPI viewer used an outdated swagger-ui with a vulnerable DOMPurify, allowing an attacker to inject arbitrary HTML elements into a repository file page. A victim who opens the page and clicks anywhere triggers the stored XSS, which could be used to steal a CSRF token and take over the account.

kannthu Follow

Originally disclosed on HackerOne

Bounty$2,000 Medium 4.1 View original
  • Triaged in 18 hours
  • Fixed in 2 months
  • Paid in 2 months
  • Disclosed after 16 months

Summary

There exists XSS in swagger-ui version used in GitLab open API viewer. The XSS exists due to the old version of DOMpurify used in swagger-ui that allows an attacker can inject any HTML elements with any attributes (except script tag) on the page.

The XSS in POC requires 1 click anywhere on the page to execute, because of CSP that does not allow to execute events from HTML tags. (f.e. <img src=1 onerror=alert(1)). I will try to find CSP bypass that will allow me to execute the script with no user interaction.

My script uses the CSP bypass presented in https://gitlab.com/gitlab-org/gitlab/-/issues/213273

<a   
  data-remote="true"
  data-method="get"  
  data-type="script"
  href="/wbowling/wiki/raw/master/test.js" 
  class='atwho-view select2-drop-mask pika-select'>
</a>  

Steps to reproduce

  1. Go to https://gitlab.com/kannthu/asdasdas123/-/blob/master/openapi.yaml (tested on Chrome and Firefox)
  2. Click anywhere on the page
  3. You should see the alert box

There is another way of executing this XSS. You can add "url=https://gitlab.com/kannthu/asdasdas123/-/raw/master/openapi.yaml" parameter to the URL of any open API file in any repository, and the XSS will still work.

  1. Open https://gitlab.com/gitlab-org/build/omnibus-mirror/alertmanager/blob/master/api/v2/openapi.yaml?url=https://gitlab.com/kannthu/asdasdas123/-/raw/master/openapi.yaml
  2. Click anywhere on the page
  3. You should see the alert box

Impact

The stored XSS is triggering for any user that opens the page and clicks anywhere on the page. The PoC can easily be extended to steal the user's CSRF token and to take over the victim's account.

Examples

What is the current bug behavior?

Gitlab uses an old version of swagger-ui.

What is the expected correct behavior?

Gitlab should use the newest version of swagger-ui.

Relevant logs and/or screenshots

F1146909

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Impact

The stored XSS is triggering for any user that opens the page and clicks anywhere on the page. An attacker can render anything on that page - malicious form to steal the user's login and password, or simply get the user's CSRF token and to take over the victim's account.

Attachments

Screenshot_2021-01-06_at_17.47.53.png
Screenshot_2021-01-06_at_17.47.53.png From the original on HackerOne

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

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 an outdated swagger-ui bundled an old DOMPurify that did not properly sanitise HTML, and GitLab's CSP only blocked automatic event execution, requiring a click.

Impact

The stored XSS triggers for any user who opens the page and clicks anywhere, and could be extended to steal the user's CSRF token and take over the victim's account.

What the attacker needed

Victim opens the crafted page; victim clicks anywhere on the page

The fix

GitLab should use the newest version of swagger-ui.

How it was found

  1. Open the attacker's openapi.yaml file in the GitLab repository file viewer.
  2. Click anywhere on the page.
  3. Observe the alert box confirming script execution.

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.

A stored cross-site scripting (XSS) flaw lets an attacker save malicious content that runs in other people's browsers when they view it. Here, a file in a GitLab repository was shown through an old OpenAPI viewer that failed to clean up HTML properly, so opening the file and clicking anywhere ran the attacker's code.

What is XSS?

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

More by kannthu

View all

1 more disclosed report, best first.

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.