Bug 52178 - IPv6 IPs as ServerName not allowed
Summary: IPv6 IPs as ServerName not allowed
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.4.37
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: MassUpdate, PatchAvailable
Depends on:
Reported: 2011-11-14 16:42 UTC by Rainer Canavan
Modified: 2018-11-08 11:48 UTC (History)
0 users

patch (search port after ] if one exists) (889 bytes, application/octet-stream)
2011-11-14 16:42 UTC, Rainer Canavan
updated patch (1.20 KB, patch)
2011-11-24 17:15 UTC, Rainer Canavan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Canavan 2011-11-14 16:42:53 UTC
Created attachment 27936 [details]
patch (search port after ] if one exists)

server/core.c:server_hostname_port() uses everything after the first ":" as a port and prevents startup if it is not in the range 1-65535. If a IPv6 IP is used as a ServerName, the result is bound to be invalid. The enclosed patch starts the search for a ":" after the first closing square bracket if one exists, otherwise it falls back to the current behavior.
Comment 1 Rainer Canavan 2011-11-24 17:15:35 UTC
Created attachment 27983 [details]
updated patch

Includes an additional modification to make IPv6-address based NameVirtualHosts work like IPv4 based vhosts.
Comment 2 William A. Rowe Jr. 2011-11-25 03:18:25 UTC
All IPv6 addresses must be disambiguated by [] notation... are you suggesting
that [::]:80 is not working correctly?
Comment 3 Rainer Canavan 2011-11-25 10:08:04 UTC
IPv6 Addresses in square brackets do work for Listen and VirtualHost statements, but not for ServerName. Aside from preventing the Server to start at all, a NameVirtualHosts with an IP as the ServerName will never match. Even with the patch, the server must not have a VirtualHost-Statement that matches the ServerName exactly (i.e. the VirtualHost should be *:80 or different due to NAT), just like it works for IPv4 Adresses now.

Servername [::]:80

results in

Syntax error on line 2 of /etc/httpd/conf.d/vhost0.conf:
The port number "[::]:80" is outside the appropriate range (i.e., 1..65535).
Comment 4 Christophe JAILLET 2013-10-09 04:51:29 UTC
According to doc, ServerName should be a fully-qualified-domain-name.

I don't see any use case that would require it to be an IP address.

Could you elaborate ?
Comment 5 Rainer Canavan 2014-04-01 10:02:22 UTC
I'm not sure if it is a realistic use case, since DNS entries are quick and easy to make, and IPv6 addresses are cumbersome in URLs, but my assumption was that NameVirtualHost should work for IPv6 as it does for IPv4. That is, one can run multiple VirtualHosts via NamevirtualHost on the same address:port, where one is identified by the address instead of a name. Since ServerName permits IPv4 addresses, it should also allow IPv6 addresses, or at least produce a clear error message and possibly also forbid IPv4 addresses. 

While the syntax in the documentation does specify [scheme://]fully-qualified-domain-name[:port], it is somewhat surprising to see something so "url-like" that only permits names, but not IP addresses for no obvious technical reason. 

I've only stumbled upon this issue while checking all aspects of IPv6 readiness of our product that I could come up with, by systematically trying everything with IPv6 that works with IPv4.
Comment 6 William A. Rowe Jr. 2018-11-07 21:09:01 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.
Comment 7 Rainer Canavan 2018-11-08 11:48:16 UTC
This issue is still present in 2.4.37, but with a slightly different error message:

AH00526: Syntax error on line 517 of /tmp/hh/conf/httpd.conf:
Invalid ServerName "[:::]:80" use ServerAlias to set multiple server names.