Race condition in Gitaly allowing arbitrary file read
Gitaly's worktree handling could create a symlink from a repository on disk, and a race condition during worktree cleanup could let an attacker read arbitrary files such as the GitLab shell secret. This could escalate separate path traversal issues into arbitrary file read.
GitLab
Originally disclosed on GitLab
- Fixed in 4 months
- Disclosed after 4 months
We received three different HackerOne S2 reports about path traversal vulnerabilities that could be escalated to arbitrary file read via a race condition in Gitaly:
- https://gitlab.com/gitlab-org/gitlab/issues/36324
- https://gitlab.com/gitlab-org/gitlab/issues/121735
- https://gitlab.com/gitlab-org/gitlab/issues/211636
Fixing the path traversal is enough to address those issues independently, but we also need to address the vulnerability in Gitaly to protect from arbitrary file read escalation. https://gitlab.com/gitlab-org/gitlab/issues/36324 explains the root cause:
- Create symlink in Gitaly
In default setups, Gitaly stores git repositories on local file system. I noticed that there's a function in the ruby part of Gitaly.
def with_worktree(worktree, branch, sparse_checkout_files: nil, env:)
...
ensure
run_git(%W[worktree remove -f #{worktree.name}])
end
...
This function uses git-worktree to checkout a specific version of the repo and do something like rebase or squash. So, if there's a symlink nyangawa.gz -> /var/opt/gitlab/gitlab-rails/etc/gitlab_shell_secret in my repo. It would be created on the disk during, for example, the rebase operation.
However, current implementation ensures worktree cleanups at the end of the with_worktree function, the symlink would also be deleted after that.
@jramsay @zj-gitlab Can you validate it is under your scope and analyse if you can provide a fix ? /cc @estrike
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 worktree cleanup removes the symlink only after the operation finishes, leaving a window where the symlink points at a sensitive file that can be read.
Impact
An attacker could read arbitrary files on the Gitaly host, including the GitLab shell secret, though the text does not confirm a working exploit end to end.
What the attacker needed
Ability to push a repository with a symlink; a git operation that uses a worktree; timing the race window
How it was found
- Create a symlink inside a repository that points to a sensitive file on the server
- Trigger a git operation such as rebase or squash that uses a worktree
- Read the target file through the symlink before the worktree cleanup removes it
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 symlink is a shortcut file that points to another file on the same computer. Gitaly, the part of GitLab that handles git repositories, briefly creates such shortcuts on disk when it checks out a repository, and a timing problem (a race condition) means an attacker might grab the target file before the shortcut is removed.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.