Skip to content
XSS Disclosed report Intermediate

Stored XSS in blob viewer

The OpenAPI blob viewer passed file content to SwaggerUIBundle, which allowed HTML attributes such as class, style and data-* to survive sanitisation. An attacker could store a crafted OpenAPI file that, when viewed and clicked, ran script in the victim's session and performed actions on their behalf.

yvvdwf Follow

Originally disclosed on HackerOne

  • Triaged in 4 days
  • Fixed in 4 months
  • Paid in 3 months
  • Disclosed after 5 months

Summary

I found a Stored-XSS in blob viewer when viewing a json file.

In particular, when viewing an openapi file, openapi_viewer is called to transfer the file's data to SwaggerUIBundle to render.

SwaggerUIBundle does its job when rending graphical representation of the openapi's content. It also allows html tags and attributes in the description of the openapi. Although it removes malicious tags and attributes, but this is not enough in gitlab's context:

  1. class and style attributes allow attackers to arbitrarily present their disposition. My demo below uses class attribute to create a transparent layer that fulfils the document to intercept any user's clics.

  2. data-* attributes, under the help of jquery-ujs, allows attackers to create any requests to server when user clicking (not only GET, but also, PUT, DELETE, HEAD) with arbitrary parameters

  3. The current CSP is easily by passed by jQuery.globalEval. In my demo below, you should see an alert after clicking anywhere

Steps to reproduce

  1. In any project, create a file naming xss-openapi.js, then put the following content:
{
  "swagger" : "2.0",
  "info" : {
    "description" : "<a href=https://gitlab.com/yvvdwf/data/-/wikis/alert.md data-type=script style='cursor:default' data-remote=true class='atwho-view select2-drop-mask pika-select'></a><script>alert(0)</script>"
  }}
  1. Click anywhere on the document view, you should see an alert.

Impact

There are three impacts as in the Summary above. The most important impact is the stored-XSS allowing attackers to perform any action on behalf of users at the client side.

Examples

(This repository is in private mode, please let me know if you cannot access it) https://gitlab.com/yvvdwf/xss/-/blob/master/xss-openapi.json

What is the current bug behavior?

Gitlab does not check the result generated by SwaggerUIBundle

What is the expected correct behavior?

Should remove any inappropriate html attributes, such as, data-*, style, class.

Output of checks

This bug happens on GitLab.com

Impact

The stored-XSS allows attackers to perform any action on behalf of users at the client side.

The original report as published on HackerOne, by yvvdwf. 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 the viewer trusted the HTML produced by SwaggerUIBundle without stripping dangerous attributes, and a jQuery helper allowed script execution despite the CSP.

Impact

The stored XSS could let an attacker perform any action on behalf of users at the client side, though the report notes the site's CSP was bypassed rather than blocking it.

What the attacker needed

A project where a file can be created; victim opens the crafted file; victim clicks on the page

The fix

The viewer should strip inappropriate HTML attributes such as data-*, style and class from rendered content.

How it was found

  1. Create a file named xss-openapi.json in any project with crafted OpenAPI content.
  2. Open the file in the blob viewer.
  3. Click anywhere on the document view to trigger the 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.

A stored cross-site scripting bug means a malicious file saved on the site runs code in another person's browser when they open it. Here the page that displays OpenAPI documents let some HTML attributes through, and a helper library in the page could then run script despite the site's protection rules. The result is that clicking the page could trigger code as the logged-in user.

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 yvvdwf

View all

10 more disclosed reports, 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.