Bug 60704 - Setting "HttpProtocolOptions Unsafe ..." does not allow Host Header containing "_"
Summary: Setting "HttpProtocolOptions Unsafe ..." does not allow Host Header containin...
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Core (show other bugs)
Version: 2.2.32
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: MassUpdate
Depends on:
Reported: 2017-02-07 13:12 UTC by Michael
Modified: 2018-11-07 21:09 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2017-02-07 13:12:19 UTC

actually this bug report affects 2.2.32, but this version is not available in "Version" dropdown.

In a server to server communication we (accidently) are using hostnames containing the underline character. With default settings apache 2.2.32 is refusing to process requests with such hostnames and fails with a http status 400, bad request.

In my understanding the HttpProcotolOptions directive has been introduced to bring back the legacy behaviour. In my case with hostnames containing underline characters, this does not work. Requests are declined as "400 Bad Request", though I set "HttpProtocolOptions Unsafe LenientMethods Allow0.9".

To reproduce start apache 2.2.32 with:
"HttpProtocolOptions Unsafe LenientMethods Allow0.9"

Run the following command:

curl -v -H "Host: bad_request_hostname"

It returns:

HTTP/1.1 400 Bad Request

With apache 2.4.25 the host header containing underlines is processed correctly, if HttpProtocolOptions is set to Unsafe.

Best regards,
Comment 1 Eric Covener 2017-02-07 13:35:37 UTC
I get the same result in 2.2.x and 2.4.x. I don't think HttpProtocolOptions was meant to revert every strict processing change.
Comment 2 Michael 2017-02-07 13:56:36 UTC
Hi Eric,

can you clarify, what the same result means?

Do you get the same results as I did:
apache 2.4.x works and apache 2.2.x does not?

Or did apache 2.4.25 and 2.2.32 behave the same and work / do not work both?

Comment 3 Eric Covener 2017-02-07 14:15:30 UTC
(In reply to Michael from comment #2)
> Hi Eric,
> can you clarify, what the same result means?
> Do you get the same results as I did:
> apache 2.4.x works and apache 2.2.x does not?
> Or did apache 2.4.25 and 2.2.32 behave the same and work / do not work both?

sorry, both rejected the underscore and HTTPProtocolOptions didn't change either behavior.
Comment 4 Michael 2017-02-07 15:40:58 UTC
I tested again on two different servers, same result again:

Apache 2.2.32 and 2.4.25 both configured with on vHost which has a ServerAlias bad_request_hostname and HttpProtocolOptions Unsafe LenientMethods Allow0.9 in server (not vHost!) context.

curl -v -H "Host: bad_request_hostname"

Apache 2.2.32: HTTP/1.1 400 Bad Request

Apache 2.4.25: HTTP/1.1 200 OK

I'm a little confused ..

Comment 5 Michael 2017-02-23 16:32:13 UTC
Today I faced another issue, that's confusing me even more. Testcase is apache 2.4.25, HttpProtocolOptions set to "Unsafe LenientMethods Allow0.9".

1) curl -H "Host: my_invalid_hostname" -v http://localhost/
   Returns: HTTP/1.1 200 OK
   OK - Unsafe mode allows a Host header containing a underline.

2) curl -H "Accept<TAB>: application/xml" -v http://localhost/
   Returns: HTTP/1.1 400 Bad Request
   Debug output: Request header field name is malformed: Accept\t: application/xml

Looking into the sourcecode (server/protocol.c, line 1130) the message "Request header field name is malformed" only will be logged in strict mode, but not in unsafe mode ..

Best regards,
Comment 6 paolo 2017-03-09 10:47:39 UTC
I have the same behaviour. Even with 
HttpProtocolOptions  Unsafe LenientMethods Allow0.9

requests may still be blocked, and I have the following log-entry:

[Thu Mar 09 11:02:51 2017] [debug] protocol.c(828): [client] HTTP Request Line; Excess whitespace (disallowed by HttpProtocolOptions Strict

I compared the code with httpd/2.4.25 (where the request is not blocked), and the functions merge_core_server_configs (core.c) do slightly differ:

in 2.2.32:
static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
    core_server_config *base = (core_server_config *)basev;
    core_server_config *virt = (core_server_config *)virtv;
    core_server_config *conf;

    conf = (core_server_config *)apr_pmemdup(p, base, sizeof(core_server_config));

in 2.4.25:
static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
    core_server_config *base = (core_server_config *)basev;
    core_server_config *virt = (core_server_config *)virtv;
    core_server_config *conf = (core_server_config *)
                               apr_pmemdup(p, base, sizeof(core_server_config));

As you can see, in 2.4.25 the 'conf' is taken from 'base' and not from 'virtv' like in 2.2.32.
I changed the code in 2.2.32. and then the request is not blocked any more.
I have no idea if this is the right solution, because of the other parameters that are used.
Comment 7 Jim Jagielski 2017-03-09 13:20:46 UTC
In the above snippets I see conf being copied from base in both cases...
Comment 8 Eric Covener 2017-03-09 13:33:08 UTC
(In reply to Jim Jagielski from comment #7)
> In the above snippets I see conf being copied from base in both cases...
This is already fixed in 2.2.x HEAD
Comment 9 William A. Rowe Jr. 2018-11-07 21:09:37 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.