HTTP header values do not have trailing OWS trimmed
The http_parser library does not trim trailing optional whitespace from HTTP header values, so a value like 'foo.com ' is passed through with the space intact. An attacker could bypass a server's domain-blocking rules by appending whitespace to a blocked hostname, allowing requests that should be denied.
Originally disclosed on HackerOne
- Triaged in 20 days
- Fixed in 3 months
- Paid in 8 months
- Disclosed after 4 months
[I suspect I may have tagged the wrong vulnerability type -I'm failing to find "insufficient validation of user input"]
According to the HTTP-spec, http values are field-value = *( field-content | LWS ) http_parser does not appear to trim trailing LWS. This means if a user sends "Host: foo\r\n" the string literal "foo" is passed up, but if the user sends "Host: foo \r\n" the string literal "foo " is passed up, complete with trailing LWS.
Steps To Reproduce:
(Add details for how we can reproduce the issue)
If one hands "GET / HTTP/1.1\r\nHost: foo.com \r\nHello: World\r\n\r\n" to http_parser, http_parser sends on_header_value "foo.com " instead of "foo.com"
Impact: [add why this issue matters]
We are trying to address an issue with Envoy, where if "GET / HTTP/1.1\r\nHost: my-super-private-domain.com \r\nHello: World\r\n\r\n" is passed to Envoy, and Envoy is configured to block any requests to "my-super-private-domain.com", the matcher fails due the trailing whitespace, and external users can tunnel requests that should be blocked.
Originally we were going to address this by doing whitespace trimming in Envoy, but this should probably be fixed upstream in http_parser in case other users are affected, so we're reaching out to see what folks on your end think.
Supporting Material/References:
My Envoy regression test verifies this lack of LWS trimming, but this is current under envoy security embargo, so please don't share
TEST_F(Http1ServerConnectionImplTest, LWS) {
initialize();
InSequence sequence;
Http::MockStreamDecoder decoder;
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));
TestHeaderMapImpl expected_headers{
{"Test", "value "}, // note the LWS after value is passed up from http_parser to Envoy :-(
{"Hello", "World"},
{":path", "/"},
{":method", "GET"},
};
EXPECT_CALL(decoder, decodeHeaders_(HeaderMapEqual(&expected_headers), true)).Times(1);
Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\nTest: value \r\nHello: World\r\n\r\n");
codec_->dispatch(buffer);
EXPECT_EQ(0U, buffer.length());
}
Impact
As said above, this could allow privileged escalation, where if one uses an http_parser enabled server configured to block specific domains, those blocks can be trivially bypassed using white-space. It's possible there are other attacks bypassing http_parser header value checks with whitespace, but I haven't investigated beyond the most obvious exploit
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the parser does not strip trailing optional whitespace (LWS) from header values as the HTTP specification requires.
Impact
A server that relies on exact header-value matching to block domains could have those blocks bypassed, potentially allowing access to private domains; the reporter notes this could allow privilege escalation but has not investigated other attacks.
What the attacker needed
Server uses http_parser and blocks domains by exact match; attacker can send crafted HTTP requests
The fix
The issue should be fixed upstream in http_parser by trimming trailing optional whitespace from header values, rather than only working around it in Envoy.
How it was found
- Send a request with a header value that has trailing whitespace, such as a Host header ending in a space.
- Observe that http_parser passes the header value to the application with the trailing space still present.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
HTTP headers are lines like 'Host: example.com'. The rules say spaces at the end of a header value are not part of the value, but this library keeps them. If a server blocks a domain by exact name, adding a space makes the name look different, so the block can be skipped.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.