Skip to content

Fix ambiguous IPv6 address in db.connection_string for MySQL/MariaDB#19078

Merged
trask merged 1 commit into
open-telemetry:mainfrom
bhuvan-somisetty:fix/ipv6-shorturl-brackets
Jun 26, 2026
Merged

Fix ambiguous IPv6 address in db.connection_string for MySQL/MariaDB#19078
trask merged 1 commit into
open-telemetry:mainfrom
bhuvan-somisetty:fix/ipv6-shorturl-brackets

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

Fixes #1421

Problem

When a JDBC URL contains a bracketed IPv6 host — for example:

jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdb

the db.connection_string attribute was produced 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. 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:

mysql:failover://::1:3306     ← ambiguous
mariadb:failover://::1:3306   ← ambiguous

Fix

The root cause is in UrlParsingUtils.buildShortUrl. The MySQL/MariaDB parser strips brackets when storing the host (keeping just the raw IPv6 literal), but buildShortUrl appended 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:

if (host.contains(":") && !host.startsWith("[")) {
    url.append('[');
    url.append(host);
    url.append(']');
} else {
    url.append(host);
}

Hosts that already carry brackets (e.g. SQL Server, which routes through extractHostPort and preserves them) are left untouched.

After the fix

Input URL Before After
jdbc:mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33,mdb.host/mdbdb mariadb:loadbalance://2001:0660:7401:0200:0000:0000:0edf:bdd7:33 mariadb:loadbalance://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:33
jdbc:mysql:failover://[::1]:3306 mysql:failover://::1:3306 mysql:failover://[::1]:3306
jdbc:mariadb:failover://[::1]:3306 mariadb:failover://::1:3306 mariadb:failover://[::1]:3306

Changes

  • UrlParsingUtils.java — wrap bare IPv6 literals in brackets inside buildShortUrl
  • JdbcConnectionUrlParserTest.java — update three test expectations to match the corrected (RFC-compliant) output

Copilot AI review requested due to automatic review settings June 25, 2026 16:09
@bhuvan-somisetty
bhuvan-somisetty requested a review from a team as a code owner June 25, 2026 16:09
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: bhuvan-somisetty / name: Bhuvan Somisetty (b316c5f)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (MysqlUrlParser strips them at lines 157-161), so the new branch brackets them.
  • MSSQL routes through extractHostPort, which already brackets IPv6 hosts, and GenericUrlParser uses URI.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 [) inside UrlParsingUtils.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.

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/ipv6-shorturl-brackets branch from 7bf4e05 to 7e3b82e Compare June 25, 2026 16:19
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
@trask
trask merged commit d8c4e3c into open-telemetry:main Jun 26, 2026
97 checks passed
@otelbot

otelbot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JDBCCOnnectionURLParser creates ambiguous IPv6 address for shortUrl

4 participants