Skip to content

fix(core): support hostnames whose last label starts with a digit - #13144

Open
siddiqueirshad wants to merge 1 commit into
grpc:masterfrom
siddiqueirshad:fix/support-hostnames-starting-with-digit
Open

siddiqueirshad wants to merge 1 commit into
grpc:masterfrom
siddiqueirshad:fix/support-hostnames-starting-with-digit

Conversation

@siddiqueirshad

Copy link
Copy Markdown

Description of changes

Fixes #13075.

In DnsNameResolver and GrpcUtil.authorityFromHostAndPort, hostnames were previously validated and parsed exclusively via java.net.URI.

Because java.net.URI follows RFC 2396 grammar, where the top-level label of a hostname is constrained to begin with an alphabetic character (alpha), valid RFC 1123 hostnames whose last label starts with a digit (such as Kubernetes service endpoints like otlp.1234-k8s-namespace) result in:

  1. nameUri.getHost() returning null in DnsNameResolver, causing IllegalArgumentException: Invalid DNS name.
  2. new URI(null, null, host, port, null, null, null) throwing URISyntaxException in GrpcUtil.authorityFromHostAndPort, causing IllegalArgumentException: Invalid host or port.

Fix

  1. In DnsNameResolver: When nameUri.getHost() is null, fall back to parsing host and port from nameUri.getAuthority().
  2. In GrpcUtil.authorityFromHostAndPort: When new URI(null, null, host, port, null, null, null) throws URISyntaxException, combine host (IPv6-bracketed if necessary) and port into an authority string and validate it through checkAuthority().
  3. Added unit tests in DnsNameResolverProviderTest and GrpcUtilTest.

Fixes #13075

In DnsNameResolver and GrpcUtil.authorityFromHostAndPort, hostnames were validated and parsed via java.net.URI. Because java.net.URI implements RFC 2396 grammar where the toplabel of a hostname must begin with an alphabetic character (JDK-8188305), valid RFC 1123 hostnames whose last label starts with a digit (e.g. Kubernetes services in namespaces like otlp.1234-k8s-namespace) resulted in URI.getHost() returning null and URI constructors throwing URISyntaxException.

This change:
1. In DnsNameResolver, if nameUri.getHost() is null due to RFC 2396 restrictions, extracts host and port from nameUri.getAuthority().
2. In GrpcUtil.authorityFromHostAndPort, falls back to manual host/port concatenation validated through checkAuthority() when new URI(...) throws URISyntaxException.
3. Adds unit tests in DnsNameResolverProviderTest and GrpcUtilTest.

Fixes grpc#13075

Signed-off-by: siddiqui irshad <mohdirshad1306@gmail.com>
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

This branch has not been deployed

No deployments
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.

Hostnames whose last label starts with a digit are rejected (java.net.URI, JDK-8188305)

1 participant