Fix ambiguous IPv6 address in db.connection_string for MySQL/MariaDB#19078
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an RFC violation where db.connection_string (the short URL) produced ambiguous IPv6 authorities for MySQL/MariaDB JDBC URLs. The MySQL/MariaDB parser stores the IPv6 literal without brackets (e.g. ::1, 2001:...), and buildShortUrl previously appended it verbatim, yielding mysql:failover://::1:3306, where the boundary between address and port is indistinguishable. The fix wraps bare IPv6 literals in square brackets so the output is RFC 3986/5952 compliant.
I verified the change is correctly scoped:
- MySQL/MariaDB store the host without brackets (
MysqlUrlParserstrips them at lines 157-161), so the new branch brackets them. - MSSQL routes through
extractHostPort, which already brackets IPv6 hosts, andGenericUrlParserusesURI.getHost()which returns the bracketed form — both start with[, so the!host.startsWith("[")guard correctly avoids double-bracketing. Existing SQL Server test expectations remain unchanged and consistent. - The
server.address/host attribute still keeps the raw unbracketed literal (only the connection string is affected), which is the desired behavior.
Changes:
- Bracket bare IPv6 literals (host contains
:and does not already start with[) insideUrlParsingUtils.buildShortUrl. - Update three test expectations (one MySQL, two MariaDB) to the corrected bracketed short URLs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/parser/UrlParsingUtils.java |
Adds bracket-wrapping for unbracketed IPv6 hosts in buildShortUrl, preserving already-bracketed hosts. |
instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java |
Updates three short-URL expectations to the RFC-compliant bracketed output. |
7bf4e05 to
7e3b82e
Compare
When a JDBC URL contains an IPv6 host (e.g. [::1] or a full address like [2001:0660:7401:0200:0000:0000:0edf:bdd7]), the db.connection_string attribute was emitted without brackets around the address: mariadb:loadbalance://2001:0660:7401:0200:0000:0000:0edf:bdd7:33 This makes it impossible to tell where the IPv6 address ends and the port begins, which is explicitly disallowed by RFC 5952 §6.6 and RFC 3986 §3.2.2. The fix wraps bare IPv6 literals in square brackets inside buildShortUrl, so the output becomes the unambiguous: mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33 Hosts that already carry brackets (e.g. SQL Server paths through extractHostPort) are left untouched. Fixes open-telemetry#1421
7e3b82e to
b316c5f
Compare
|
Thank you for your contribution @bhuvan-somisetty! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
Fixes #1421
Problem
When a JDBC URL contains a bracketed IPv6 host — for example:
the
db.connection_stringattribute was produced without brackets around the address:This makes it impossible to tell where the IPv6 address ends and the port begins — which is explicitly disallowed by RFC 5952 §6.6 and RFC 3986 §3.2.2. Both RFCs require IPv6 literals inside URL authority components to be enclosed in square brackets.
The same problem affected the compressed form (
::1) used in MySQL/MariaDB failover URLs:Fix
The root cause is in
UrlParsingUtils.buildShortUrl. The MySQL/MariaDB parser strips brackets when storing the host (keeping just the raw IPv6 literal), butbuildShortUrlappended it verbatim without re-adding brackets.The fix adds a check: if the host string contains a colon and does not already start with
[, it is wrapped in square brackets before being appended to the URL:Hosts that already carry brackets (e.g. SQL Server, which routes through
extractHostPortand preserves them) are left untouched.After the fix
jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdbmariadb:loadbalance://2001:0660:7401:0200:0000:0000:0edf:bdd7:33mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33jdbc:mysql:failover://[::1]:3306mysql:failover://::1:3306mysql:failover://[::1]:3306jdbc:mariadb:failover://[::1]:3306mariadb:failover://::1:3306mariadb:failover://[::1]:3306Changes
UrlParsingUtils.java— wrap bare IPv6 literals in brackets insidebuildShortUrlJdbcConnectionUrlParserTest.java— update three test expectations to match the corrected (RFC-compliant) output