# A bug when Host header contain IPv6 address

**URL:** <https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265>\
**Category:** NGINX\
**Created:** [August 31, 2011, 9:37am UTC](https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265 "2011-08-31T09:37:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 31, 2011, 9:37am UTC](https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265/1 "2011-08-31T09:37:46Z")

</div>

For a request with an IPv6 Host header like:

Host: Host: [2001:250:1800:1::88]

The function “ngx\_http\_validate\_host” will consider the trailing “:88]”  
as a port number and trim it. Therefore the value of  
“r-\>headers\_in.server” and “$host” will become:

[2001:250:1800:1:

Test (in Nginx - 1.1.1):  
Test config:

```
 listen [::]:80
 location / {
       add_header MYHEADER $host;
       return 200;
 }

Test input:

```

telnet 2001:250:1800:1::88  
Trying 2001:250:1800:1::88…  
Connected to 2001:250:1800:1::88.  
Escape character is ‘^]’.  
GET / HTTP/1.0  
Host: [2001:250:1800:1::88]

```
Test output:

```

HTTP/1.1 200 OK  
Server: nginx/1.0.3  
Date: Wed, 24 Aug 2011 12:11:07 GMT  
Content-Type: application/octet-stream  
Content-Length: 0  
Connection: close  
MYHEADER: [2001:250:1800:1:

Posted at Nginx Forum:

> **[A bug when Host header contain IPv6 address](https://forum.nginx.org/read.php?2,214541,214541#msg-214541)**
>
> For a request with an IPv6 Host header like: Host: Host: \[2001:250:1800:1::88\] The function "ngx\_http\_validate\_host" will consider the trailing ":88\]" as a port number and trim it. Therefore the value of...

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [August 31, 2011, 9:49am UTC](https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265/2 "2011-08-31T09:49:30Z")

</div>

A patch has been submitted in nginx-devel maillist, please review. After  
the fix, the test result is:

telnet 2001:250:1800:1::88  
Trying 2001:250:1800:1::88…  
Connected to 2001:250:1800:1::88.  
Escape character is ‘^]’.  
GET / HTTP/1.0  
Host: [2001:250:1800:1::88]

HTTP/1.1 200 OK  
Server: nginx/1.1.1  
Date: Wed, 24 Aug 2011 12:26:00 GMT  
Content-Type: application/octet-stream  
Content-Length: 0  
Connection: close  
MYHEADER: [2001:250:1800:1::88]

Posted at Nginx Forum:

> **[Re: A bug when Host header contain IPv6 address](https://forum.nginx.org/read.php?2,214541,214543#msg-214543)**
>
> For a request with an IPv6 Host header like: Host: Host: \[2001:250:1800:1::88\] The function "ngx\_http\_validate\_host" will consider the trailing ":88\]" as a port number and trim it. Therefore the value of...

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [August 31, 2011, 11:08am UTC](https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265/3 "2011-08-31T11:08:38Z")

</div>

Hello!

On Wed, Aug 31, 2011 at 03:37:28AM -0400, speedfirst wrote:

> For a request with an IPv6 Host header like:
> 
> Host: Host: [2001:250:1800:1::88]
> 
> The function “ngx\_http\_validate\_host” will consider the trailing “:88]”  
> as a port number and trim it. Therefore the value of  
> “r-\>headers\_in.server” and “$host” will become:

This is a known problem, please see

> **[\#1 (Incorrect parsing of IPv6 literal in Host header)
          – nginx](https://trac.nginx.org/nginx/ticket/1)**

The same applies to the patch submitted.

Maxim D.

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [September 1, 2011, 5:17am UTC](https://www.ruby-forum.com/t/a-bug-when-host-header-contain-ipv6-address/211265/4 "2011-09-01T05:17:31Z")

</div>

Thanks. the general idea of that patch is similar to mine but better. So  
I’ll apply it.

If you can tell me why you feel that patch is not enough, I can help to  
improve it.

Posted at Nginx Forum:

> **[Re: A bug when Host header contain IPv6 address](https://forum.nginx.org/read.php?2,214541,214605#msg-214605)**
>
> For a request with an IPv6 Host header like: Host: Host: \[2001:250:1800:1::88\] The function "ngx\_http\_validate\_host" will consider the trailing ":88\]" as a port number and trim it. Therefore the value of...
