Skip to content

[🍒] Fix SQL injection in connector sample path and escape init queries for release/1.12 - #693

Merged
vishwasvaidya-cloudsufi merged 1 commit into
release/1.12from
sql-identifier-escaping-cherrypick-1.12
Nov 30, 2026
Merged

vishwasvaidya-cloudsufi merged 1 commit into
release/1.12from
sql-identifier-escaping-cherrypick-1.12

Conversation

@vishwasvaidya-cloudsufi

@vishwasvaidya-cloudsufi vishwasvaidya-cloudsufi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

[🍒]

🍒 [cherrypick]

PR : (#688)

Description:

What's this about

A VRP report found a SQL injection in the Cloud SQL PostgreSQL connector's sample/spec path. A table path containing a " could break out of the quoted identifier and execute stacked statements (such as an UPDATE) in default autocommit mode under the connection's stored credential. The same unescaped identifier pattern existed across the other database connectors.

(Note: Source query / splitBy validation via SelectQueryValidator has been split out to a follow-up PR per review feedback so this fix can merge without blocking on source-query validation design, compatibility flags, and docs.)

What changed

  • Connector identifier escaping (quoteIdentifier): Schema, database, table, and strata column identifiers in AbstractDBSpecificConnector and all connector overrides (CloudSQLPostgreSQL, PostgreSQL, Redshift, Oracle, SqlServer, MySQL, CloudSQLMySQL, Databricks) now double embedded quote characters (" or `) so user-supplied path/sample parameters cannot break out of the quoted identifier.
  • Read-only connection & rollback defense-in-depth:
    • AbstractDBSpecificConnector.loadTableSchema now sets connection.setReadOnly(true), disables auto-commit (when !isAutoCommitEnabled()), and rolls back in finally on both normal completion and error, closing the opened connections in getInputFormatProvider and getTableSchema.
    • Connector sampling (getInputFormatProvider -> DataDrivenETLDBInputFormat) marks the configuration read-only (ConnectionConfigAccessor.READ_ONLY) and wraps non-autocommit sampling connections in RollbackOnCloseConnection so DBRecordReader.close() rolls back instead of committing.
  • Init queries: Extracted SqlServerConstants.buildSetLanguageQuery and MysqlConstants.buildSetSqlModeQuery to escape interpolated string literals across all 8 SQL Server and MySQL source/sink/action/post-action configs.

Testing

  • Unit tests for quoteIdentifier, getTableName, and getStratifiedQuery across every connector (including the exact payload from the report).
  • Unit + embedded-HSQLDB end-to-end tests (AbstractDBSpecificConnectorReadOnlyTest, RollbackOnCloseConnectionTest) verifying read-only transaction setup, rollback on error/close, full InputFormat/RecordReader sampling, and that neither a stacked UPDATE in a table path nor a direct UPDATE passed to loadTableSchema modifies a marker table.
  • Unit tests (SqlServerInitQueriesUnitTest, MysqlInitQueriesUnitTest) pinning getInitQueries() escaping across all 8 MySQL and SQL Server configs.
  • Testing Report : https://docs.google.com/document/d/1c6EB2mV9I8-BiztZ62uKJFq9pfodM-afoOby-J88qUk/edit?usp=sharing

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces robust SQL identifier escaping across multiple database connectors (including Redshift, CloudSQL, Databricks, SQL Server, MySQL, Oracle, and PostgreSQL) to mitigate SQL injection vulnerabilities. It also implements read-only transaction configurations and rollback-on-close mechanisms to secure schema loading and sampling operations. Review feedback suggests simplifying the getTableName implementation in DatabricksConnector by removing redundant null checks for database and schema parameters, as they are guaranteed to be non-null, and updating the corresponding unit tests accordingly.

@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi force-pushed the sql-identifier-escaping-cherrypick-1.12 branch from d07d748 to 34ce458 Compare November 30, 2026 11:52
@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi merged commit bc60078 into release/1.12 Nov 30, 2026
18 of 19 checks passed
@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi deleted the sql-identifier-escaping-cherrypick-1.12 branch November 30, 2026 17:04
@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi restored the sql-identifier-escaping-cherrypick-1.12 branch November 30, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants