Bug 62383 - HttpParser.DomainParserState fails valid hostname gateway.demo-ilt-latest-demo:9000
Summary: HttpParser.DomainParserState fails valid hostname gateway.demo-ilt-latest-dem...
Status: RESOLVED DUPLICATE of bug 62371
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Util (show other bugs)
Version: 8.5.31
Hardware: All All
: P2 major (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-18 01:03 UTC by Abhijit Sarkar
Modified: 2018-05-18 23:52 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abhijit Sarkar 2018-05-18 01:03:58 UTC
We recently upgraded to Tomcat 8.5.31 and found that it's rejecting the hostname gateway.demo-ilt-latest-demo:9000 with the following message:
 
The character [:] is not valid after a letter in a domain name.

I traced the code on GitHub to https://github.com/apache/tomcat/blob/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java#L875

Looking at the history of this file, it appears that there have been quite a few problems with the hostname verification. I'd like to know why the above hostname is considered invalid. FWIW, name gateway.demo-ilt-latest-demo.svc.cluster.local works.
Comment 1 Mark Thomas 2018-05-18 06:05:47 UTC
The short answer is because of this text from RFC 1123:
<quote>
However, a valid host name can never have the dotted-decimal form #.#.#.#, since at least the highest-level component label will be alphabetic.
</quote>

However, there is some interesting discussion of this in the errata. For a full discussion of how this relates to Tomcat, see the duplicate. The summary of that discussion is that '-' should be allowed in the final segment and the parsing has been updated to permit this.

*** This bug has been marked as a duplicate of bug 62371 ***
Comment 2 Michael Osipov 2018-05-18 07:53:13 UTC
(In reply to Abhijit Sarkar from comment #0)

> FWIW, name gateway.demo-ilt-latest-demo.svc.cluster.local works.

It shouldn't because .local is reseved for link-local mDNS (Avahi, zeroconf, etc.). The are no subdomains. I refused to merge something like this to Commons Validator.
Comment 3 Abhijit Sarkar 2018-05-18 09:13:20 UTC
(In reply to Mark Thomas from comment #1)
> However, a valid host name can never have the dotted-decimal form #.#.#.#,

62371 appears to be about hyphen in the hostname, whereas my problem is the colon. Clearly, the hostname verifier is getting greedy and trying to parse what's really not the hostname. If you insist, please point me the section in the RFC that says port can't be part of a URL.
Comment 4 Mark Thomas 2018-05-18 09:50:10 UTC
It is the same problem and the problem has been fixed.

The parser complains about the ':' because it sees the '-' in the final segment and therefore expects a '.' followed by a purely alphabetic segment. Rather than the alphabetic segment, it sees the ':' and complains.

To prove the point I've added a test case for this example and it passes.

*** This bug has been marked as a duplicate of bug 62371 ***
Comment 5 Abhijit Sarkar 2018-05-18 16:49:02 UTC
(In reply to Mark Thomas from comment #4)
> It is the same problem and the problem has been fixed.

Let me try again because what I was saying didn't get across. The port is *not* part of the hostname. Since hyphen is allowed in the last segment of a hostname, a.b-c is a valid hostname: You add a valid port to it and get a valid URI; where is the problem with that?

The parser should only validate what's on the left of the last ':', if any.
Comment 6 Abhijit Sarkar 2018-05-18 20:17:36 UTC
Reopening to draw attention to my last comment, which is "port is not part of the hostname". Any argument that applies to hostname validation doesn't apply to port.
Comment 7 Mark Thomas 2018-05-18 20:32:03 UTC
This has been fixed. It is a duplicate of 62371.

Please re-read comment #4. It explains why Tomcat was incorrectly complaining about the ':' and why the problem you are reporting is a duplicate. If comment #4 is not sufficiently clear, please follow-up on the users mailing list.

If you continue to re-open this issue your bugzilla account will be disabled.

*** This bug has been marked as a duplicate of bug 62371 ***
Comment 8 Abhijit Sarkar 2018-05-18 23:52:22 UTC
(In reply to Mark Thomas from comment #7)
> If you continue to re-open this issue your bugzilla account will be disabled.

If you don't continue to close it without waiting for my response, I won't need to reopen it. The mailing list is a 2-way street; threatening to use your admin privileges is a cheap gimmick.