When you call your branch the same name as a git hash, it could be checked out by dependents
GitLab allows branches to be named with 40-character hexadecimal strings that look like commit hashes. When a dependent project references a commit by hash, Git may check out the malicious branch instead, causing the dependent to build from attacker-controlled code.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 6 months
- Paid in 3 days
- Disclosed after 18 months
Summary
If we call a branch the same name like a git hash then the moment it's checked out somewhere, git prefers the branch name. So let's say the git hash is "e91803d442559d6efb63102b10c919e10901b01d". And someone referenced that hash in their program. Now the developer or a hacker with access to the repo can create a branch named "e91803d442559d6efb63102b10c919e10901b01d". Git will checkout the branch and not the hash when someone puts "git checkout e91803d442559d6efb63102b10c919e10901b01d". GitHub prevents users from pushing branches that are the same name as hashes, but GitLab does not.
Steps to reproduce
(Step-by-step guide to reproduce the issue, including:)
- Take a hash of a commit A
- Go to any other commit B
- Create a branch that is named the same as the hash from commit A
- Push
- If someone references the hash in their program, their "git checkout" will checkout commit B. Because it will use the branch name instead of the hash
Impact
Referencing a hash isn't secure anymore. It would reference a branch that has completely different data. git shows a warning but "git checkout {...}" is often used.
Examples
Any project that refs a git ref
What is the current bug behavior?
Gitlab accepts pushed branches that are 40-char hexadecimals
What is the expected correct behavior?
Gitlab shouldn't accept pushed branches that are 40-char hexadecimals (like Github does9
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Impact
Redirect pinned refrs of libraries if there is control of a library. A referenced hash won't point to a hash anymore. An attacker can make the branch which has the hash's name contain any other data.
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 GitLab does not reject branch names that are 40-character hexadecimal strings, so they can collide with commit hashes and be resolved preferentially by Git.
Impact
A referenced hash may no longer point to the intended commit, allowing an attacker to make dependents build from a branch containing different data; Git shows a warning but checkout by hash is often used.
What the attacker needed
Access to push branches to the repository; a dependent project references a commit hash
The fix
GitLab should reject pushed branch names that are 40-character hexadecimal strings, as GitHub does.
How it was found
- Take the hash of a commit A.
- Go to any other commit B.
- Create a branch named exactly like the hash from commit A.
- Push the branch.
- When someone references the hash in their program, git checkout will check out commit B instead.
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.
Git identifies commits by long hexadecimal strings called hashes. If a branch is given exactly the same name as a hash, Git may prefer the branch over the commit when checking out that name. This means someone who can push to a repository could make another project that depends on it build from different code than intended.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.