Skip to main content
Menu
Advisories

ClickHouse SQL Injection via Array Column Update

GHSA-3XXG-X7QC-9JW7Published Updated GitHub

Description

Severity: Moderate (defense in depth, not a privilege escalation) CWE: CWE-89 (SQL Injection) Affected version: v0.112.0 (latest as of 2026-05-30), clidey/whodb:latest Affected file: core/src/plugins/clickhouse/compound_convert.go (formatLiteral)

Summary

When you update a row that has an Array(String) column, WhoDB builds the SQL by wrapping each array element in single quotes without escaping any single quotes inside the value. The result goes into the ALTER TABLE ... UPDATE statement as a raw expression, so a single quote in an array element breaks out of the string literal and the rest is parsed as SQL.

Root cause

// core/src/plugins/clickhouse/compound_convert.go
func formatLiteral(v any) string {
    switch v := v.(type) {
    case string:
        return "'" + v + "'"   // no escaping of single quotes
    default:
        return fmt.Sprintf("%v", v)
    }
}

arrayToExpr joins these into a raw gorm.Expr, which is not parameterized:

func arrayToExpr(v any) any {
    rv := reflect.ValueOf(v)
    parts := make([]string, rv.Len())
    for i := range rv.Len() {
        parts[i] = formatLiteral(rv.Index(i).Interface())
    }
    return gorm.Expr("[" + strings.Join(parts, ", ") + "]")
}

The non-array update path already uses ? placeholders. Only the array path builds raw SQL.

PoC

Needs an authenticated ClickHouse session and a table with an Array(String) column.

CREATE TABLE test_db.sqli_poc (id UInt32, tags Array(String), name String) ENGINE = MergeTree() ORDER BY id;
INSERT INTO test_db.sqli_poc VALUES (1, ['safe_tag'], 'original_value');

Send an UpdateSourceObject where the tags value contains a single quote:

{
  "operationName": "UpdateSourceObject",
  "query": "mutation UpdateSourceObject($values:[RecordInput!]!,$updated:[String!]!){ UpdateSourceObject(ref:{Kind:Table,Path:[\"test_db\",\"sqli_poc\"]}, values:$values, updatedColumns:$updated){Status} }",
  "variables": {
    "values": [
      {"Key":"id","Value":"1"},
      {"Key":"tags","Value":"[\"injected', name = 'PWNED' WHERE id = 1 AND 'a' = 'a\"]"},
      {"Key":"name","Value":"original_value"}
    ],
    "updated": ["tags"]
  }
}

ClickHouse rejects it with a syntax error that shows the injected text sitting in the query as raw SQL:

{"errors":[{"message":"code: 62, message: Syntax error: failed at position 64 ('name'): name = 'PWNED' WHERE id = 1 AND 'a' = 'a\"'] WHERE `id` = 1. Expected one of: comma or closing bracket, ...","path":["UpdateSourceObject"]}]}

The single quote closed the string literal and name = 'PWNED' WHERE ... was parsed as SQL, which proves the break-out.

Impact

This is a real injection, but it is worth being honest about what it gets an attacker. A WhoDB session already has RunSourceQuery, which runs arbitrary SQL, so an authenticated user is not gaining any access they didn't already have. The value here is correctness and defense in depth:

  • It violates the project's own rule in AGENTS.md ("Never use fmt.Sprintf with user input for SQL. Use parameterized queries or GORM builders").
  • It would matter in any deployment or future mode where a user can edit rows but is not meant to run raw queries, since the injection would then let them run SQL the UI was supposed to prevent.

So it should be fixed, but it is not the high-severity, boundary-crossing bug the original report implied.

Severity (CVSS 3.1)

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N = about 4.3 (Moderate)

Remediation

Escape single quotes in formatLiteral, or better, use parameterized values for the array update path the same way the scalar path already does.

case string:
    return "'" + strings.ReplaceAll(v, "'", "''") + "'"

Test environment

  • clidey/whodb:latest (v0.112.0), clickhouse/clickhouse-server:24.3, a table with an Array(String) column.
  • Tested 2026-05-31.

Affected versions

References

GitHub · clidey/whodb