Skip to content

fix(pinot/dremio/ksql/databriks/hive/jdbc-driver): correct SQL parameter escaping - #11374

Merged
ovr merged 6 commits into
masterfrom
fix/other-drivers-escape
Jul 27, 2026
Merged

ovr merged 6 commits into
masterfrom
fix/other-drivers-escape

Conversation

@ovr

@ovr ovr commented Jul 27, 2026

Copy link
Copy Markdown
Member

Audit of all 29 driver packages for the escaping bug fixed for Trino/Presto in 463e602 and Athena in 9b23d090e1: sqlstring (a MySQL escaper) used to interpolate parameters for engines that are not MySQL.

Mismatching the dialect is unsafe in BOTH directions, so there is no safe universal default and each engine has to be handled explicitly:

  • MySQL rules on a standard-SQL engine emit \'. The backslash is data there, so the quote that follows closes the literal and the rest of the statement lands in code position.
  • Standard-SQL rules on a backslash-escaping engine leave a trailing \, which escapes the closing quote and lets the literal run on.
engine backslash is correct formatter
Pinot, Dremio (Calcite) data formatAnsi
ksqlDB (Presto-derived) data formatAnsi
Athena, Presto, Trino data formatAnsi
MySQL, Hive, Spark SQL escape char formatMySql
ClickHouse, Cube Store escape char formatMySql

@ovr
ovr requested review from a team as code owners July 27, 2026 12:38
@github-actions github-actions Bot added driver:prestodb Issues relating to the PrestoDB driver driver:dremio driver:questdb javascript Pull requests that update Javascript code data source driver driver:databricks driver:trino Issues relating to the Trino driver driver:pinot cubejs-jdbc-driver labels Jul 27, 2026
@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 1m 24s —— View job


Claude PR Review

Verdict: LGTM — the mapping and per-driver rewrites are correct, tests cover both directions of the escaping mismatch. 0 blockers, 2 minor observations.

Details
  • Read PR context
  • List existing review threads (none)
  • Read changed files
  • Analyze correctness, security, tests
  • Post review

Correctness

  • The dialect table in the PR body matches the code: Athena → ansi, MySQL/Hive/Spark SQL → mysql in supported-drivers.ts; Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB all route through formatAnsi; Databricks correctly overrides escapeDialect() → 'mysql' because it runs Spark SQL (backslash is an escape char there).
  • The old Dremio/Pinot post-processing regexes (.replace(/\\\\([_%])/g, '\\$1'), .replace(/\\'/g, '\'\'')) were band-aids for the wrong-dialect output of sqlstring. Removing them is right — formatAnsi doesn't emit \_ / \% / \' in the first place, so the strips have nothing to undo.
  • escapeStringLiteral in QuestDriver.ts:220,241 closes a real hole: previously '${table}' interpolated the table name raw, so a quote in table broke the literal. QuestDB accepts single-quoted table identifiers, so the wrapping is the correct fix.
  • Only one JDBC subclass (DatabricksDriver) — checked; nothing else silently inherits the 'mysql' default.

Minor observations (non-blocking)

  1. JDBCDriver.escapeDialect() default is 'mysql' (packages/cubejs-jdbc-driver/src/JDBCDriver.ts:240). The PR description itself notes "no safe universal default," yet an unregistered dbType silently gets MySQL rules — which the same PR body says will leave \' and swallow the closing quote on ANSI engines. This preserves prior behavior so it's not a regression, but consider either (a) throwing on unknown dbType (fail-loud), or (b) documenting that new engines MUST be added to SupportedDrivers before use. A comment on the fallback would be enough.

  2. escapeStringLiteral name suggests output is a bare string; it actually returns the quoted literal. In QuestDriver.ts the call sites read FROM ${escapeStringLiteral(table)} — no surrounding quotes — which is correct, but the diff from FROM '${table}' is easy to miss on review. A one-line JSDoc on escapeStringLiteral clarifying "returns 'foo''bar' (quotes included)" would prevent a future caller from wrapping it in quotes again.

Tests

  • sql-escape.test.ts: covers the parity check (odd/even quote runs) plus explicit backslash-as-data behavior. Good.
  • escape-dialect.test.ts: nice touch asserting the mapping directly rather than instantiating JDBCDriver (which would boot the JVM). The "every supported engine declares a dialect" test guards against future additions forgetting the flag.
  • Per-driver params-escaping.test.ts files exercise the actual prepareQueryWithParams seam on real payloads (backslash-terminated, embedded quotes, injection strings).

Security

Correctly addresses the CVE-class issue: mismatched escaper → literal escape via trailing backslash or backslash-quote. No new injection surface introduced. The QuestDB change is a bonus fix.

@ovr
ovr force-pushed the fix/other-drivers-escape branch from 8b16b97 to cba3cc6 Compare July 27, 2026 12:39
@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 1m 42s —— View job


Claude PR Review

Verdict: LGTM. Findings: 0 high, 1 low.

Details
  • Read PR context
  • List existing review threads (none)
  • Read changed files
  • Analyze correctness, security, tests
  • Post review

Summary

The PR follows the same recipe as the earlier Trino/Presto and Athena fixes, applied consistently across the remaining affected drivers:

  • Central formatAnsi / formatMySql from @cubejs-backend/shared are used based on the engine's real literal semantics.
  • New escapeStringLiteral helper is well-tested and used for the last raw interpolation in QuestDB (SHOW COLUMNS FROM ... and INSERT INTO ...).
  • The sqlstring runtime dependency is dropped from jdbc-driver, trino-driver, and transitively via the Pinot/Dremio/Ksql code paths.
  • EscapeDialect is per-engine on SupportedDrivers, and Databricks overrides to 'mysql' (Spark SQL semantics) — correct.
  • Test coverage is genuinely adversarial: trailing-backslash payloads, \' smuggling, quote-doubling, LIKE ESCAPE '\' interactions on Dremio, IN-list arrays, and a mapping-coverage test in escape-dialect.test.ts that fails if a new supported engine is added without declaring a dialect.

Correctness / security

  • applyParams in driver/DremioDriver.js now delegates directly to formatAnsi, and the old MySQL-escape-then-unescape workaround (.replace(/\\\\([_%])/g, '\\$1').replace(/\\'/g, "''")) is gone. Since ANSI leaves \ as data, values like new\_order pass through unchanged, matching the accompanying LIKE ESCAPE '\' tests — behavior is now aligned with the schema compiler's assumption instead of double-flipped.
  • KsqlDriver.query and KsqlDriver.downloadStreamingTable both route through prepareQueryWithParams, so no code path uses sqlstring any longer.
  • PinotDriver.prepareQueryWithParams visibility narrowed from public to protected; no callers outside the class, so safe.
  • PrestoDriver.prepareQueryWithParams narrowed the same way; the test file adapts via a subclass, and the Trino driver does not touch it, so no external breakage.
  • QuestDB escapeStringLiteral(table) replaces '${table}'. Even though table names rarely contain quotes, this closes a latent injection surface for callers of tableColumnTypes / write paths.

Low — JDBCDriver.escapeDialect() silently defaults to 'mysql' for unregistered engines

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:240-243 returns 'mysql' when dbTypeDescription?.escapeDialect is missing. Given this PR's own thesis — "no safe universal default" — an engine registered via user config or a future addition to SupportedDrivers without a declared escapeDialect reintroduces exactly the bug the PR fixes (e.g. a Calcite-family engine wired through JDBC). The escape-dialect.test.ts mapping-coverage test guards SupportedDrivers but does not guard the runtime default for out-of-tree registrations.

Consider either making escapeDialect a required field on DriverOptionsInterface (so the compiler catches omissions) or throwing at construction time when it is missing. Not a blocker; documented and behavior-preserving as-is.

Nits

  • packages/cubejs-backend-shared/src/sql-escape.ts:49 adds a stray blank line inside SqlEscaper.escapeString; harmless.
  • Removed doc comments in KsqlDriver.ts (Class constructor. etc.) are content-free — fine to drop, just noting the unrelated cleanup rides along with a security fix.
• [Branch](https://github.com/cube-js/cube/tree/fix/other-drivers-escape)

@ovr
ovr force-pushed the fix/other-drivers-escape branch from cba3cc6 to 4bb5262 Compare July 27, 2026 12:41
@claude

claude Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Claude Code is working…

I'll analyze this and get back to you.

View job run

@ovr
ovr force-pushed the fix/other-drivers-escape branch from 4bb5262 to e83ea86 Compare July 27, 2026 12:42
@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 35s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 1 low (previously noted).

Details
  • Read PR context and existing threads
  • Diff vs origin/master — single commit e83ea86, 21 files, matches prior review scope
  • Verify per-driver escaping routing
  • Verify test coverage

Summary

Consistent application of the Trino/Athena fix pattern to the remaining affected drivers:

  • Central formatAnsi / formatMySql from @cubejs-backend/shared chosen per real literal semantics.
  • Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi (backslash is data).
  • Databricks overrides escapeDialect() → 'mysql' (Spark SQL semantics) — correct.
  • Legacy Dremio/Pinot regex band-aids (.replace(/\\\\([_%])/g, ...), .replace(/\\'/g, "''")) removed; formatAnsi never emits those sequences, so the strips have nothing to undo.
  • escapeStringLiteral closes the raw '${table}' interpolation in QuestDB (SHOW COLUMNS FROM, INSERT INTO).
  • sqlstring dep dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql paths.
  • Adversarial tests: trailing-backslash payloads, \' smuggling, quote-doubling, LIKE ESCAPE '\' on Dremio, IN-list arrays. escape-dialect.test.ts mapping-coverage test fails if a new supported engine forgets to declare a dialect.

Low (previously flagged, non-blocking) — JDBCDriver.escapeDialect() silent 'mysql' fallback

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:240 defaults to 'mysql' when dbTypeDescription?.escapeDialect is missing. The PR body itself notes "no safe universal default"; an out-of-tree or newly-added engine wired through JDBC without declaring escapeDialect reintroduces exactly the bug this PR fixes. Consider making escapeDialect required on DriverOptionsInterface or throwing at construction. The mapping-coverage test guards SupportedDrivers but not runtime registrations.

Security

Correctly addresses the CVE-class issue (mismatched escaper → literal escape via trailing \ or \'). No new injection surface. QuestDB escapeStringLiteral is a bonus fix.

• [Branch](https://github.com/cube-js/cube/tree/fix/other-drivers-escape)

@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 50s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 1 low (previously noted, unchanged).

Details
  • Read PR context and existing threads (none open)
  • Diff vs origin/master — 21 files, +389/-53, identical scope to prior reviews (force-push, same content, new SHA deca0d7)
  • Verify per-driver routing and default fallback
  • Verify test coverage still intact

Summary

No substantive change since the previous review. Re-verified:

  • Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi (backslash is data).
  • Databricks overrides escapeDialect() → 'mysql' (Spark SQL) — correct.
  • Legacy Dremio/Pinot regex band-aids removed; formatAnsi doesn't emit \_ / \% / \', so nothing to undo.
  • escapeStringLiteral closes the raw '${table}' interpolation in QuestDB.
  • sqlstring dep dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql paths.
  • Adversarial tests intact (trailing-backslash, \' smuggling, quote-doubling, LIKE ESCAPE '\' on Dremio, IN-list arrays); escape-dialect.test.ts mapping-coverage test still guards SupportedDrivers.

Low (previously flagged, still non-blocking) — JDBCDriver.escapeDialect() silent 'mysql' fallback

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:241 still defaults to 'mysql' for engines missing escapeDialect. The PR body itself says "no safe universal default"; an out-of-tree engine wired through JDBC without declaring escapeDialect reintroduces exactly the bug this PR fixes. Mapping-coverage test guards in-tree SupportedDrivers but not runtime registrations. Consider making the field required on DriverOptionsInterface or throwing at construction. Behavior-preserving as-is.

Security

Correctly addresses the CVE-class issue (mismatched escaper → literal escape via trailing \ or \'). No new injection surface. QuestDB escapeStringLiteral is a bonus fix.

• Branch •

@codecov

codecov Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.98%. Comparing base (5ad0041) to head (d02e55d).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
packages/cubejs-ksql-driver/src/KsqlDriver.ts 0.00% 1 Missing and 1 partial ⚠️
packages/cubejs-pinot-driver/src/PinotDriver.ts 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11374      +/-   ##
==========================================
- Coverage   59.72%   58.98%   -0.75%     
==========================================
  Files         217      223       +6     
  Lines       17586    17891     +305     
  Branches     3570     3636      +66     
==========================================
+ Hits        10504    10553      +49     
- Misses       6569     6819     +250     
- Partials      513      519       +6     
Flag Coverage Δ
cube-backend 58.98% <71.42%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 31s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 1 low (previously noted, unchanged).

Details
  • Read PR context and existing threads (none open)
  • Diff since last review — new commit 582dc43 "chore: move to try/catch block"
  • Verify no regression from the change

New commit 582dc43

Moves this.prepareQueryWithParams(sql, values) inside the try block in JDBCDriver.stream() (packages/cubejs-jdbc-driver/src/JDBCDriver.ts:292). Correct improvement: if param preparation throws (e.g. a caller passes an unsupported value shape), the pooled connection acquired one line above is now released via the existing catch handler instead of being leaked. cancelObj was rightly moved with it — it's only used inside the try body. No behavior change on the happy path.

Prior review (still applies)

Consistent application of the Trino/Athena fix pattern:

  • Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi (backslash is data).
  • Databricks overrides escapeDialect() → 'mysql' (Spark SQL) — correct.
  • Legacy Dremio/Pinot regex band-aids removed; formatAnsi doesn't emit \_ / \% / \', so nothing to undo.
  • escapeStringLiteral closes the raw '${table}' interpolation in QuestDB.
  • sqlstring dep dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql paths.
  • Adversarial tests intact; escape-dialect.test.ts mapping-coverage test still guards SupportedDrivers.

Low (previously flagged, still non-blocking) — JDBCDriver.escapeDialect() silent 'mysql' fallback

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:241 still defaults to 'mysql' for engines missing escapeDialect. The PR body itself says "no safe universal default"; an out-of-tree engine wired through JDBC without declaring escapeDialect reintroduces exactly the bug this PR fixes. Consider making the field required on DriverOptionsInterface or throwing at construction. Behavior-preserving as-is.

Security

Correctly addresses the CVE-class issue. No new injection surface.

• Branch •

@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 33s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 1 low (previously noted, unchanged).

Details
  • Read PR context and existing threads (none open)
  • Diff since last review — new commit be81a23 "chore: sync lock"
  • Verify no regression

New commit be81a23

Pure yarn.lock cleanup: drops the now-unused sqlstring@^2.3.0 range from the resolved dedupe entry (was pinned by the packages that no longer depend on sqlstring after this PR). No dependency or code change — just makes the lockfile consistent with the package.json edits in deca0d7. Zero risk.

Prior review (still applies)

Consistent application of the Trino/Athena fix pattern:

  • Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi (backslash is data).
  • Databricks overrides escapeDialect() → 'mysql' (Spark SQL) — correct.
  • Legacy Dremio/Pinot regex band-aids removed; formatAnsi doesn't emit \_ / \% / \', so nothing to undo.
  • escapeStringLiteral closes the raw '${table}' interpolation in QuestDB.
  • sqlstring dep dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql paths.
  • 582dc43 correctly moved prepareQueryWithParams inside the try block in JDBCDriver.stream() so preparation errors release the pooled connection via the existing catch.
  • Adversarial tests intact; escape-dialect.test.ts mapping-coverage test still guards SupportedDrivers.

Low (previously flagged, still non-blocking) — JDBCDriver.escapeDialect() silent 'mysql' fallback

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:241 still defaults to 'mysql' for engines missing escapeDialect. The PR body itself says "no safe universal default"; an out-of-tree engine wired through JDBC without declaring escapeDialect reintroduces exactly the bug this PR fixes. Consider making the field required on DriverOptionsInterface or throwing at construction. Behavior-preserving as-is.

Security

Correctly addresses the CVE-class issue. No new injection surface.

• Branch •

@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 54s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 1 low (previously noted, unchanged).

Details
  • Read PR context and existing threads
  • Diff since last review — new commits cc29b83 (test round-trip refactor) and 6cc5638 (Spark/Hive/Databricks dialect)
  • Verify Spark dialect correctness and coverage

New commit 6cc5638 — dedicated spark dialect

This is a real correctness fix, not just a rename. Spark SQL, Hive, and Databricks lexers do NOT accept '' as an escape — they close the literal and open the next one, and adjacent literals are silently concatenated ('O''Brien' → OBrien, no parse error). The previous 'mysql' mapping was safe by luck (both use ` for identifiers and \ for escapes) but wrong in principle for any input containing a quote: MySQL emits '' here, which Spark misreads.

  • New SparkSqlDialect in sql-escape.ts:39 sets doubleQuoteToEscape: false, escapeBackslash: true — the right combination; quotes become \', backslashes double.
  • SqlEscaper.escapeString already handles this ordering correctly (backslash pass first, then quote-to-\'), so no engine changes were needed.
  • format(dialect, ...) entry point + the two prior formatAnsi/formatMySql helpers now share one implementation — nice consolidation.
  • EscapeDialect moved to @cubejs-backend/shared with a type re-export from jdbc-driver/supported-drivers.ts — non-breaking.
  • DatabricksDriver.escapeDialect() → 'spark' (was 'mysql'); sparksql and hive entries in SupportedDrivers likewise flipped. All three run Spark SQL / Hive lexers, so this is correct.
  • The mapping-coverage test in escape-dialect.test.ts was updated to accept spark, so it still guards against a new supported engine forgetting to declare a dialect.

Tests

  • decodeSparkLiteral correctly rejects unescaped quotes and lone backslashes, then the injection-payload/short-combinations/Unicode suites round-trip through it — same adversarial shape as the Ansi/MySQL suites.
  • Explicit spec asserts spark.escapeString("O'Brien") does NOT contain '' and equals 'O\\'Brien', with a comment noting verification against apache/spark:3.5.1 behavior.
  • format(dialect, ...) cross-dialect test pins ANSI/MySQL/Spark output for the same input a\b'c — a good regression anchor.

Commit cc29b83

Refactors the earlier "odd/even quote parity" checks into a proper round-trip: parse the emitted literal with a mini-decoder and assert it equals the input. Strictly stronger — a parity check would pass on '' for Spark; the round-trip catches it.

Prior review (still applies)

Consistent application of the Trino/Athena fix pattern across Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi. QuestDB escapeStringLiteral closes the raw '${table}' interpolation. sqlstring dep dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql paths.

Low (previously flagged, still non-blocking) — JDBCDriver.escapeDialect() silent 'mysql' fallback

packages/cubejs-jdbc-driver/src/JDBCDriver.ts:238 still defaults to 'mysql' for engines missing escapeDialect. The PR body itself says "no safe universal default"; an out-of-tree engine wired through JDBC without declaring escapeDialect reintroduces the bug this PR fixes. The mapping-coverage test guards in-tree SupportedDrivers but not runtime registrations. Consider making the field required on DriverOptionsInterface or throwing at construction. Behavior-preserving as-is.

Security

Correctly addresses the CVE-class issue in a new direction: Spark's silent-concatenation-on-'' is arguably worse than the trailing-backslash swallow because no parse error is raised on the wrong-dialect output. No new injection surface.

• Branch •

@ovr ovr changed the title fix(pinot/dremio/ksql/jdbc-driver): correct SQL parameter escaping fix(pinot/dremio/ksql/databriks/hive/jdbc-driver): correct SQL parameter escaping Jul 27, 2026
ovr added 2 commits July 27, 2026 17:11
Audit of all 29 driver packages for the escaping bug fixed for Trino/Presto
in 463e602 and Athena in 9b23d090e1: `sqlstring` (a MySQL escaper) used to
interpolate parameters for engines that are not MySQL.

Mismatching the dialect is unsafe in BOTH directions, so there is no safe
universal default and each engine has to be handled explicitly:

- MySQL rules on a standard-SQL engine emit `\'`. The backslash is data there,
  so the quote that follows closes the literal and the rest of the statement
  lands in code position.
- Standard-SQL rules on a backslash-escaping engine leave a trailing `\`,
  which escapes the closing quote and lets the literal run on.

| engine                       | backslash is | correct formatter |
| ---------------------------- | ------------ | ----------------- |
| Pinot, Dremio (Calcite)      | data         | `formatAnsi`      |
| ksqlDB (Presto-derived)      | data         | `formatAnsi`      |
| Athena, Presto, Trino        | data         | `formatAnsi`      |
| MySQL, Hive, Spark SQL       | escape char  | `formatMySql`     |
| ClickHouse, Cube Store       | escape char  | `formatMySql`     |
ovr and others added 3 commits July 27, 2026 17:11
… parity

The escapeStringLiteral suite asserted that the literal is quoted and that its
body contains an even number of quotes. That is strictly weaker than the
decodeAnsiLiteral round-trip the ANSI and MySQL suites already use, and it
accepts escapers that silently corrupt the value:

| Mutant escaper                | Quote parity | Round-trip |
| ----------------------------- | ------------ | ---------- |
| strips every quote            | passes       | fails      |
| quadruples every quote        | passes       | fails      |

escapeStringLiteral is `new SqlEscaper(AnsiSqlDialect).escapeString`, i.e. the
exact grammar decodeAnsiLiteral parses, so the payload cases now decode and
compare against the input, and the suite gains the same short-combination
round-trip loop as its siblings.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Spark SQL, Hive and Databricks lexers know backslash escapes only. A doubled
quote is not an escape there: it closes the literal and opens the next one,
and because adjacent literals are concatenated the corruption is silent — no
parse error is raised.
@ovr
ovr force-pushed the fix/other-drivers-escape branch from 6cc5638 to 33818b5 Compare July 27, 2026 15:11
@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 3m 40s —— View job


Claude PR Review

Verdict: LGTM. 0 blockers, 2 low, 2 nits. New spark dialect is a genuine correctness fix, not a rename.

Details
  • Read PR context and commits (6ec532a → 33818b5)
  • List existing review threads (none)
  • Read changed files + verify dialect claims
  • Analyze correctness / security / tests
  • Post review

Latest commits since prior reviews

  • 190bcde — replaces the odd/even quote-parity assertions with a real round-trip through mini-decoders (decodeAnsiLiteral / decodeMySqlLiteral / decodeSparkLiteral). Strictly stronger: a parity check would have passed on '' for Spark; the round-trip catches it.
  • 33818b5 — adds SparkSqlDialect (sql-escape.ts:39) and flips sparksql, hive, and DatabricksDriver from 'mysql' to 'spark'.

Verified: the Spark claim holds

The comment at sql-escape.ts:33-38 is accurate. Spark's SqlBaseLexer STRING rule is '\'' ( ~('\''|'\\') | ('\\' .) )* '\'' — '' is not an escape, it terminates the literal — and the constant : … | stringLit+ production concatenates adjacent literals. So 'O''Brien' evaluates to OBrien with no parse error. Hive's grammar behaves the same way. The prior 'mysql' mapping was safe by coincidence (same identifier char, same backslash semantics) but silently corrupted any value containing a quote. escapeString already ordered the backslash pass before the quote pass, so no engine change was needed. Good catch, and arguably a nastier failure mode than the trailing-backslash swallow because it fails silently.

Correctness

  • format(dialect, …) consolidates the three helpers behind one Dialects table; formatAnsi/formatMySql are now thin wrappers — no behavior drift.
  • EscapeDialect lives in @cubejs-backend/shared and is re-exported as a type from jdbc-driver/supported-drivers.ts and via src/index.ts — non-breaking for DatabricksDriver's import.
  • Visibility narrowing (public → protected prepareQueryWithParams) on Pinot and Presto: grepped all in-tree callers, both only self-invoke; tests reach it via subclass. Safe.
  • Legacy Dremio/Pinot regex band-aids (.replace(/\\\\([_%])/g, …), .replace(/\\'/g, "''")) removed correctly — they existed to undo sqlstring's MySQL output, and formatAnsi never emits \_ / \% / \'. The Dremio LIKE-ESCAPE '\' tests pin that new\_order passes through untouched.
  • cb29812 moving prepareQueryWithParams inside the try in stream() (JDBCDriver.ts:294) is right — a throw during preparation now releases the pooled connection through the existing catch instead of leaking it.
  • QuestDB escapeStringLiteral(table) closes the last raw '${table}' interpolation. QuestDB accepts single-quoted table identifiers, so this is the correct form.

Low — Date values render as ISO-8601, diverging from sqlstring

escapeValue returns value.toISOString() for Date (sql-escape.ts:96, asserted at test/sql-escape.test.ts:359), i.e. '2024-01-02T03:04:05.000Z'. sqlstring.dateToString emitted '2024-01-02 03:04:05.000'. That choice landed with the merged Presto/Trino fix, but this PR widens it to the MySQL / Hive / Spark JDBC paths, where the T separator and trailing Z are not equally tolerated — Hive's timestamp parser rejects both and yields NULL; MySQL rejects the Z. Reachability is narrow but not zero: BaseDriver.toColumnValue (BaseDriver.ts:514) passes row values through unchanged into the INSERT INTO … VALUES (?, …) in uploadTableWithIndexes, so a source driver that parses timestamps into Date would hit it. Worth either confirming no in-tree path passes Date params to a JDBC driver, or making the date rendering dialect-aware.

Low — escapeDialect() fallback to 'mysql' (inline)

Previously flagged as a top-level note; now filed inline with the reachability detail — CUBEJS_JDBC_DRIVER + CUBEJS_JDBC_URL satisfy the constructor's required-property checks without any SupportedDrivers entry, so an arbitrary dbType genuinely reaches the fallback and gets MySQL rules on a likely standard-SQL engine.

Nits

  • escapeStringLiteral is ANSI-hardcoded but dialect-neutral in name (inline).
  • formatSparkSql is exported but only consumed by the test suite — drivers go through format('spark', …). Fine as a public API, just noting it has no production caller.
  • DremioDriver.js:279 attaches applyParams onto module.exports purely so the unit test can reach it, which makes it a de-facto static on the exported class. Harmless; an explicit module.exports.applyParams is the pragmatic option for a CJS file.
  • cubejs-dremio-driver's test script is still yarn integration, so the new test/unit/params-escaping.test.ts runs only under yarn unit (after yarn tsc, since it resolves from dist/test/unit). Same for ksql/pinot/jdbc. Assuming CI invokes yarn unit per package — I couldn't confirm, .github/workflows isn't in this checkout.

Tests

Genuinely adversarial and now round-trip-verified: injection payload table, exhaustive 4-char combinations over ' \ \0 \n \r a, Unicode/invisible characters, buffer/array/object/toSqlString parity with sqlstring, cross-dialect anchor on a\b'c, and an explicit assertion that Spark output does not contain ''. escape-dialect.test.ts still fails if a new SupportedDrivers entry omits a dialect.

Note: I could not execute the suites — node_modules is absent in this review environment, and a full yarn install was out of scope for a review pass. Review is static.

Security

Addresses the CVE-class issue in both directions the PR body describes, plus the newly-identified silent-concatenation variant on Spark/Hive. No new injection surface introduced.

• [Branch](https://github.com/cube-js/cube/tree/fix/other-drivers-escape)

@claude

claude Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ovr's task in 1m 38s —— View job


Claude PR Review

Verdict: request changes. 1 medium, 0 low. New commit d02e55d fixes the fallback but the throw is reachable from a supported config.

Details

  • Read PR context and existing threads
  • Diff since last review — new commit d02e55d "chore: require dialect"
  • Verify reachability of the new throw
  • Resolve stale own thread, post finding

New commit d02e55d

Addresses the low I'd flagged twice: escapeDialect is now required on DriverOptionsInterface, and JDBCDriver.escapeDialect() throws instead of falling back to 'mysql'. The test file also grew real coverage — it stubs the JVM modules virtually, builds a driver via Object.create(JDBCDriver.prototype) to skip the pool, and asserts per-engine output plus the throw. Good shape; my prior thread on the fallback is resolved.

Medium — the throw is reachable from CUBEJS_DB_TYPE=jdbc (inline)

packages/cubejs-server-core/src/core/DriverDependencies.ts:9 maps jdbc: '@cubejs-backend/jdbc-driver' — the generic JDBC driver is reached with config.dbType === 'jdbc', and the constructor is built for exactly that (dbTypeDescription undefined, drivername/url from CUBEJS_JDBC_DRIVER / CUBEJS_JDBC_URL, JDBCDriver.ts:122-138). SupportedDrivers has keys mysql, athena, sparksql, hive only — no jdbc. So escapeDialect() throws and every query fails for generic JDBC users.

Compounding:

  • No escape hatch — escapeDialect isn't on JDBCDriverConfiguration and there's no env var, so the user's only remedy is patching SupportedDrivers.
  • Fails late — testConnection() and pool creation succeed; the error surfaces on the first query, so a broken config looks healthy at startup.

Fail-loud is the right call; the problem is where the loud failure lands. Suggested shape: optional escapeDialect on JDBCDriverConfiguration (+ env/constructor option), preferred over the table lookup, with the throw retained only when neither is present, and validated in the constructor.

Rest of the PR (re-verified, unchanged)

  • Dremio, Pinot, ksqlDB, Presto, Trino, QuestDB → formatAnsi (backslash is data).
  • SparkSqlDialect for sparksql / hive / Databricks — genuine correctness fix, not a rename: Spark's SqlBaseLexer STRING rule doesn't treat '' as an escape and constant : … | stringLit+ concatenates adjacent literals, so 'O''Brien' silently evaluates to OBrien with no parse error. The prior 'mysql' mapping corrupted any quoted value.
  • Legacy Dremio/Pinot regex band-aids removed correctly — formatAnsi never emits \_ / \% / \'.
  • escapeStringLiteral closes the last raw '${table}' interpolation in QuestDB.
  • sqlstring dropped from jdbc-driver, trino-driver, and transitively via Pinot/Dremio/Ksql.
  • cb29812 moving prepareQueryWithParams inside the try in stream() releases the pooled connection on preparation errors.

Tests

Round-trip decoders (decodeAnsiLiteral / decodeMySqlLiteral / decodeSparkLiteral) are strictly stronger than the prior quote-parity checks — parity would have passed on '' for Spark. Injection-payload table, exhaustive 4-char combinations, Unicode, sqlstring parity for buffer/array/object/toSqlString, cross-dialect anchor on a\b'c, explicit "Spark output contains no ''". escape-dialect.test.ts guards both the mapping table and the new throw.

Not covered: a test for dbType: 'jdbc' — that gap is what let the medium above through.

Note: static review only. node_modules is absent in this environment, so I could not execute the suites.

Security

Addresses the CVE-class issue in both directions from the PR body plus the Spark/Hive silent-concatenation variant. No new injection surface. The remaining risk is availability, not injection.

• Branch •

@ovr
ovr merged commit a743790 into master Jul 27, 2026
122 of 125 checks passed
@ovr
ovr deleted the fix/other-drivers-escape branch July 27, 2026 16:01
ovr added a commit that referenced this pull request Jul 27, 2026
@claude claude Bot mentioned this pull request Jul 27, 2026
ovr added a commit that referenced this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cubejs-jdbc-driver data source driver driver:databricks driver:dremio driver:pinot driver:prestodb Issues relating to the PrestoDB driver driver:questdb driver:trino Issues relating to the Trino driver javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy