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.
- 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:
-
classandstyleattributes allow attackers to arbitrarily present their disposition. My demo below usesclassattribute to create a transparent layer that fulfils the document to intercept any user's clics. -
data-*attributes, under the help of jquery-ujs, allows attackers to create any requests to server when user clicking (not onlyGET, but also,PUT,DELETE,HEAD) with arbitrary parameters -
The current CSP is easily by passed by jQuery.globalEval. In my demo below, you should see an
alertafter clicking anywhere
Steps to reproduce
- 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>"
}}
- 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.
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
- Create a file named xss-openapi.json in any project with crafted OpenAPI content.
- Open the file in the blob viewer.
- 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.