Gabriel39 commented on code in PR #71205: URL: https://github.com/apache/doris/pull/71205#discussion_r4782713635
########## fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/StorageEndpointProperties.java: ########## @@ -0,0 +1,225 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.filesystem.properties; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** Network endpoint aliases consumed by filesystem providers and their authentication clients. */ +public final class StorageEndpointProperties { + private static final List<String> PAIMON_STORAGE_PREFIXES = List.of( + "paimon.s3.", "paimon.s3a.", "paimon.fs.s3.", "paimon.fs.oss."); + private static final List<String> S3_REGION_ALIASES = List.of("s3.region", "AWS_REGION", "region", "REGION", + "aws.region", "glue.region", "aws.glue.region", "iceberg.rest.signing-region", "rest.signing-region", + "client.region"); + private static final List<String> S3_ENDPOINT_ALIASES = List.of("s3.endpoint", "AWS_ENDPOINT", "endpoint", + "ENDPOINT", "aws.endpoint", "glue.endpoint", "aws.glue.endpoint"); + private static final Pattern[] S3_ENDPOINT_PATTERNS = new Pattern[] { + Pattern.compile( + "^(?:https?://)?(?:" + + "s3(?:[-.]fips)?(?:[-.]dualstack)?[-.]([a-z0-9-]+)|" + + "s3express-control\\.([a-z0-9-]+)|" + + "s3express-[a-z0-9-]+\\.([a-z0-9-]+)" + + ")\\.amazonaws\\.com(?:/.*)?$", + Pattern.CASE_INSENSITIVE), + Pattern.compile( + "^(?:https?://)?glue(?:-fips)?\\.([a-z0-9-]+)\\.(amazonaws\\.com(?:\\.cn)?|api\\.aws)$", + Pattern.CASE_INSENSITIVE) + }; + + private StorageEndpointProperties() { + } + + public static Map<String, List<String>> derivedEndpointValues(Map<String, String> properties) { + String regionKey = firstNonblankKey(properties, S3_REGION_ALIASES); + String endpointKey = firstNonblankKey(properties, S3_ENDPOINT_ALIASES); + String sourceKey = endpointKey; + String endpoint = endpointKey == null ? null : properties.get(endpointKey).trim(); + if (regionKey == null && endpointKey == null) { + // The binder's legacy URI fallback runs on its HashMap snapshot, including URI key aliases. + Map<String, String> raw = new HashMap<>(properties); + sourceKey = raw.keySet().stream().filter(key -> key.equalsIgnoreCase("uri")).findFirst().orElse(null); + if (sourceKey == null) { + return Map.of(); + } + String pathKey = firstNonblankKey(properties, List.of("use_path_style", "s3.path-style-access")); + String forceKey = firstNonblankKey(properties, List.of("force_parsing_by_standard_uri")); + endpoint = LegacyS3Uri.deriveEndpointQuietly(raw, + pathKey == null ? "false" : properties.get(pathKey).trim(), + forceKey == null ? "false" : properties.get(forceKey).trim()); + } + if (endpoint != null && !endpoint.toLowerCase(Locale.ROOT).contains("glue")) { + return Map.of(); + } + // Glue normalization infers a missing region before rewriting the S3 endpoint. Reuse the + // storage binder's inference and retain the original peer for callers that also contact Glue. + String region = regionKey == null + ? (endpoint == null ? "" : s3RegionFromEndpoint(endpoint).orElse("")) + : properties.get(regionKey).trim(); + if (region.isEmpty()) { + return Map.of(); + } + if (!region.matches("[A-Za-z0-9-]+")) { + throw new IllegalArgumentException("S3 region must be a literal hostname component"); + } + String serviceEndpoint = s3EndpointForRegion(region); + if (regionKey != null) { + return Map.of(regionKey, List.of(serviceEndpoint)); + } + String source = properties.get(sourceKey); + String normalized = source.trim().toLowerCase(Locale.ROOT); + // An S3 URI is a resource locator; its rewritten endpoint is the socket peer. An HTTP URI + // can also name the catalog service, so retain that independently checked original peer. + boolean originalPeer = endpointKey != null || normalized.startsWith("http://") + || normalized.startsWith("https://"); + return Map.of(sourceKey, originalPeer ? List.of(source, serviceEndpoint) : List.of(serviceEndpoint)); + } + + public static String s3EndpointForRegion(String region) { + return "https://s3." + region + ".amazonaws.com"; + } + + public static Optional<String> s3RegionFromEndpoint(String endpoint) { + String lowerEndpoint = endpoint.toLowerCase(Locale.ROOT); + for (Pattern pattern : S3_ENDPOINT_PATTERNS) { + Matcher matcher = pattern.matcher(lowerEndpoint); + if (matcher.matches()) { + for (int i = 1; i <= matcher.groupCount(); i++) { + String group = matcher.group(i); + if (group != null && !group.isBlank()) { + return Optional.of(group); + } + } + } + } + return Optional.empty(); + } + + private static String firstNonblankKey(Map<String, String> properties, List<String> aliases) { + for (String key : aliases) { + String value = properties.get(key); + if (value != null && !value.isBlank()) { + return key; + } + } + return null; + } + + /** + * Shared aliases can reach different SDKs; require an explicit scheme or port instead of guessing it. + * @throws IllegalArgumentException if a proxy route cannot be established from independent endpoint values + */ + public static Map<String, Integer> endpoints(Map<String, String> properties, Predicate<String> opaqueCredential) { + Map<String, Integer> endpoints = new LinkedHashMap<>(); + // OSS-HDFS prefers its specific alias over oss.endpoint before emitting fs.oss.endpoint. + for (String key : new String[] {"s3.endpoint", "AWS_ENDPOINT", "endpoint", "ENDPOINT", "aws.endpoint", + "glue.endpoint", "aws.glue.endpoint", "oss.endpoint", "oss.hdfs.endpoint", "OSS_ENDPOINT", + "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint", "cos.endpoint", "COS_ENDPOINT", + "obs.endpoint", "OBS_ENDPOINT", "azure.endpoint", "AZURE_ENDPOINT", "azure.oauth2_server_uri", + "azure.oauth2_account_host", "gs.endpoint", "minio.endpoint", "ozone.endpoint", "fs.s3a.endpoint", + "fs.gs.proxy.address"}) { + if (properties.containsKey(key)) { + endpoints.put(key, -1); + } + } + // ABFS OAuth always uses HTTPS; this value is a hostname also used in Hadoop property keys. + if (properties.containsKey("azure.oauth2_account_host")) { + endpoints.put("azure.oauth2_account_host", 443); + } + // Hadoop passes through new client options. Keep URI-valued token and service endpoints covered + // even when a dependency adds an option that Doris does not bind itself yet. + properties.forEach((key, value) -> { + String trimmed = value == null ? "" : value.trim(); + String normalized = trimmed.toLowerCase(Locale.ROOT); + String lowerKey = key.toLowerCase(Locale.ROOT); + boolean endpointName = lowerKey.endsWith(".url") || lowerKey.endsWith(".uri") + || lowerKey.endsWith(".endpoint"); + String storageKey = hadoopStorageKey(key); + // Bucket options and aliases can replace a filesystem proxy tuple after endpoint checking. + // Until those routes are modeled together, reject configured proxy hosts before any probe. + if (!trimmed.isEmpty() && (storageKey.equals("fs.s3a.proxy.host") || storageKey.equals("fs.obs.proxy.host") + || ((storageKey.startsWith("fs.s3a.bucket.") || storageKey.startsWith("fs.obs.bucket.")) + && storageKey.endsWith(".proxy.host")))) { + throw new IllegalArgumentException("Unsupported filesystem proxy routing"); + } + boolean storageOption = storageKey.startsWith("fs.") || storageKey.startsWith("dfs.") + || storageKey.startsWith("hadoop."); + boolean opaqueValue = opaqueCredential.test(storageKey) + || (!storageKey.equals(key) && opaqueCredential.test(key)) + || storageKey.endsWith(".proxy.username") || storageKey.endsWith(".access-key") + || storageKey.endsWith(".secret-key") || storageKey.endsWith(".session-token"); + boolean warehouse = key.equals("warehouse") || key.endsWith(".warehouse") + || key.equals("hive.metastore.warehouse.dir"); + if ((storageOption + // URL-shaped passwords stay opaque; explicit aliases and endpoint names still win. + && (endpointName || (!opaqueValue + && (normalized.startsWith("http://") || normalized.startsWith("https://"))))) + || (warehouse + && (normalized.startsWith("http://") || normalized.startsWith("https://")))) { + endpoints.put(key, -1); + } + // Paimon HMS eagerly opens its warehouse, including an inherited Hadoop default filesystem. + // Keep HDFS separate so admission can expand logical HA nameservices to physical RPC nodes. + // A preferred storage alias can replace fs.defaultFS during binding; retain every raw candidate. + boolean defaultFilesystem = key.equals("fs.defaultFS") || key.equals("fs.default.name") + || key.equals("oss.hdfs.fs.defaultFS"); + // HTTP HA/redirects, mount tables, FTP and archive delegates are not HDFS RPC routes modeled below. + if ((warehouse || defaultFilesystem || (storageOption && (endpointName || !opaqueValue))) + && (normalized.startsWith("webhdfs:") || normalized.startsWith("swebhdfs:") + || normalized.startsWith("viewfs:") || normalized.startsWith("ftp:") + || normalized.startsWith("har:"))) { + throw new IllegalArgumentException("Unsupported filesystem transport routing"); + } + // Interpolation can supply the scheme itself, so these known storage keys must enter + // literal validation even when their raw value does not yet start with a network scheme. + if ((warehouse || defaultFilesystem) && trimmed.contains("${")) { + endpoints.put(key, -1); + } + // Hadoop's lowercase "local" sentinel is special; other bare values are HDFS hostnames. + if (((warehouse || defaultFilesystem || (storageOption && (endpointName || !opaqueValue))) Review Comment: Addressed in ed62825c9aa. HDFS-valued legacy uri/URI fallback now enters the same filesystem default-port and inline-HA expansion path as fs.defaultFS when no canonical default is bound. It uses the physical filesystem default port 8020 while retaining separate metadata semantics. Tests cover canonical suppression, logical HA nodes and CREATE/ALTER. Validation: 137 selected test classes / 2460 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 376 expected policy refusals with positive CREATE/ALTER controls. ########## fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java: ########## @@ -0,0 +1,388 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.connector; + +import org.apache.doris.cloud.security.SecurityChecker; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.util.DatasourcePrintableMap; +import org.apache.doris.common.util.DebugPointUtil; +import org.apache.doris.common.util.DebugPointUtil.DebugPoint; +import org.apache.doris.connector.spi.ConnectorSecuritySurface; +import org.apache.doris.filesystem.properties.HdfsEndpointProperties; +import org.apache.doris.filesystem.properties.StorageEndpointProperties; + +import com.google.common.net.HostAndPort; +import com.google.common.net.InetAddresses; +import okhttp3.HttpUrl; + +import java.net.IDN; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** Shared endpoint admission for root and indirectly created catalog connectors. */ +public final class CatalogEndpointSecurity { + private static final String REJECT_HOST_POINT = "CatalogEndpointSecurity.reject_host"; + + private CatalogEndpointSecurity() { + } + + public static boolean isEnabled() { + return SecurityChecker.getInstance().isEnabled() || DebugPointUtil.isEnable(REJECT_HOST_POINT); + } + + public static void validate(String catalogName, ConnectorSecuritySurface surface, Map<String, String> properties) + throws DdlException { + SecurityChecker checker = SecurityChecker.getInstance(); + DebugPoint rejection = DebugPointUtil.getDebugPoint(REJECT_HOST_POINT); + if (!checker.isEnabled() && rejection == null) { + return; + } + Map<String, Integer> storageEndpoints; + Map<String, List<String>> derivedStorageEndpoints; + try { + storageEndpoints = StorageEndpointProperties.endpoints(properties, DatasourcePrintableMap::isSensitiveKey); + derivedStorageEndpoints = StorageEndpointProperties.derivedEndpointValues(properties); + } catch (IllegalArgumentException e) { + // Storage routing can fail before URI parsing; never expose credential-bearing option values. + throw new DdlException("Cannot validate shared storage routing against the SSRF policy"); + } + Map<String, Integer> endpoints = new LinkedHashMap<>(storageEndpoints); + derivedStorageEndpoints.keySet().forEach(key -> endpoints.putIfAbsent(key, -1)); + for (String key : surface.ssrfEndpointKeys(properties)) { + int defaultPort = surface.ssrfEndpointDefaultPort(key); + endpoints.put(key, defaultPort < 0 ? endpoints.getOrDefault(key, -1) : defaultPort); + } + // Driver downloads can connect during pre-validation, before a connector's connectivity test. + String flavor = surface.jdbcDriverUrlFlavorKey(); + String flavorValue = flavor == null ? "jdbc" : properties.getOrDefault(flavor, "").trim(); + if ("jdbc".equalsIgnoreCase(flavorValue)) { + for (String key : surface.jdbcDriverUrlKeys()) { + String value = properties.getOrDefault(key, "").trim().toLowerCase(Locale.ROOT); + if (value.startsWith("http://") || value.startsWith("https://")) { + endpoints.put(key, -1); + } + } + } + // Validate every candidate on ALTER: a flavor/authentication change can activate a stored address + // without modifying its key. Replays never enter this statement-time path. + Map<String, List<HostAndPort>> parsedEndpoints = new LinkedHashMap<>(); + for (Map.Entry<String, Integer> entry : endpoints.entrySet()) { + String key = entry.getKey(); + String value = properties.get(key); + List<HostAndPort> destinations; + try { + destinations = new ArrayList<>(); + List<String> values = derivedStorageEndpoints.containsKey(key) + ? derivedStorageEndpoints.get(key) : surface.ssrfEndpointValues(key, value); + for (String endpoint : values) { + // A provider can derive destinations even when this raw property is absent. + if (endpoint == null || endpoint.trim().isEmpty()) { + continue; + } + if (endpoint.contains("${")) { + throw new DdlException("Endpoint property '" + key + "' must be literal under the SSRF policy; " + + "a placeholder can change its destination after validation"); + } + if (storageEndpoints.getOrDefault(key, -1) == 8020) { + for (String authority : HdfsEndpointProperties.authorities(endpoint.trim(), properties)) { + destinations.add(parseAuthority(authority, 8020)); + } + } else { + destinations.addAll(parseEndpoints(endpoint.trim(), entry.getValue())); + } + } + } catch (IllegalArgumentException e) { + // Do not echo URLs: their authority or query can carry credentials. + throw new DdlException("Cannot validate endpoint property '" + key + "' of catalog '" + + catalogName + "' against the SSRF policy: use an explicit network URI or host:port"); + } + parsedEndpoints.put(key, destinations); + } + int rejectedPort = rejection == null ? -1 : rejection.param("port", -1); + for (Map.Entry<String, List<HostAndPort>> entry : parsedEndpoints.entrySet()) { + String key = entry.getKey(); + for (HostAndPort destination : entry.getValue()) { + // A fail-only seam lets SQL regression tests exercise routing without the optional SDK. + // It cannot bypass a real policy rejection or allow a connection. + // Optional port matching distinguishes peers on one host; every real checker call remains below. + if (rejection != null && destination.getHost().equals(rejection.param("host", "127.0.0.1")) + && (rejectedPort < 0 || destination.getPort() == rejectedPort)) { + throw new DdlException("Endpoint property '" + key + "' is rejected by the SSRF policy"); + } + checker.checkEndpointForSsrf(destination.getHost(), destination.getPort()); + } + } + } + + /** Parses URI lists, multi-host authorities and scheme-less endpoints without splitting URL path commas. */ + public static List<HostAndPort> parseEndpoints(String value, int defaultPort) { + String normalized = value.trim(); + List<HostAndPort> result = parseUnnormalizedEndpoints(normalized, defaultPort); + if (normalized.regionMatches(true, 0, "jdbc:", 0, 5) && normalized.contains(" ")) { + // Standalone JDBC strips spaces; Paimon and Iceberg pass the raw URL to their drivers. + // Checking both interpretations prevents normalization from hiding an active host override. + LinkedHashSet<HostAndPort> destinations = new LinkedHashSet<>(result); + destinations.addAll(parseUnnormalizedEndpoints(normalized.replace(" ", ""), defaultPort)); + return new ArrayList<>(destinations); + } + return result; + } + + private static List<HostAndPort> parseUnnormalizedEndpoints(String normalized, int defaultPort) { + List<HostAndPort> result = new ArrayList<>(); + // An SRV seed is a discovery name, not a server at MongoDB's ordinary default port. + // Until discovery peers are modeled, require literal mongodb:// authorities under enforcement. + if (normalized.startsWith("mongodb+srv://")) { + throw new IllegalArgumentException("Unsupported MongoDB SRV discovery routing"); + } + if (normalized.startsWith("mongodb://")) { + int authorityEnd = normalized.indexOf('/', "mongodb://".length()); + authorityEnd = authorityEnd < 0 ? normalized.length() : authorityEnd; + int query = normalized.indexOf('?'); + if (query >= 0) { + authorityEnd = Math.min(authorityEnd, query); + } + // MongoDB treats '#' in userinfo as ordinary bytes; Java URI ends its authority there. + // Reject that disagreement before either the database or proxy endpoint is probed. + int fragment = normalized.indexOf('#'); + if (fragment >= 0 && fragment < authorityEnd) { + throw new IllegalArgumentException("Ambiguous MongoDB URI authority"); + } + parseSingle(normalized, defaultPort, result); + addMongoProxy(normalized, result); + return result; + } + // JDBC-specific parameters and Oracle descriptors are not ordinary URI authorities. + if (normalized.regionMatches(true, 0, "jdbc:mysql:", 0, 11) + || normalized.regionMatches(true, 0, "jdbc:mysql+srv:", 0, 15)) { + return JdbcEndpointParser.mysql(normalized); + } + if (normalized.startsWith("jdbc:mariadb:")) { + return JdbcEndpointParser.mariaDb(normalized); + } + if (normalized.startsWith("jdbc:oceanbase:")) { + return JdbcEndpointParser.oceanbase(normalized); + } + if (normalized.startsWith("jdbc:postgresql:")) { + return JdbcEndpointParser.postgresql(normalized); + } + if (normalized.startsWith("jdbc:sqlserver://")) { + return JdbcEndpointParser.sqlServer(normalized); + } + if (normalized.startsWith("jdbc:oracle:thin:")) { + return JdbcEndpointParser.oracle(normalized); + } + if (normalized.startsWith("jdbc:clickhouse:") || normalized.startsWith("jdbc:ch:")) { + return JdbcEndpointParser.clickhouse(normalized); + } + if (normalized.startsWith("jdbc:trino:") || normalized.startsWith("jdbc:presto:")) { + return JdbcEndpointParser.trinoOrPresto(normalized); + } + if (normalized.startsWith("jdbc:sap:")) { + return JdbcEndpointParser.sap(normalized); + } + if (normalized.startsWith("jdbc:db2:") || normalized.startsWith("jdbc:ibmdb:") + || normalized.startsWith("jdbc:ids:") || normalized.startsWith("jdbc:informix-sqli:") + || normalized.startsWith("jdbc:db2os390:") || normalized.startsWith("jdbc:db2os390sqlj:")) { + return JdbcEndpointParser.db2(normalized); + } + if (normalized.startsWith("postgresql://") || normalized.startsWith("postgres://")) { + validateNativePostgresql(normalized); + parseSingle(normalized, defaultPort, result); + return result; + } + if (normalized.startsWith("jdbc:")) { + normalized = normalized.substring(5); + } + for (String endpoint : normalized.split(",(?=\\s*[A-Za-z][A-Za-z0-9+.-]*://)", -1)) { + parseSingle(endpoint.trim(), defaultPort, result); + } + return result; + } + + private static void addMongoProxy(String uri, List<HostAndPort> result) { + int query = uri.indexOf('?'); + if (query < 0) { + return; + } + Map<String, String> proxy = new LinkedHashMap<>(); + for (String part : uri.substring(query + 1).split("[&;]")) { + String[] pair = part.split("=", 2); + String key = pair[0].toLowerCase(Locale.ROOT); + if (key.equals("proxyhost") || key.equals("proxyport") + || key.equals("proxyusername") || key.equals("proxypassword")) { + // The driver rejects every repeated proxy option and decodes values exactly once. + if (pair.length != 2 || proxy.containsKey(key)) { + throw new IllegalArgumentException("Ambiguous MongoDB proxy routing"); + } + proxy.put(key, URLDecoder.decode(pair[1], StandardCharsets.UTF_8)); + } + } + if (proxy.isEmpty()) { + return; + } + String host = proxy.get("proxyhost"); + if (host == null || host.isBlank()) { + throw new IllegalArgumentException("MongoDB proxy requires a literal host"); + } + // MongoDB ProxySettings uses 1080 when the URI omits proxyPort; authentication stays opaque. + int port = Integer.parseInt(proxy.getOrDefault("proxyport", "1080")); + result.add(parseAuthority(HostAndPort.fromParts(host, port).toString(), -1)); + } + + private static void validateNativePostgresql(String value) { + int start = value.indexOf("://") + 3; + int slash = value.indexOf('/', start); + int query = value.indexOf('?', start); + int at = value.indexOf('@', start); + int authorityEnd = slash < 0 ? value.length() : slash; + if (query >= 0) { + authorityEnd = Math.min(authorityEnd, query); + } + int secondAt = at < 0 ? -1 : value.indexOf('@', at + 1); + // libpq has no fragment syntax and scans userinfo up to the first slash, even across '?'. + // Reject structures whose destination differs from Java URI authority parsing. + if (value.indexOf('#') >= 0 || (at >= 0 && query >= 0 && query < at && (slash < 0 || at < slash)) + || (at >= 0 && at < authorityEnd && secondAt >= 0 && secondAt < authorityEnd)) { + throw new IllegalArgumentException("Ambiguous native PostgreSQL URI"); + } + if (query >= 0) { + for (String token : value.substring(query + 1).split("&")) { + String rawKey = token.split("=", 2)[0]; + // libpq percent-decodes keys once and preserves literal plus signs. + String key = URLDecoder.decode(rawKey.replace("+", "%2B"), StandardCharsets.UTF_8); + if (key.equals("host") || key.equals("hostaddr") || key.equals("port") || key.equals("service")) { + throw new IllegalArgumentException("Native PostgreSQL routing requires literal URI authorities"); + } + } + } + } + + private static void parseSingle(String endpoint, int defaultPort, List<HostAndPort> result) { + if (endpoint.isEmpty()) { + throw new IllegalArgumentException("Empty endpoint"); + } + if (endpoint.regionMatches(true, 0, "file:", 0, 5)) { + try { + URI local = new URI(endpoint); + String authority = local.getRawAuthority(); + if (local.isOpaque() || (authority != null && !authority.isEmpty() + && !"localhost".equalsIgnoreCase(authority))) { + throw new IllegalArgumentException("Remote or opaque file URI"); + } + return; + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid local file URI"); + } + } + // DLF's scheme-less endpoints use URL authority semantics, including userinfo and suffixes. + if ((defaultPort == 80 || defaultPort == 443) + && !endpoint.matches("[A-Za-z][A-Za-z0-9+.-]*://.*")) { + endpoint = (defaultPort == 80 ? "http://" : "https://") + endpoint; + } + if (!endpoint.contains("://")) { + String authority = endpoint.split("/", 2)[0]; + for (String host : authority.split(",", -1)) { + result.add(parseAuthority(host.trim(), defaultPort)); + } + return; + } + URI uri; + try { + uri = new URI(endpoint); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid endpoint URI"); + } + String scheme = uri.getScheme().toLowerCase(Locale.ROOT); Review Comment: Addressed in ed62825c9aa. Endpoint parsing now requires a scheme and authority before lowercasing the scheme, so relative values containing :// return the sanitized per-property DdlException. Recording tests verify the error and ensure parsing finishes before any endpoint probe. Validation: 137 selected test classes / 2460 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 376 expected policy refusals with positive CREATE/ALTER controls. -- 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]
