Skip to content
XSS Disclosed report Intermediate

XSS in file APIs give access to user X-CSRF-Token

An SVG file containing a script could be served from GitLab's raw file API endpoint, and the script executed in the context of gitlab.com. An attacker could use this to make authenticated API calls on behalf of a victim, leading to account takeover.

GitLab

Originally disclosed on GitLab

  • Fixed in 6 months
  • Disclosed after 6 months

HackerOne report #651335 by rpadovani on 2019-07-19, assigned to akelly:

Summary

Attacker can craft SVG files, reachable in a GET endpoint, that retrieves user X-CSRF-Token

Steps to reproduce

Attacker creates a project, and a SVG file like this (standard XSS injection):

<?xml version="1.0" standalone="no"?>  
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">  
  <polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"/>  
  <script type="text/javascript">  
     alert("surprise");  
  </script>  
</svg>  

This SVG doesn't do anything if accessed through the repository view (such as https://gitlab.com/rpadovani/test-gitlab-pages/raw/master/test.svg), but it triggers the alert if accessed through the raw APIs, such as https://gitlab.com/api/v4/projects/13337155/repository/files/test.svg/raw?ref=master (I can give access to the project, if needed).

This XSS doesn't give access to the user account, since the session cookie is httpOnly.

However, we can do fetch calls from this page to the APIs, and they will have success, meaning we have almost complete control over the account.
We can verify this trying fetching some more information about the user:

<?xml version="1.0" standalone="no"?>  
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">  
  <polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"/>  
  <script type="text/javascript">  
    fetch("/api/v4/user")  
        .then(res => res.json())  
        .then(j => alert(j["email"]))  
  </script>  
</svg>  

This file is called fetch.svg, and again accessing it from the API link, such as https://gitlab.com/api/v4/projects/13337155/repository/files/fetch.svg/raw?ref=master, triggers the script, returning information about user profile: this shows APIs call work.

I wasn't able to include the image directly in over a public place in gitlab.com, I think due CSP, but opening the image on the target browser would be quite simple, both leaving links to it, or doing a redirect from a website you control.

Impact

Being able to do any operation permitted by APIs on behalf of the user

Examples

I was able to reproduce both on Chrome and Firefox, I attach a video on Chrome, simulating a valid issue over a private project on Gitlab.com.

The project is private (of course) and is available at https://gitlab.com/rpadovani/test-gitlab-pages

I can give access to whoever needs it.

What is the current bug behavior?

This is a stored XSS which allows a complete account takeover

What is the expected correct behavior?

No XSS

Relevant logs and/or screenshots

See attached

Output of checks

This bug happens on GitLab.com

Impact

Any operation permitted through internal and public Gitlab APIs on behalf of victims

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

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 perform any operation permitted by the APIs on behalf of the victim, effectively taking over the account, though the session cookie is httpOnly and CSP may limit embedding the file in public places.

What the attacker needed

Victim opens a link to the raw SVG; attacker has a GitLab account

How it was found

  1. Create a project and upload an SVG file containing a script.
  2. Access the SVG through the raw file API endpoint.
  3. Observe that the script executes (e.g., an alert).
  4. Use fetch calls from the script to make authenticated API requests.

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 you upload a file to a website, the site usually shows it safely. Here, a specially crafted image file (an SVG) could run code when opened via a certain link. That code could then act as the logged-in user, reading their data or performing actions.

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.