[
https://issues.apache.org/jira/browse/KNOX-3442?focusedWorklogId=1040242&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1040242
]
ASF GitHub Bot logged work on KNOX-3442:
----------------------------------------
Author: ASF GitHub Bot
Created on: 08/Sep/26 13:43
Start Date: 08/Sep/26 13:43
Worklog Time Spent: 10m
Work Description: smolnar82 opened a new pull request, #1383:
URL: https://github.com/apache/knox/pull/1383
[KNOX-3442](https://issues.apache.org/jira/browse/KNOX-3442) - Harden H2
JDBC URL construction against injection
## What changes were proposed in this pull request?
`H2DataSourceFactory` built the JDBC URL by concatenating
`gateway.database.name` verbatim. H2 URLs can carry connection settings
(`INIT`, `RUNSCRIPT`, `CREATE ALIAS`) that execute arbitrary code, so a
malicious/misconfigured name was a latent RCE sink. The factory now rejects
`INIT`/`RUNSCRIPT`/`ALIAS` tokens in the settings portion (after the first `;`,
whole-word, case-insensitive) with a clear `SQLException` before the URL is
built. The embedded path and valid settings (`DB_CLOSE_DELAY`, `AUTO_SERVER`,
`CIPHER`, ...) are unaffected.
## How was this patch tested?
Added unit tests in `DataSourceProviderTest` covering a valid
`mem:knox;DB_CLOSE_DELAY=-1` name, a rejected `;INIT=RUNSCRIPT FROM
'http://…'`, and a rejected `;init=CREATE ALIAS …`. Full suite: `Tests run: 23,
Failures: 0, Errors: 0`.
## Integration Tests
N/A
## UI changes
N/A
Issue Time Tracking
-------------------
Worklog Id: (was: 1040242)
Remaining Estimate: 0h
Time Spent: 10m
> Harden H2 JDBC URL construction against connection-string injection via
> gateway.database.name
> ---------------------------------------------------------------------------------------------
>
> Key: KNOX-3442
> URL: https://issues.apache.org/jira/browse/KNOX-3442
> Project: Apache Knox
> Issue Type: Improvement
> Components: Server
> Affects Versions: 3.1.0
> Reporter: Sandor Molnar
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> KNOX-3401 added H2. H2DataSourceFactory builds the URL by raw concatenation:
> {noformat}
> String url = "jdbc:h2:" + gatewayConfig.getDatabaseName(); // :49
> {noformat}
> {{gateway.database.name}} comes straight from {{gateway-site.xml}},
> unvalidated. H2 URLs are an RCE sink: an appended {{;INIT=RUNSCRIPT FROM
> 'http://…'}} (or CREATE ALIAS …) runs arbitrary code at datasource creation.
> The embedded path is safe ({{{}EmbeddedH2Database{}}} sets a trusted
> {{securityDir}} file path), but a manually-configured non-embedded H2
> deployment flows the raw value into the URL. Operator-controlled/trusted
> config, so low severity, but cheap defense-in-depth.
> Fix: reject H2 code-execution tokens ({{{}INIT/RUNSCRIPT/ALIAS{}}},
> case-insensitive) in the name at URL construction, fail-fast. Not a blanket
> {{';'}} ban, because valid H2 settings exist (e.g.
> {{{}mem:knox;DB_CLOSE_DELAY=-1{}}}).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)