Skip to content

[#4211] fix(catalog-jdbc): Harden database SQL generation against injection - #11780

Open
JandyTenedora wants to merge 7 commits into
apache:mainfrom
JandyTenedora:jandyt/fix-sql-injection-drop-database-validation
Open

[#4211] fix(catalog-jdbc): Harden database SQL generation against injection#11780
JandyTenedora wants to merge 7 commits into
apache:mainfrom
JandyTenedora:jandyt/fix-sql-injection-drop-database-validation

Conversation

@JandyTenedora

@JandyTenedora JandyTenedora commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add validateBacktickQuotedIdentifier() in JdbcDatabaseOperations to reject database names containing SQL metacharacters before they are embedded in backtick-quoted DROP DATABASE statements. Applied to all JDBC catalog overrides that use backtick quoting (MySQL, OceanBase via parent, Doris, StarRocks, ClickHouse).

Why are the changes needed?

generateDropDatabaseSql builds SQL via string formatting with backtick quoting. A name containing backticks can break out of the identifier and inject arbitrary SQL. The upstream SchemaNormalizeDispatcher validates names today, but calling JdbcDatabaseOperations.delete() directly bypasses that validation.

Fix: #4211

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added unit tests for drop-path validation in TestJdbcDatabaseOperations, TestClickHouseDatabaseOperations, TestDorisDatabaseOperationsSqlGeneration, and TestStarRocksDatabaseOperationsSqlGeneration — covering valid names, null, empty, SQL injection strings, spaces, and overlength names.

./gradlew :catalogs:catalog-jdbc-common:test
./gradlew :catalogs:catalog-jdbc-doris:test
./gradlew :catalogs:catalog-jdbc-starrocks:test
./gradlew :catalogs-contrib:catalog-jdbc-clickhouse:test

@JandyTenedora
JandyTenedora force-pushed the jandyt/fix-sql-injection-drop-database-validation branch 2 times, most recently from 00fb195 to 7f4edee Compare June 25, 2026 13:59
@JandyTenedora JandyTenedora changed the title Jandyt/fix sql injection drop database validation [#4211] fix(catalog-jdbc): Harden database SQL generation against injection Jun 25, 2026
@JandyTenedora
JandyTenedora force-pushed the jandyt/fix-sql-injection-drop-database-validation branch 2 times, most recently from 2e05a2e to 1a47603 Compare June 25, 2026 17:34
@JandyTenedora

Copy link
Copy Markdown
Contributor Author
image image

Reran

  ./gradlew spotlessApply
  ./gradlew spotlessCheck

@JandyTenedora
JandyTenedora force-pushed the jandyt/fix-sql-injection-drop-database-validation branch from 07b4fba to e4daa5d Compare June 29, 2026 11:54
@yuqi1129

Copy link
Copy Markdown
Contributor

@JandyTenedora
Is this one ready for review?

…ck-quoted drop SQL

Add validateBacktickQuotedIdentifier() in JdbcDatabaseOperations to reject
database names containing SQL metacharacters before they are embedded in
backtick-quoted DROP DATABASE statements. Applied to all JDBC catalog
overrides that use backtick quoting (MySQL, OceanBase, Doris, StarRocks,
ClickHouse).
@JandyTenedora
JandyTenedora force-pushed the jandyt/fix-sql-injection-drop-database-validation branch from cf84ad6 to 7d4709c Compare July 10, 2026 13:16
@JandyTenedora

Copy link
Copy Markdown
Contributor Author

Hi @yuqi1129, yes it is. Was just waiting to be assigned the issue. Have updated with latest master now :)

@JandyTenedora
JandyTenedora marked this pull request as ready for review July 10, 2026 13:17
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 67.79% -0.02% 🟢
Files changed 61.09% 🟢

Module Coverage
aliyun 1.72% 🔴
api 47.82% 🟢
authorization-common 85.96% 🟢
aws 42.04% 🟢
azure 2.47% 🔴
catalog-common 9.92% 🔴
catalog-fileset 79.74% 🟢
catalog-glue 66.91% 🟢
catalog-hive 79.4% 🟢
catalog-jdbc-common 46.74% -2.48% 🟢
catalog-jdbc-doris 81.75% -0.34% 🟢
catalog-jdbc-mysql 79.33% 🟢
catalog-jdbc-postgresql 83.44% +0.9% 🟢
catalog-jdbc-starrocks 79.21% -0.3% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 59.18% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.86% 🟢
catalog-lakehouse-paimon 84.23% 🟢
catalog-model 77.72% 🟢
cli 44.5% 🟢
client-java 78.27% 🟢
common 51.95% 🟢
core 82.55% 🟢
filesystem-hadoop3 77.28% 🟢
flink 0.0% 🔴
flink-common 47.09% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 12.7% 🔴
hive-metastore-common 53.4% 🟢
iceberg-common 64.65% 🟢
iceberg-rest-server 74.91% 🟢
idp-basic 86.02% 🟢
integration-test-common 0.0% 🔴
jobs 66.17% 🟢
lance-common 20.67% 🔴
lance-rest-server 64.84% 🟢
lineage 53.02% 🟢
optimizer 83.24% 🟢
optimizer-api 21.95% 🔴
server 86.05% 🟢
server-common 76.12% 🟢
spark 28.57% 🔴
spark-common 46.01% 🟢
tencent 69.84% 🟢
trino-connector 40.29% 🟢
Files
Module File Coverage
catalog-jdbc-common JdbcDatabaseOperations.java 20.93% 🔴
catalog-jdbc-doris DorisDatabaseOperations.java 75.86% 🟢
catalog-jdbc-postgresql PostgreSqlSchemaOperations.java 90.14% 🟢
catalog-jdbc-starrocks StarRocksDatabaseOperations.java 73.81% 🟢

@yuqi1129

Copy link
Copy Markdown
Contributor

@JandyTenedora
Do we only need to handle drop operations? What about other operations?

@JandyTenedora

Copy link
Copy Markdown
Contributor Author

@JandyTenedora Do we only need to handle drop operations? What about other operations?

Hi @yuqi1129 thanks so much for the feedback! I did actually consider putting similar guards in for generateCreateDatabaseSql as well. I assumed the issue was scoped to generateDropDatabaseSql as per the description.

Happy to fold this into this PR too? Or submit as follow ups once this lands? Let me know your preference

@yuqi1129

Copy link
Copy Markdown
Contributor

@JandyTenedora Do we only need to handle drop operations? What about other operations?

Hi @yuqi1129 thanks so much for the feedback! I did actually consider putting similar guards in for generateCreateDatabaseSql as well. I assumed the issue was scoped to generateDropDatabaseSql as per the description.

Happy to fold this into this PR too? Or submit as follow ups once this lands? Let me know your preference

I suggest you fix this problem thoroughly within a PR.

@JandyTenedora

Copy link
Copy Markdown
Contributor Author

Hi @yuqi1129 , I've added the guards for the create path. Apologies should have updated the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Possible SQL injection in MysqlDatabaseOperations.java

2 participants