Repository navigation
[🍒] Fix SQL injection in connector sample path and escape init queries for release/1.11 - #697
Conversation
There was a problem hiding this comment.
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.
db0d1a7 to
8d5cd5f
Compare
[🍒]
🍒 [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 anUPDATE) in default autocommit mode under the connection's stored credential. The same unescaped identifier pattern existed across the other database connectors.(Note: Source query /
splitByvalidation viaSelectQueryValidatorhas 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
quoteIdentifier): Schema, database, table, andstratacolumn identifiers inAbstractDBSpecificConnectorand 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.AbstractDBSpecificConnector.loadTableSchemanow setsconnection.setReadOnly(true), disables auto-commit (when!isAutoCommitEnabled()), and rolls back infinallyon both normal completion and error, closing the opened connections ingetInputFormatProviderandgetTableSchema.getInputFormatProvider->DataDrivenETLDBInputFormat) marks the configuration read-only (ConnectionConfigAccessor.READ_ONLY) and wraps non-autocommit sampling connections inRollbackOnCloseConnectionsoDBRecordReader.close()rolls back instead of committing.SqlServerConstants.buildSetLanguageQueryandMysqlConstants.buildSetSqlModeQueryto escape interpolated string literals across all 8 SQL Server and MySQL source/sink/action/post-action configs.Testing
quoteIdentifier,getTableName, andgetStratifiedQueryacross every connector (including the exact payload from the report).AbstractDBSpecificConnectorReadOnlyTest,RollbackOnCloseConnectionTest) verifying read-only transaction setup, rollback on error/close, fullInputFormat/RecordReadersampling, and that neither a stackedUPDATEin a table path nor a directUPDATEpassed toloadTableSchemamodifies a marker table.SqlServerInitQueriesUnitTest,MysqlInitQueriesUnitTest) pinninggetInitQueries()escaping across all 8 MySQL and SQL Server configs.