Skip to content

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

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

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

Conversation

@vishwasvaidya-cloudsufi

@vishwasvaidya-cloudsufi vishwasvaidya-cloudsufi commented Nov 26, 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.

@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 updates the database plugins to version 1.11.16-SNAPSHOT and introduces SQL injection prevention by implementing identifier quoting across multiple database connectors. It also configures read-only transactions during schema loading and sampling, introducing a RollbackOnCloseConnection wrapper to ensure uncommitted changes are rolled back before closing. Feedback on the changes highlights critical issues, including potential NullPointerExceptions when deregistering a null driverShim in DataDrivenETLDBInputFormat, and unintended side-effects on shared connections in AbstractDBSpecificConnector where the original auto-commit and read-only states should be restored. Additionally, replacing the deprecated Throwables.propagate with standard Java exception wrapping is recommended.

@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi merged commit 5ea62aa into release/1.11 Nov 30, 2026
9 of 15 checks passed
@vishwasvaidya-cloudsufi
vishwasvaidya-cloudsufi deleted the sql-identifier-escaping-cherrypick-1.11 branch November 30, 2026 04:07
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.

2 participants