Skip to content

[BUG-SEC-3] Shell injection via unsanitized passwords in subprocess calls (clickhouse_loader.py, mysql_dumper.py) #1293

Description

@minguyen9988

Summary

Both clickhouse_loader.py and mysql_dumper.py construct shell commands using Popen(shell=True) with database passwords interpolated directly into the command string without escaping. A password containing shell metacharacters (e.g., semicolons, quotes, pipe characters) can execute arbitrary shell commands.

Affected Code

clickhouse_loader.py

File: sink-connector/python/db_load/clickhouse_loader.py

password_option = f"--password '{password}'"
# ...
cmd = f"clickhouse-client {password_option} --query ..."
process = Popen(cmd, shell=True, ...)

Two occurrences of this pattern. The single quotes around {password} provide no protection — a password containing ' breaks out of the quoting.

mysql_dumper.py

File: sink-connector/python/db_dump/mysql_dumper.py

mysql_password_clause = f""" --password "{mysql_password}" """
# ...
cmd = f"mysqldump {mysql_password_clause} ..."
process = Popen(cmd, shell=True, ...)

Double quotes around {mysql_password} — a password containing double-quotes or other shell-interpreted characters breaks out.

Attack Vector

If a ClickHouse or MySQL password contains shell metacharacters, the password value breaks out of its quoting context and the remainder is interpreted as a separate shell command. The password is typically set in a YAML config file or environment variable. In shared environments or automated deployments, an attacker who can influence the password value can execute arbitrary commands on the host running the Python tools.

Fix

Use shlex.quote() to properly escape the password for shell use:

import shlex
password_option = f"--password {shlex.quote(password)}"

Or better yet, avoid shell=True entirely and pass arguments as a list:

cmd = ["clickhouse-client", "--password", password, "--query", query]
process = Popen(cmd, shell=False, ...)

The same fix applies to config_file_option in clickhouse_loader.py, which has the same vulnerability.

Impact

  • Severity: CRITICAL (Command Injection — CWE-78)
  • Type: OS Command Injection via shell metacharacters
  • Affected versions: All versions with the Python db_load/db_dump tools

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions