Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uhv: add http-parser permissive parsing for h1 codec #20872

Merged
merged 6 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bazel/external/http_parser/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ cc_library(
# This compiler flag is set to an arbtitrarily high number so
# as to effectively disables the http_parser header limit, as
# we do our own checks in the conn manager and codec.
copts = ["-DHTTP_MAX_HEADER_SIZE=0x2000000"],
copts = ["-DHTTP_MAX_HEADER_SIZE=0x2000000"] + select({
"@envoy//bazel:uhv_enabled": ["-DHTTP_PARSER_STRICT=0"],
"//conditions:default": [],
}),
includes = ["."],
visibility = ["//visibility:public"],
)
28 changes: 28 additions & 0 deletions test/common/http/http1/codec_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,34 @@ TEST_F(Http1ServerConnectionImplTest, PipedRequestWithMutipleEvent) {
connection_.dispatcher_.clearDeferredDeleteList();
}

TEST_F(Http1ServerConnectionImplTest, Utf8Path) {
initialize();

MockRequestDecoder decoder;
Buffer::OwnedImpl buffer("GET /δ¶/δt/pope?q=1#narf HXXP/1.1\r\n\r\n");
#ifdef ENVOY_ENABLE_UHV
// permissive
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

TestRequestHeaderMapImpl expected_headers{
{":path", "/δ¶/δt/pope?q=1#narf"},
{":method", "GET"},
};
EXPECT_CALL(decoder, decodeHeaders_(HeaderMapEqual(&expected_headers), true));

auto status = codec_->dispatch(buffer);
EXPECT_TRUE(status.ok());
EXPECT_EQ(0U, buffer.length());
#else
// strict
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

EXPECT_CALL(decoder, sendLocalReply(_, _, _, _, _));
auto status = codec_->dispatch(buffer);
EXPECT_TRUE(isCodecProtocolError(status));
#endif
}

// Tests that incomplete response headers of 80 kB header value fails.
TEST_F(Http1ClientConnectionImplTest, ResponseHeadersWithLargeValueRejected) {
initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ TEST_F(HttpInspectorTest, MultipleReadsHttp1IncompleteBadHeader) {
}

TEST_F(HttpInspectorTest, MultipleReadsHttp1BadProtocol) {
#ifdef ENVOY_ENABLE_UHV
// permissive parsing
return;
#endif

const std::string valid_header = "GET /index HTTP/1.1\r";
// offset: 0 10
const std::string truncate_header = valid_header.substr(0, 14).append("\r");
Expand Down
5 changes: 5 additions & 0 deletions test/integration/protocol_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3468,6 +3468,11 @@ TEST_P(ProtocolIntegrationTest, UpstreamDisconnectBeforeResponseCompleteWireByte
TEST_P(DownstreamProtocolIntegrationTest, BadRequest) {
config_helper_.disableDelayClose();
// we only care about upstream protocol.
#ifdef ENVOY_ENABLE_UHV
// permissive parsing is enabled
return;
#endif

if (downstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions tools/spelling/spelling_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ UA
UBSAN
UDP
UDS
UHV
UNC
URI
URL
Expand Down