# CVE-2022-40604: Apache Airflow: Format String Vulnerability

User-controlled run_id flowed into a Python str.format() call in Airflow's file task handler, letting an attacker inject format fields to leak secrets like secret_key and DB credentials.

- Payout: $8,000
- Severity: critical
- Program: Internet Bug Bounty
- Found by (vendor credit): L3yx of Syclover Security Team
- Found by: leixiao
- Disclosed: 2025-01-18
- CVE: CVE-2022-40604
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1707287
- Library page: https://bugbountylibrary.com/r/h1%3A1707287
- Tags: area:cloud domain:infra impact:ato impact:data-leak impact:internal-access kind:bounty platform:hackerone sev:critical tech:python technique:source-review vuln:info-disclosure vuln:secrets-leak

**Target:** Airflow webserver get_logs_with_metadata endpoint / file_task_handler.py
**Root cause:** log_relative_path (built from attacker-controlled run_id) was passed into a .format(ti=ti, worker_log_server_port=...) call, so braces in run_id were interpreted as format fields evaluated against the ti object.
**Steps:**
1. Trigger any DAG with config and set run_id to `{ti.task.__class__.__init__.__globals__[conf].__dict__}`
2. Open /xcom/list/ and enter the corresponding task page
3. Click Log and capture the `/get_logs_with_metadata?...&try_number=1&metadata=null` request
4. Change `try_number` to a nonexistent value like `9999`
5. Request the modified URL; the format string is evaluated and secrets rendered into the log response
**How found:** Noticed that log_relative_path (containing run_id) was interpolated into a .format() call, meaning user input was treated as a format template; then found the error path (bad try_number) that renders the formatted URL back to the user.
**Exploitation:** Attacker with DAG-trigger access sets a malicious run_id, then forces the log handler down the error path (nonexistent try_number) so the formatted URL is built and returned, dumping the conf globals dict including secret_key and DB connection strings; secret_key enables session forgery and DB creds enable direct DB access.
**Escalation:** Leaked secret_key allows forging Flask session cookies for admin impersonation; leaked DB connection string gives direct database access.
**Insight:** When user input reaches str.format() as the template (not just an argument), braces become field accessors into the passed objects — look for .format() on strings containing request-derived values, and find an error/echo path that returns the rendered result.

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

**Format string payload in run_id**

```
Set the run_id to `{ti.task.__class__.__init__.__globals__[conf].__dict__}` and trigger it.
```

**Modified get_logs_with_metadata request with try_number 9999**

```
/get_logs_with_metadata?dag_id=example_xcom&task_id=push_by_returning&map_index=-1&execution_date=2022-08-29T13%3A25%3A11%2B00%3A00&try_number=9999&metadata=null
```

