pratikvasa pratikvasa - 4 months ago 37
HTTP Question

Extra space in HTTP headers gives 400 error on HAProxy

We switched from citrix to HAProxy for load balancing recently.

The Problem is that for some requests HAProxy started giving a 400 Error (Which used to work well on citrix). So we moved to TCP based load balancing from a HTTP based load balancing for the time being.

On further investigating we found that some requests had an extra space in the HTTP header which caused the 400 error.


And these requests came from the android app so we are not able to change the source code.

We are trying to move back to http based load balancing.

Is there any config setting that may allow us to ignore the space.


HAProxy supports a proxy configuration directive called option accept-invalid-http-request.

It relaxes some of the strict protocol compliance that HAProxy correctly requires by default on incoming requests, so it should not be used blindly or carelessly without understanding the implications.

From the documentation:

By default, HAProxy complies with RFC7230 in terms of message parsing. This means that invalid characters in header names are not permitted and cause an error to be returned to the client. This is the desired behaviour as such forbidden characters are essentially used to build attacks exploiting server weaknesses, and bypass security filtering.

Sometimes, a buggy browser or server will emit invalid header names for whatever reason (configuration, implementation) and the issue will not be immediately fixed. In such a case, it is possible to relax HAProxy's header name parser to accept any character even if that does not make sense, by specifying this option.

Similarly, the list of characters allowed to appear in a URI is well defined by RFC3986, and chars 0-31, 32 (space), 34 ('"'), 60 ('<'), 62 ('>'), 92 ('\'), 94 ('^'), 96 ('`'), 123 ('{'), 124 ('|'), 125 ('}'), 127 (delete) and anything above are not allowed at all. Haproxy always blocks a number of them (0..32, 127). The remaining ones are blocked by default unless this option is enabled. This option also relaxes the test on the HTTP version, it allows HTTP/0.9 requests to pass through (no version specified) and multiple digits for both the major and the minor version.

This option should never be enabled by default as it hides application bugs and open security breaches. It should only be deployed after a problem has been confirmed. (emphasis added)

Adding this option to the respective frontend section of your configurarion file should allow these invalid headers to be accepted.

Note that the potential security risks mentioned in the documentation are not risks inherent in HAProxy, but rather risks of exploits against vulnerabilities in your stack behind the proxy -- because normally, HAProxy shields those components from such invalid requests.