Skip to content

Commit acf842e

Browse files
committed
[fix](jdbc) Scope driver_url grammar to create/alter, leave historical catalogs untouched
The strict bare-name grammar was enforced inside the shared resolver getFullDriverUrl(), which is also on the lazy load path of pre-existing catalogs (Iceberg/Paimon/legacy JDBC consumers call it directly, with no create/alter or replay context). An unmodified historical catalog using a previously valid driver file name (e.g. one containing '+') could therefore fail on first access after upgrade. Move the mandatory grammar to the create/alter path only (JdbcDorisConnector.checkDriverUrlSecurityRule, run by checkProperties on CREATE and ALTER, both !isReplay). getFullDriverUrl now applies no new restriction, so historical catalogs resolve exactly as before while new or altered catalogs are still validated.
1 parent a341e48 commit acf842e

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/catalog/JdbcResource.java‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.List;
5656
import java.util.Map;
5757
import java.util.Objects;
58-
import java.util.regex.Pattern;
5958

6059
/**
6160
* External JDBC Catalog resource for external table query.
@@ -301,10 +300,6 @@ private static void checkCloudWhiteList(String driverUrl) throws IllegalArgument
301300
}
302301
}
303302

304-
// A scheme-less driver_url must be a plain jar file name: letters, digits, dot, underscore, hyphen.
305-
// No path separator (encoded or not) and no other characters, so it can never escape jdbc_drivers_dir.
306-
private static final Pattern SAFE_BARE_JAR_NAME = Pattern.compile("^[A-Za-z0-9._-]+\\.jar$");
307-
308303
public static String getFullDriverUrl(String driverUrl) throws IllegalArgumentException {
309304
if (!(driverUrl.startsWith("file://") || driverUrl.startsWith("http://")
310305
|| driverUrl.startsWith("https://") || driverUrl.matches("^[^:/]+\\.jar$"))) {
@@ -325,15 +320,12 @@ public static String getFullDriverUrl(String driverUrl) throws IllegalArgumentEx
325320
String schema = uri.getScheme();
326321
checkCloudWhiteList(driverUrl);
327322
if (schema == null && !driverUrl.startsWith("/")) {
328-
// Enforce the safe bare-name grammar in this shared resolver, before resolving under
329-
// jdbc_drivers_dir. Otherwise an encoded separator (e.g. "%2e%2e%2Fevil.jar") passes the
330-
// loose format check above and, once resolved and decoded by the loader, escapes the
331-
// directory. The connector rule catches "%" too, but Iceberg/Paimon/legacy JDBC consumers
332-
// call getFullDriverUrl directly and bypass that rule, so it must be enforced here.
333-
if (!SAFE_BARE_JAR_NAME.matcher(driverUrl).matches()) {
334-
throw new IllegalArgumentException(
335-
"Invalid driver_url: a driver file name must match [A-Za-z0-9._-]+.jar: " + driverUrl);
336-
}
323+
// A scheme-less driver_url is a plain jar file name resolved under jdbc_drivers_dir. This
324+
// shared resolver is also on the lazy load path of pre-existing catalogs (Iceberg/Paimon/
325+
// legacy JDBC consumers call it directly, with no create/alter or replay context), so it
326+
// deliberately applies no new restriction here: an unmodified historical catalog must keep
327+
// resolving exactly as before. The mandatory bare-name grammar is enforced only when a
328+
// catalog is created or altered, in JdbcDorisConnector.checkDriverUrlSecurityRule.
337329
return checkAndReturnDefaultDriverUrl(driverUrl);
338330
}
339331

‎fe/fe-core/src/test/java/org/apache/doris/catalog/JdbcResourceTest.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,19 @@ public void testSecurePathRejectsRemoteUserInfoMismatch() {
361361
}
362362

363363
@Test
364-
public void testSchemelessEncodedSeparatorRejected() {
365-
// Shared resolver must reject encoded separators in a scheme-less name, so direct consumers
366-
// (Iceberg/Paimon/legacy JDBC) that call getFullDriverUrl cannot escape jdbc_drivers_dir.
367-
Assert.assertThrows(IllegalArgumentException.class, () ->
368-
JdbcResource.getFullDriverUrl("%2e%2e%2Fevil.jar"));
364+
public void testSchemelessLegacyCharsAccepted() {
365+
// The shared resolver is on the lazy load path of pre-existing catalogs, so it applies no new
366+
// restriction: a bare name using historically valid characters (e.g. '+') must keep resolving,
367+
// so an unmodified historical catalog is not broken after upgrade. The stricter bare-name
368+
// grammar applies only when a catalog is created or altered (enforced in the JDBC connector).
369+
String savedDir = Config.jdbc_drivers_dir;
370+
try {
371+
Config.jdbc_drivers_dir = "/opt/doris/jdbc_drivers";
372+
Assert.assertEquals("file:///opt/doris/jdbc_drivers/legacy+patched.jar",
373+
JdbcResource.getFullDriverUrl("legacy+patched.jar"));
374+
} finally {
375+
Config.jdbc_drivers_dir = savedDir;
376+
}
369377
}
370378

371379
@Test

0 commit comments

Comments
 (0)