Skip to content

IPv6 host names are not checked for brackets when using HttpRequest with ServletCall #959

Open
@Maia-Everett

Description

@Maia-Everett

ServletCall.getHostDomain() simply returns the result of getServerName() from the HttpServletRequest without surrounding it with brackets.

Unfortunately, in combination with the HttpClient constructor, this results in cases where hostRef contains a malformed URL, since the hostRef URL is assembled by using StringBuilder (why?!) with everything concatenated without escaping.

This causes issues with Jetty 9 servlets and ServletAdapter, since HttpServletRequest.getServerName() there returns IPv6 addresses without any escaping.

For example, when accessing

http://[::1]:8888/api-path

references in HttpClient are actually set to

http://::1:8888/api-path

and later attempts to parse the URL fail with:

Can't parse hostPort : [hostRef,requestUri]=[null,http://::1:8888/api-path]

This can be fixed by changing either HttpClient or ServletCall to check for unbracketed IPv6 addresses and bracket them as necessary. I'm not sure which is the right way (the right right way, of course, being using java.net.URI for assembling URLs, and not that StringBuilder hack, but I assume you had reasons to do it this way). I'll make a pull request with ServletCall changed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions