Repository navigation
fix(bigquery-jdbc): add single-pass URL parser, remove PARSE_CACHE, and validate property keys - #15289
Conversation
…nd validate property keys
There was a problem hiding this comment.
Code Review
This pull request refactors the BigQuery JDBC connection URL parsing logic to improve security and robustness. It removes the static PARSE_CACHE to prevent retaining plaintext credentials in memory and introduces a two-phase, non-throwing parser via the ParsedConnectionUrl class. Additionally, it adds validation to reject invalid property keys (containing delimiters, control characters, or duplicates) and registers several new safe-to-log properties. The review feedback highlights two opportunities to strengthen validation: first, by treating whitespace-only keys in URL segments as malformed rather than unknown, and second, by trimming keys in parsePropertiesMapFromValue before performing duplicate checks to prevent whitespace-based bypasses.
| String entryKey = keyValueParts.get(0); | ||
| if (entryKey.trim().isEmpty()) { |
There was a problem hiding this comment.
Trimming the entryKey directly ensures that any leading or trailing whitespace is removed before performing the duplicate key check (propertiesMap.containsKey(entryKey)). Otherwise, keys like key1 and key1 would bypass the duplicate check but might be treated as the same key by consumers, leading to unexpected behavior.
| String entryKey = keyValueParts.get(0); | |
| if (entryKey.trim().isEmpty()) { | |
| String entryKey = keyValueParts.get(0).trim(); | |
| if (entryKey.isEmpty()) { |
…L/PartnerToken/map parsing
…id Properties keys Address review feedback on #15289: DatabaseMetaData display URL now returns only the caller's connection endpoint, validatePropertyKey is renamed to extractValidPropertyKey and rejects non-String keys, and keys that are blank, padded, or contain ';', '=', or control characters are ignored with a warning instead of failing the connection.
logachev
left a comment
There was a problem hiding this comment.
Please update PR description to reflect latest changes
Stack: PR 1 of 3 (base:
main)Bug: b/584839495, b/584839379, b/584840529
Summary
Introduces the lock-free, two-phase single-pass URL parser (
ParsedConnectionUrl/parseConnectionUrl), removes the staticPARSE_CACHE, adds endpoint-only display URL sanitization (sanitizeUrlForDisplay), ignoresPropertieskeys that could inject delimiters or control characters (extractValidPropertyKey), and hardensparsePropertiesMapFromValue.What Changed & Why
PARSE_CACHE(b/584839495): Eliminates cross-connection heap retention of plaintext credential-bearing URLs and removes globalCollections.synchronizedMaplock contention during concurrent connect bursts.Locale.ROOTacross allPROPERTY_NAME_MAPinitialization andparseUriProperty()lookups so property canonicalization works identically under non-English default locales (e.g., Turkishtr_TR).ParsedConnectionUrl(b/584839495,b/584840728):EnableDiagnosticTelemetry,LogLevel,LogPath,enableGcpLogExporter) using last-wins semantics without throwing before logging opens.=) and invalid percent-encoding using 1-based segment indices only (never echoing raw secret slices) and logs sanitized unknown keys.sanitizeUrlForDisplay()(b/584839495): Returns only the caller's normalized connection endpoint (for examplejdbc:bigquery://https://www.googleapis.com/bigquery/v2:443) and never any connection properties. Prefixes containing=,?, or@collapse tojdbc:bigquery:. The caller's host is kept so PSC and custom-universe connections stay identifiable.SAFE_TO_LOG_PROPERTIES: AddsBigQueryConnection.isSafeToLogProperty(String)and 6 non-secret properties (SSLTrustStoreType,SSLTrustStoreProvider,gcpTelemetryProjectId,enableGcpTraceExporter,enableGcpLogExporter,useGlobalOpenTelemetry) to the log-masking allowlist, with an exhaustive classification unit test covering every key inPROPERTY_NAME_MAP.PartnerTokendecoding (formatPartnerTokenHeaderValue): Decodes percent-escapes once, insideparseConnectionUrl(), so URL tokens are never double-decoded and discreteProperties/DataSourcetokens preserve literal%xxsequences; rejects control characters before formatting into theuser-agentheader.b/584839379,b/584840529):extractValidPropertyKey()returnsnullfor keys that are blank, have leading/trailing whitespace, or contain;,=, or control characters; callers skip them and log a warning that does not echo the key.BigQueryJdbcRuntimeExceptioninstead of being converted withtoString()(Propertiesalready rejectsnullkeys).parsePropertiesMapFromValue()trims entry keys, rejects empty keys and exact duplicate keys (case-variantsession_idkeys still reach the existing case-insensitive check), and sanitizes warning logs.How It Was Tested
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 make lint— 0 reformatted.mvn -B -ntp clean test— Enforcer, Checkstyle (0 violations), Java 8animal-sniffer, and 1,471 unit tests (1 skipped, 0 errors; only the known pre-existing local failureBigQueryJdbcOAuthUtilityTest.testPrivateKeyFromP12Bytesloading/fake.p12).mvn clean testcompiles the integration test sources; they were not executed (live IT execution requiresGOOGLE_APPLICATION_CREDENTIALS).Stack Plan
PARSE_CACHEremoval, endpoint-only display URL, property key handling (base: main)DataSourcesnapshot/overlay and unified last-winsconnectpipeline (base: fix/g01-url-parsing-and-sanitization)DatabaseMetaData.getURL(),Driver.getPropertyInfo()redaction,toMaskedLogMap(), and legacy URL round-trip helper deletion (base: fix/g01-structured-connect-and-datasource-overrides)