Skip to content
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
4 changes: 2 additions & 2 deletions source/common/router/header_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ HeaderParserPtr HeaderParser::configure(
// We reject :-prefix (e.g. :path) removal here. This is dangerous, since other aspects of
// request finalization assume their existence and they are needed for well-formedness in most
// cases.
if (header[0] == ':') {
throw EnvoyException(":-prefixed headers may not be removed");
if (header[0] == ':' || Http::LowerCaseString(header).get() == "host") {
throw EnvoyException(":-prefixed or host headers may not be removed");
}
header_parser->headers_to_remove_.emplace_back(header);
}
Expand Down
4 changes: 2 additions & 2 deletions test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ name: foo
// Validate that we can't remove :-prefixed request headers.
TEST(RouteMatcherTest, TestRequestHeadersToRemoveNoPseudoHeader) {
for (const std::string& header : {":path", ":authority", ":method", ":scheme", ":status",
":protocol", ":no-chunks", ":status"}) {
":protocol", ":no-chunks", ":status", "host"}) {
const std::string yaml = fmt::format(R"EOF(
name: foo
virtual_hosts:
Expand All @@ -1027,7 +1027,7 @@ name: foo
envoy::api::v2::RouteConfiguration route_config = parseRouteConfigurationFromV2Yaml(yaml);

EXPECT_THROW_WITH_MESSAGE(TestConfigImpl config(route_config, factory_context, true),
EnvoyException, ":-prefixed headers may not be removed");
EnvoyException, ":-prefixed or host headers may not be removed");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config { virtual_hosts { name: " " domains: "*" routes { match { path: "/" } route { cluster: " " host_rewrite: " " } } } request_headers_to_remove: "host" }
16 changes: 8 additions & 8 deletions test/common/router/route_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ DEFINE_PROTO_FUZZER(const test::common::router::RouteTestCase& input) {
MessageUtil::validate(input.config());
ConfigImpl config(input.config(), factory_context, true);
Http::TestHeaderMapImpl headers = Fuzz::fromHeaders(input.headers());
// It's a precondition of routing that {host, path:, x-fowarded-proto} headers exists, HCM
// enforces this.
if (!headers.has("host")) {
headers.addCopy("host", "example.com");
// It's a precondition of routing that {:authority, :path, x-forwarded-proto} headers exists,
// HCM enforces this.
if (headers.Host() == nullptr) {
headers.insertHost().value(std::string("example.com"));
}
if (!headers.has(":path")) {
headers.addCopy(":path", "/");
if (headers.Path() == nullptr) {
headers.insertPath().value(std::string("/"));
}
if (!headers.has("x-forwarded-proto")) {
headers.addCopy("x-forwarded-proto", "http");
if (headers.ForwardedProto() == nullptr) {
headers.insertForwardedProto().value(std::string("http"));
}
auto route = config.route(headers, input.random_value());
if (route != nullptr && route->routeEntry() != nullptr) {
Expand Down