Skip to contentSkip to conversation

HTTP/1.1 Host header

Openvpn-devel Lars Hupel 5 participants 18 messages Sep 27, 2010 – Oct 3, 2010

lore
Share & tools
lore

Lars Hupel

author
#0 lore raw

Hi,

as the subject states, I would like that OpenVPN sends an appropriate Host header, because my server configuration relies on Apache's VirtualHosts. Because OpenVPN doesn't send this header, I patched it myself. Recently, I found the discussion on openvpn-devel from 10/2008 (subject was "enhance compatibility with HTTP/1.1 proxies", from Frank Behrens) about a very similar patch. However, I was not able to extract from that discussion why the patch was rejected (or simply ignored?). Are there any objections to accept the patch?

Regards,
Lars

#1 lore raw
Quoted 12 lines · Lars Hupel

Hi,

as the subject states, I would like that OpenVPN sends an appropriate Host header, because my server configuration relies on Apache's VirtualHosts. Because OpenVPN doesn't send this header, I patched it myself. Recently, I found the discussion on openvpn-devel from 10/2008 (subject was "enhance compatibility with HTTP/1.1 proxies", from Frank Behrens) about a very similar patch. However, I was not able to extract from that discussion why the patch was rejected (or simply ignored?). Are there any objections to accept the patch?

I'm not sure if I understand the question ; openvpn already has the option to use http/1.1 headers using
--http-proxy-option VERSION 1.1
which should send HTTP/1.1 type messages - doesn't that work?

HTH,

JJK

author
#2 lore raw
Quoted 4 lines

I'm not sure if I understand the question ; openvpn already has the option to use http/1.1 headers using
--http-proxy-option VERSION 1.1
which should send HTTP/1.1 type messages - doesn't that work?

The problem is that (at least Apache) rejects these requests because the Host header is missing, so I get "Bad Request" responses.

Additionally, without Host header it's impossible to use Apache's VirtualHost facility.

Regards
Lars

#3 lore raw
Quoted 6 lines · Lars Hupel
Quoted 5 lines

I'm not sure if I understand the question ; openvpn already has the option to use http/1.1 headers using
--http-proxy-option VERSION 1.1
which should send HTTP/1.1 type messages - doesn't that work?

Quoted 10 lines

The problem is that (at least Apache) rejects these requests because the Host header is missing, so I get "Bad Request" responses.

Additionally, without Host header it's impossible to use Apache's VirtualHost facility.

Regards
Lars

ah right, now I see... hmmm 'Host: ...' headers should not be required by a web server and with apache's Virtual Hosts you can override this using

<VirtualHost _default_:1234>
DocumentRoot /www/default1234
...
</VirtualHost>

<VirtualHost _default_:80>
DocumentRoot /www/default80
...
</VirtualHost>

etc but this seems like an easy patch. Perhaps someone else on the -devel list can comment on why it was not accepted...

cheers,

JJK

#4 lore raw
Quoted 2 lines · Jan Just Keijser

ah right, now I see... hmmm 'Host: ...' headers should not be required by a web server and with apache's Virtual Hosts you can override this using

I would have to disagree with whether Host: headers should be required, given that the HTTP/1.1 specification explicitly says [RFC2616]:

"All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field."

The client also "MUST" send a Host: header in every request, it is not an optional field. Changing only the version number on the CONNECT line OpenVPN sends does not make it a real HTTP/1.1 request.

(From what I can tell, and based on a very quick test, the string "_default_" in an Apache <VirtualHost> config also only matches unlisted IP addresses, and does not change how it processes HTTP requests that claim to be version 1.1 but aren't.)

Signature · 2 lines
Heikki Kallasjoki
[email protected]...
author
#5 lore raw
Quoted 10 lines

I would have to disagree with whether Host: headers should be required, given that the HTTP/1.1 specification explicitly says [RFC2616]:

"All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field."

The client also "MUST" send a Host: header in every request, it is not an optional field. Changing only the version number on the CONNECT line OpenVPN sends does not make it a real HTTP/1.1 request.

I would second that and therefore consider this behaviour as a bug. Additionally, my setup requires to have all VirtualHosts on Port 80, so without the header an effective disambiguation is impossible.

Lars

#6 lore raw
In reply to Heikki Kallasjoki

Hi ,

Quoted 12 lines · Heikki Kallasjoki
Quoted 2 lines · Jan Just Keijser

ah right, now I see... hmmm 'Host: ...' headers should not be required by a web server and with apache's Virtual Hosts you can override this using

I would have to disagree with whether Host: headers should be required, given that the HTTP/1.1 specification explicitly says [RFC2616]:

"All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field."

Quoted 11 lines

The client also "MUST" send a Host: header in every request, it is not an optional field. Changing only the version number on the CONNECT line OpenVPN sends does not make it a real HTTP/1.1 request.

(From what I can tell, and based on a very quick test, the string "_default_" in an Apache <VirtualHost> config also only matches unlisted IP addresses, and does not change how it processes HTTP requests that claim to be version 1.1 but aren't.)

now I see where the confusion is coming from : by default openvpn is using HTTP/1.0 requests; RFC1945 (http 1.0 standard) does NOT specify that the Host: header should be present. This was added in HTTP/1.1 RFC2616 ; so I guess that whenever you specify HTTP/1.1 requests using
--http-proxy-option VERSION 1.1
then OpenVPN should also send a 'Host: ' header - seems like a trivial fix to me. I still have no clue why the original patch was not accepted, but then again, the mechanism for entering patches has changed (improved!) a lot as of late.

HTH,

JJK

author
#7 lore raw

After looking into the source code, there are (at least) two places where this patch has to be applied.

1) The place described earlier and mentioned in the original patch (I would guess)
2) There is duplicated code in the same function when the proxy answered with "407 Proxy Authentication Required". Maybe it is possible to move this into an extra function, maybe send_proxy_headers.

However, contrary to the original patch from 2008, I would suggest to always send the Host header (even when HTTP/1.0 is selected). That should cause no problems with legacy 1.0 applications, as stated by the RFC:

Quoted 2 lines

Unrecognized header fields should be ignored by the recipient and forwarded by proxies.

If necessary, I could write a new patch including all proxy requests in proxy.c. But as I have no overview of the OpenVPN source code, I will probably miss some places where such a request is sent.

Lars

author
#8 lore raw
Quoted 8 lines

After looking into the source code, there are (at least) two places where this patch has to be applied.

1) The place described earlier and mentioned in the original patch (I would guess)
2) There is duplicated code in the same function when the proxy answered with "407 Proxy Authentication Required". Maybe it is possible to move this into an extra function, maybe send_proxy_headers.

Apparently I was mistaken at this point. With the very first place where an HTTP CONNECT is issued being the only exception, at all other places the Host header is sent.

However, I'm not sure whether these are correct. As far as I can see, there are two possible hosts which can be sent:

* 'host' (denoting the 'remote' config option)
* 'p->options.server' (denoting the 'http-proxy' config option)

I would guess that sending the latter would be correct, but the OpenVPN sources use the first one. For example, consider the following configuration:

http-proxy-option VERSION 1.1
http-proxy vpn.example.com 80
remote localhost 1194

I would expect the OpenVPN client to send the request as following (over a connection with vpn.example.com:80):

	CONNECT localhost:1194 HTTP/1.1
	Host: vpn.example.com

At the moment (and with the patch proposed in 2008), the following request is sent:

	CONNECT localhost:1194 HTTP/1.1
	Host: localhost

The problem is that the RFC isn't clear at that point. Consider the following snippet from the section about 'CONNECT':

Quoted 3 lines

This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel (e.g. SSL tunneling [44]).

The section about the host header isn't very helpful either:

Quoted 4 lines

The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (generally an HTTP URL [...]

#9 lore raw
Quoted 2 lines · Lars Hupel

I would suggest to always send the Host header (even when HTTP/1.0 is selected).

I strongly support this. Please watch out for HTTP/1.1, if a client claims to support 1.1 then servers can respond e.g. with chunked transfer coding, which certainly isn't supported by 1.0 clients. On the other hand, if OpenVPN only ever CONNECTs, maybe it's not an issue.

Quoted 7 lines · Lars Hupel

As far as I can see, there are two possible hosts which can be sent:

* 'host' (denoting the 'remote' config option)
* 'p->options.server' (denoting the 'http-proxy' config option)

I would guess that sending the latter would be correct, but the OpenVPN sources use the first one.

Current behavior is correct. The first one is what should be sent.

Quoted 5 lines

The section about the host header isn't very helpful either:

Quoted 3 lines

The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (generally an HTTP URL

Actually it is helpful. It says that *the resource being requested as obtained from the original URI given by the user* is what should be sent. This is the "remote" parameter and nothing else.

I'll ack your patch if it only adds a Host header where one is missing, and sends the correct contents, ie. the "remote" hostname.

//Peter

author
#10 lore raw
Quoted 5 lines

Current behavior is correct. The first one is what should be sent. [...]
Actually it is helpful. It says that *the resource being requested as obtained from the original URI given by the user* is what should be sent. This is the "remote" parameter and nothing else.

So what you're implying is that if a request is sent, the part after 'CONNECT' must be always the same as the part after 'Host'.

Quoted 2 lines

I'll ack your patch if it only adds a Host header where one is missing, and sends the correct contents, ie. the "remote" hostname.

Hopefully the attached patch is acceptable for you.

Lars

proxy.c +4 -0
@@ -551,6 +551,10 @@
       /* send HTTP CONNECT message to proxy */
       if (!send_line_crlf (sd, buf))
 	goto error;
+      
+      openvpn_snprintf(buf, sizeof(buf), "Host: %s", host);
+      if (!send_line_crlf(sd, buf))
+        goto error;
 
       /* send User-Agent string if provided */
       if (p->options.user_agent)
Acked-by
#11 lore raw

Re: [Openvpn-devel] HTTP Host header

Quoted 8 lines · Lars Hupel
Quoted 5 lines

Current behavior is correct. The first one is what should be sent. [...]
Actually it is helpful. It says that *the resource being requested as obtained from the original URI given by the user* is what should be sent. This is the "remote" parameter and nothing else.

So what you're implying is that if a request is sent, the part after 'CONNECT' must be always the same as the part after 'Host'.

Yep. It's a bit redundant, but consider that CONNECT is already the odd kid among the HTTP verbs. Most other verbs only take an absolute path URI, without host component.

Quoted 4 lines
Quoted 2 lines

I'll ack your patch if it only adds a Host header where one is missing, and sends the correct contents, ie. the "remote" hostname.

Hopefully the attached patch is acceptable for you.

I'm just another community member, but I think the patch is correct. Thanks!

#12 lore raw

Re: [Openvpn-devel] HTTP Host header

Quoted 7 lines · Peter Stuge
Quoted 6 lines · Lars Hupel
Quoted 5 lines

Current behavior is correct. The first one is what should be sent. [...]
Actually it is helpful. It says that *the resource being requested as obtained from the original URI given by the user* is what should be sent. This is the "remote" parameter and nothing else.

Quoted 6 lines
Quoted 2 lines

So what you're implying is that if a request is sent, the part after 'CONNECT' must be always the same as the part after 'Host'.

Yep. It's a bit redundant, but consider that CONNECT is already the odd kid among the HTTP verbs. Most other verbs only take an absolute path URI, without host component.

On the other hand, in a proxy context the host component is always present even for the other methods. ("The absoluteURI form is REQUIRED when the request is being made to a proxy.") In that sense the host header is sort-of redundant for all proxy requests, and could be used for name-based "do we act as a proxy or an origin server" decisions. Still, duplicating the "target" host name seems to be what regular web browsers do; mine sends "GET http://example.com/test HTTP/1.1" followed by "Host: example.com". And I do agree that this is what the "original URI" verbiage in the RFC implies, though I think it could have been worder better.

(Also, the patch looks good.)

Signature · 2 lines
Heikki Kallasjoki
[email protected]...
author
#13 lore raw

Re: [Openvpn-devel] HTTP Host header

Quoted 9 lines
Quoted 3 lines

Yep. It's a bit redundant, but consider that CONNECT is already the odd kid among the HTTP verbs. Most other verbs only take an absolute path URI, without host component.

On the other hand, in a proxy context the host component is always present even for the other methods. ("The absoluteURI form is REQUIRED when the request is being made to a proxy.") In that sense the host header is sort-of redundant for all proxy requests, and could be used for name-based "do we act as a proxy or an origin server" decisions.

I would agree with that. When thinking about it, the Host header doesn't make any sense to me.

My expectation would be that the proxy server uses the host name given after GET (or CONNECT) to regulate access control (and to forward it as 'new' Host header) and the Host header to disambiguate between multiple virtual hosts (e. g. like in my case with a configuration where a normal web server and a proxy server have the same IP address and are represented by two different Apache virtual hosts). With that, both host fields would serve different purposes and wouldn't be redundant.

Lars

#14 lore raw

Re: [Openvpn-devel] HTTP Host header

Quoted 1 line · Lars Hupel

When thinking about it, the Host header doesn't make any sense to me.

It was added to support virtual hosting in a time (20? years ago) when the domain name wasn't included anywhere in the request, but used only for client-side IP-adress lookup. Back then it was a reasonable assumption that IP addresses were actually useful identifiers for network resources.

//Peter

#15 lore raw

Re: [Openvpn-devel] HTTP Host header

In reply to Lars Hupel

Hi,

Quoted 7 lines · Lars Hupel

My expectation would be that the proxy server uses the host name given after GET (or CONNECT) to regulate access control (and to forward it as 'new' Host header) and the Host header to disambiguate between multiple virtual hosts (e. g. like in my case with a configuration where a normal web server and a proxy server have the same IP address and are represented by two different Apache virtual hosts). With that, both host fields would serve different purposes and wouldn't be redundant.

Have you been able to figure out how Apache handles this? Is it using the Host: header in CONNECT requests for anything, and if yes, what should be in there? Is that documented anywhere?

To see how "other software" does this, I've tcpdumped firefox going to a SSL secured banking site, and that's what it does...:

CONNECT banking.postbank.de:443 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.9) Gecko/20100927 Gentoo Firefox/3.6.9
Proxy-Connection: keep-alive
Host: banking.postbank.de

- so indeed, the Host: header is redundant and somewhat useless here.

Soo...: I ACK the proposed patch as well. It does the same what web browsers do (no matter how useful or not it might be), the code has no quality issues and conforms to OpenVPN coding conventions.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
author
#16 lore raw

Re: [Openvpn-devel] HTTP Host header

Quoted 3 lines

Have you been able to figure out how Apache handles this? Is it using the Host: header in CONNECT requests for anything, and if yes, what should be in there? Is that documented anywhere?

I made a test, but it was inconclusive. I couldn't find any pattern in the results I got. My configuration with two VirtualHosts looked like this:

ServerName foo
<Proxy foo>
...
</Proxy>
AllowCONNECT 1234

ServerName bar
<Proxy bar>
...
</Proxy>
AllowCONNECT 1235

With some request combinations for port 1234 I even got connected to port 1235. I couldn't find any documentation on this.

Lars