# When you call your branch the same name as a git hash, it could be checked out by dependents

GitLab allows branches named as 40-char hex hashes, so `git checkout <hash>` resolves to the attacker's branch instead of the pinned commit, redirecting dependents to different code.

- Payout: $2,000
- Severity: medium
- Program: GitLab
- Found by: retroplasma
- Disclosed: 2021-08-19
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/790634
- Library page: https://bugbountylibrary.com/r/h1%3A790634
- Tags: area:cloud domain:infra domain:web impact:integrity kind:bounty platform:hackerone sev:medium technique:recon vuln:misconfiguration

**Target:** GitLab repository branch creation / git ref resolution
**Root cause:** GitLab does not reject branch names that are 40-character hexadecimal strings, unlike GitHub. Git resolves an ambiguous ref name to the branch over the commit hash, so a hash reference silently points to attacker-controlled content.
**Steps:**
1. Take commit hash A, e.g. `e91803d442559d6efb63102b10c919e10901b01d`.
2. Check out any other commit B.
3. Create a branch named exactly the hash of A: `git checkout -b e91803d442559d6efb63102b10c919e10901b01d`.
4. Push the branch to GitLab (accepted, unlike GitHub).
5. A dependent running `git checkout e91803d442559d6efb63102b10c919e10901b01d` gets commit B (branch) instead of commit A.
**How found:** Observed that git prefers a branch name over a commit hash when both match, then tested that GitLab (unlike GitHub) accepts pushing 40-char hex branch names.
**Exploitation:** Attacker with push access to a repo creates a branch named after a commit hash that downstream projects pin/reference; when dependents run `git checkout <hash>`, git prefers the branch and delivers attacker-controlled content instead of the pinned commit.
**Insight:** When auditing git hosting, test whether ref names colliding with commit hashes are permitted; any consumer that pins by hash (CI, dependency refs, submodules) can be redirected to attacker content.

