Skip to content

[SECURITY] Block JDBC URL-option injection via DB2 instance field#5450

Merged
casionone merged 1 commit into
apache:masterfrom
aiceflower:dev-CVE-db2-instance-injection
Jun 26, 2026
Merged

[SECURITY] Block JDBC URL-option injection via DB2 instance field#5450
casionone merged 1 commit into
apache:masterfrom
aiceflower:dev-CVE-db2-instance-injection

Conversation

@aiceflower

Copy link
Copy Markdown
Member

What is the purpose of the change

Follow-up to #5449 that closes a remaining JDBC URL-option injection sink reported separately against the DB2 instance field. The DB2 SqlConnection classes interpolate the user-supplied instance value directly into the URL via String.format(\"jdbc:db2://%s:%s/%s\", ...), so a malicious value like SAMPLE:traceLevel=1; becomes jdbc:db2://host:port/SAMPLE:traceLevel=1;. The CVE-2023-49566 fix in #5449 denylisted clientRerouteServerListJNDIName etc. when they arrive via Properties, but a value smuggled through the URL database segment bypasses Properties entirely and reaches driver options like traceLevel/traceFile/traceDirectory/traceFileAppend that allow arbitrary file writes.

Same class of issue affects SQL Server (; separator), Oracle (service-name slot), and the jdbc:mysql:// family (?/&).

This PR adds four layers of defense:

  1. Runtime validation (primary fix). New SecurityUtils.checkDatabaseIsSafe(JdbcDriverType, database) rejects URL-option separators per driver family. Called from the generic checkJdbcConnParams path used by every non-MySQL SqlConnection.

    • DB2 → : ; ? # & (matches the advisory's PoC)
    • SQLSERVER → ; ? # &
    • ORACLE → ? # &
    • PG/MySQL/ClickHouse/DM/etc → ? # & /
  2. Expanded DB2 denylist. JDBC_DB2_BLOCKED_PARAMS now also includes traceLevel, traceFile, traceDirectory, traceFileAppend so Properties-based injection of the same logging options is blocked too.

  3. Schema-layer validation. Backfill value_regex for the instance field of every JDBC data source in linkis_dml.sql. RegExpParameterValidateStrategy skips validation when value_regex is NULL, so the existing schema offered no first-line defense. New regex ^[A-Za-z0-9_.-]+$.

  4. Upgrade SQL. Same regex backfilled via UPDATE ... WHERE key='instance' AND value_regex IS NULL in the 1.9.0 upgrade script for existing installs.

Tests

  • 6 new unit tests covering: the DB2 PoC (SAMPLE:traceLevel=1; and SAMPLE:traceFile=/tmp/evil;), the single-character variants for each forbidden char, the SQL Server and MySQL variants, benign-database sanity across all driver families, and the expanded DB2 denylist.
  • All 24 tests in SecurityUtilsTest pass.

Relation to prior work

🤖 Generated with Claude Code

@aiceflower aiceflower force-pushed the dev-CVE-db2-instance-injection branch from 9dc6a68 to 338302f Compare June 26, 2026 08:13
…ce/database field

The DB2 SqlConnection classes interpolate the user-supplied instance
value directly into the JDBC URL via String.format("jdbc:db2://%s:%s/%s", ...).
A value containing URL option separators (e.g. "SAMPLE:traceLevel=1;")
becomes "jdbc:db2://host:port/SAMPLE:traceLevel=1;", letting the database
segment toggle DB2 driver options (traceLevel/traceFile/traceDirectory/
traceFileAppend) that bypass the Properties denylist. Same class of issue
affects SQL Server (';' separator), Oracle (service-name slot), and the
mysql:// family.

Adds four layers of defense:

1. SecurityUtils.checkDatabaseIsSafe(JdbcDriverType, database) rejects
   URL-option separators per driver family:
     DB2 -> : ; ? # &
     SQLSERVER -> ; ? # &
     ORACLE -> ? # &
     PG/MySQL/CK/DM/etc -> ? # & /

2. Expand JDBC_DB2_BLOCKED_PARAMS with traceLevel/traceFile/
   traceDirectory/traceFileAppend so Properties-based injection of the
   same logging options is also blocked (defense in depth).

3. Backfill value_regex for the `instance` field of every JDBC data
   source in linkis_dml.sql. RegExpParameterValidateStrategy skips
   validation when value_regex is NULL, so the previous schema offered
   no first-line defense. New regex: ^[A-Za-z0-9_.-]+$

4. Same regex backfilled via UPDATE in the 1.9.0 upgrade script for
   existing installs.

5. 6 new unit tests covering the DB2 database segment, the SQL Server
   and MySQL variants, benign-database sanity, and the expanded DB2
   denylist. All 24 tests in SecurityUtilsTest pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@aiceflower aiceflower force-pushed the dev-CVE-db2-instance-injection branch from 338302f to 099767b Compare June 26, 2026 08:33

@casionone casionone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@casionone casionone merged commit 1da0c67 into apache:master Jun 26, 2026
4 of 11 checks passed
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.

2 participants