Skip to content

fix: Escape quote characters in SQL identifiers - #12622

Merged
ovr merged 2 commits into
masterfrom
ovr/rest-mysql-alias-inject
Nov 5, 2026
Merged

ovr merged 2 commits into
masterfrom
ovr/rest-mysql-alias-inject

Conversation

@ovr

@ovr ovr commented Nov 5, 2026

Copy link
Copy Markdown
Member

No description provided.

@claude

claude Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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


Fix is right where applied, but incomplete — 0 high, 1 medium, 1 low. BigQuery, ClickHouse and ksqlDB can still be injected through identifiers.

Review details
  • Gather context (diff, changed files)
  • Review changes
  • Resolve/check prior review threads
  • Post findings

Findings

Severity Location Issue
Medium packages/cubejs-schema-compiler/src/adapter/BaseQuery.ts:971 BigqueryQuery.ts:76, ClickHouseQuery.ts:79 and KsqlQuery.ts:54 still put names between backticks unescaped (legacy planner). On Tesseract, the BigQuery and ClickHouse quotes.escape = '\\'never escapes backslashes, so ``a\`` or a trailing` breaks out of the identifier.
Low packages/cubejs-schema-compiler/src/adapter/MysqlQuery.ts:225 No schema-compiler test for the adapter overrides or the MySQL template change. The only new test covers the shared helpers.

What looks right

  • The MySQL quotes.escape change from '\\'to'``'` fixes Tesseract on MySQL. MySQL never accepted backslash escapes inside identifiers, so the old value didn't work.
  • escapeIdentifier doubles the quote character, which is correct for ANSI SQL, MySQL, Spark, Hive and Databricks. Dremio and Vertica now inherit the ANSI version from BaseQuery, so dropping their overrides is fine.
  • Every call builds a new SqlEscaper. That allocation is trivial even though escapeColumnName runs often; a module-level instance would be a nicety, not a fix.

Docs

None needed: this is a bug fix with no new options or behaviour for users.

Review threads

The listing returned 0 of my threads (no prior threads), so none were resolved or re-affirmed. Both findings were posted inline.

Not run

I didn't run the sql-escape unit tests: the permission sandbox blocked the jest command.

@cube-js cube-js deleted a comment from claude Bot Nov 5, 2026
@ovr ovr changed the title fix(schema-compiler): Escape quote characters in SQL identifiers fix: Escape quote characters in SQL identifiers Nov 5, 2026
@ovr
ovr requested a review from a team as a code owner November 5, 2026 12:18
@github-actions github-actions Bot added the rust Pull requests that update Rust code label Nov 5, 2026
@claude

claude Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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


LGTM: 0 high, 0 medium, 1 low. The one low is a missing test, already tracked in an existing thread, so nothing new is posted inline.

Review details

Checklist

  • Gather diff and changed files
  • Review escaping per dialect (JS + Rust)
  • Check tests / docs
  • Review threads
  • Post findings

Correctness: each dialect checked

Adapter Before After Engine rule
Base (Postgres, Snowflake, MSSQL, Oracle, Dremio, Vertica, …) "${name}" "a""b" ANSI doubling (Calcite/Dremio and Vertica follow it) ✅
MySQL / Cube Store `${name}`, template escape \` `ab``, template escape `` ` MySQL never treats a backslash as an escape inside identifiers, so the old \` closed the identifier early. That was the injection, and it is now fixed ✅. Cube Store's sqlparser 0.54 fork reads doubled quotes in identifiers ✅
Hive / Databricks / ksqlDB raw backticks `ab` `` Hive, Spark and the ksql grammar ( '' ) all double the backtick ✅. JS output now matches the existing ` ` templates
BigQuery / ClickHouse raw backticks `a\`b` with backslash doubled first Both engines read backslash escapes in backticked identifiers ✅. JS output now matches the \` templates

On the Rust side, quote_identifier in plan.rs:206 (Tesseract) and service.rs:680 (SQL API) uses the same escape.starts_with('\\') check. That check is consistent with every quotes.escape template in the repo. Escaping backslashes before quotes is the right order: a\` becomes `a\\\ ``, and the new tests cover that case.

Removing the Dremio and Vertica overrides doesn't change normal output: they were identical to the old base method, and the new base method now escapes " correctly for both.

Findings

  • Low: missing end-to-end test. All new tests target the shared helpers (sql-escape.test.ts:567) or the Rust quote_identifier. No schema-compiler test compiles a MySQL, BigQuery or Tesseract query with a quote character in a member alias. That is the actual REST → MySQL alias injection path, so it is the place a regression test belongs. This is the same concern as the existing open thread on MysqlQuery.ts:225, so it is folded into that thread and not posted again.

Not in this PR

Driver quoteIdentifier methods still interpolate raw quotes, e.g. BaseDriver.ts:600, MySqlDriver.ts:312, BigQueryDriver.ts:487, CubeStoreDriver.ts:237, DatabricksDriver.ts:750. Their inputs are pre-aggregation table and column names from the data model or introspection, not API callers, so I don't see them as exploitable. They could switch to the same helpers later for consistency.

Docs

None needed. This is a bug fix with no new options or behaviour that users would need documented.

Tests

I didn't run them locally: the jest command needed approval in this environment. CI covers the shared and Rust tests.

Review threads

The listing returned 1 of my own threads. I resolved 0 and re-affirmed 1 (MysqlQuery.ts:225, missing schema-compiler regression test), which is still unaddressed.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.17%. Comparing base (d8516cd) to head (fc52bcc).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
packages/cubejs-ksql-driver/src/KsqlQuery.ts 50.00% 1 Missing ⚠️
...es/cubejs-schema-compiler/src/adapter/HiveQuery.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12622      +/-   ##
==========================================
+ Coverage   83.15%   83.17%   +0.01%     
==========================================
  Files         531      531              
  Lines      124741   124800      +59     
  Branches     5294     5308      +14     
==========================================
+ Hits       103726   103800      +74     
+ Misses      20221    20202      -19     
- Partials      794      798       +4     
Flag Coverage Δ
cube-backend 66.24% <91.66%> (+0.05%) ⬆️
cubesql 86.80% <100.00%> (+0.01%) ⬆️

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.

@ovr
ovr merged commit cc12c27 into master Nov 5, 2026
121 checks passed
@ovr
ovr deleted the ovr/rest-mysql-alias-inject branch November 5, 2026 14:49
ovr added a commit that referenced this pull request Nov 9, 2026
Identifiers were wrapped in the dialect's quote without escaping that quote
inside the name, so a quote character in a member alias ended the identifier
early and let the rest of the alias run as SQL.

- `escapeColumnName` now uses new `@cubejs-backend/shared` helpers:
  `escapeIdentifierAnsi` (Base, Vertica, Dremio), `escapeIdentifierMySql`
  (MySQL, Cube Store), `escapeIdentifierSparkSql` (Hive, Databricks, ksqlDB)
  and `escapeIdentifierBackslash` (BigQuery, ClickHouse).
- The MySQL `quotes/escape` template doubles the backtick instead of `\``,
  which MySQL reads literally inside an identifier.
- `quote_identifier` in Tesseract and cubesql doubles backslashes before a
  backslash-escaped quote (BigQuery, ClickHouse), so `\` in a name can no
  longer escape the quote after it.

(cherry picked from commit 8c76d4c)
kewin-robetti pushed a commit to viasoftkorp/cube that referenced this pull request Nov 13, 2026
Identifiers were wrapped in the dialect's quote without escaping that quote
inside the name, so a quote character in a member alias ended the identifier
early and let the rest of the alias run as SQL.

- `escapeColumnName` now uses new `@cubejs-backend/shared` helpers:
  `escapeIdentifierAnsi` (Base, Vertica, Dremio), `escapeIdentifierMySql`
  (MySQL, Cube Store), `escapeIdentifierSparkSql` (Hive, Databricks, ksqlDB)
  and `escapeIdentifierBackslash` (BigQuery, ClickHouse).
- The MySQL `quotes/escape` template doubles the backtick instead of `\``,
  which MySQL reads literally inside an identifier.
- `quote_identifier` in Tesseract and cubesql doubles backslashes before a
  backslash-escaped quote (BigQuery, ClickHouse), so `\` in a name can no
  longer escape the quote after it.
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 javascript Pull requests that update Javascript code rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ Proxy