# RCE via the DecompressedArchiveSizeValidator and Project BulkImports (behind feature flag)

Attacker-controlled import_source flowed into a shell string in DecompressedArchiveSizeValidator, giving command injection RCE on GitLab via bulk project imports.

- Payout: $33,510
- Severity: critical
- Program: GitLab
- Found by (vendor credit): vakzz
- Found by: vakzz
- Disclosed: 2022-09-13
- CVE: CVE-2022-2185
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/1609965
- Library page: https://bugbountylibrary.com/r/h1%3A1609965
- Tags: area:web domain:web impact:internal-access impact:rce kind:bounty platform:hackerone sev:critical tech:ruby technique:chained technique:mass-assignment technique:source-review vuln:command-injection vuln:rce

**Target:** GitLab EE DecompressedArchiveSizeValidator / BulkImports ProjectPipeline
**Root cause:** DecompressedArchiveSizeValidator builds a shell command string `gzip -dc #{@archive_path} | wc -c` passed to Open3.popen3, and ProjectPipeline fails to filter import_source, letting attacker control archive_path.
**Steps:**
1. Enable feature: `::Feature.enable(:bulk_import_projects)` in rails console
2. Create API token, group, and project in that group
3. Serve a fake GitLab API (flask) returning project export with `"import_source":"/tmp/ggg;echo lala|tee /tmp/1234;#"`
4. Expose via ngrok; in GitLab UI import group from that instance URL with token
5. Select group, set parent No parent, hit import
6. Wait for wait_for_archived_file retries to exhaust (~minutes); payload executes in sidekiq
7. Verify: `cat /tmp/1234` shows `lala`
**How found:** Code-read the DecompressedArchiveSizeValidator, noticed string interpolation into Open3.popen3 (shell interpretation), then traced archive_path back through FileImporter/Importer to project.import_source, and hunted for a path where import_source is attacker-settable — found BulkImports ProjectPipeline's insufficient ProhibitedAttributesTransformer filtering, then chained template_name to flip import_type.
**Exploitation:** Attacker controls all project params via bulk import pipeline; sets template_name=rails to route through CreateFromTemplateService which flips import_type to gitlab_project, triggering import_schedule. Custom import_source becomes @archive_file; after MAX_RETRIES the validator runs the shell string, executing injected commands as the git user.
**Insight:** When a sink takes a shell string, trace the tainted param back to every setter; look for import/migration pipelines that pass raw attribute hashes into CreateService, and abuse template_name/template_project_id to flip import_type and reach otherwise-unreachable import code paths.

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

**Malicious import_source payload in bulk import JSON**

```
"import_source":"/tmp/ggg;echo lala|tee /tmp/1234;#",` to be your custom command (it cannot contain `>` as json will convert it to `\u003c`)
```

**Vulnerable shell command construction in validator**

```
def command
        "gzip -dc #{@archive_path} | wc -c"
      end

   def validate
        pgrp = nil
        valid_archive = true

        Timeout.timeout(TIMEOUT_LIMIT) do
          stdin, stdout, stderr, wait_thr = Open3.popen3(command, pgroup: true)
```

