Sandor Molnar created KNOX-3442:
-----------------------------------
Summary: 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
Fix For: 3.1.0
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)