Skip to content

Commit

Permalink
http_health_check: host and path validation (envoyproxy#32521)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Boteng Yao <boteng@google.com>
  • Loading branch information
botengyao authored Mar 27, 2024
1 parent be5ee88 commit b43ea9d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
5 changes: 2 additions & 3 deletions api/envoy/config/core/v3/health_check.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ message HealthCheck {
// left empty (default value), the name of the cluster this health check is associated
// with will be used. The host header can be customized for a specific endpoint by setting the
// :ref:`hostname <envoy_v3_api_field_config.endpoint.v3.Endpoint.HealthCheckConfig.hostname>` field.
string host = 1 [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];
string host = 1 [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE}];

// Specifies the HTTP path that will be requested during health checking. For example
// ``/healthcheck``.
string path = 2
[(validate.rules).string = {min_len: 1 well_known_regex: HTTP_HEADER_VALUE strict: false}];
string path = 2 [(validate.rules).string = {min_len: 1 well_known_regex: HTTP_HEADER_VALUE}];

// [#not-implemented-hide:] HTTP specific payload.
Payload send = 3;
Expand Down
2 changes: 2 additions & 0 deletions source/extensions/health_checkers/http/health_checker_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ HttpHealthCheckerImpl::HttpHealthCheckerImpl(
static_cast<uint64_t>(Http::Code::OK)),
codec_client_type_(codecClientType(config.http_health_check().codec_client_type())),
random_generator_(context.api().randomGenerator()) {
// TODO(boteng): introduce additional validation for the authority and path headers
// based on the default UHV when it is available.
auto bytes_or_error = PayloadMatcher::loadProtoBytes(config.http_health_check().receive());
THROW_IF_STATUS_NOT_OK(bytes_or_error, throw);
receive_bytes_ = bytes_or_error.value();
Expand Down
49 changes: 49 additions & 0 deletions test/common/upstream/health_check_corpus/http_host_value

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions test/common/upstream/health_checker_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,40 @@ TEST_F(HttpHealthCheckerImplTest, MethodConnectDisallowedValidation) {
"Proto constraint validation failed.*")
}

TEST_F(HttpHealthCheckerImplTest, InvalidHost) {
const std::string yaml = R"EOF(
timeout: 1s
interval: 1s
no_traffic_interval: 5s
interval_jitter: 1s
unhealthy_threshold: 1
healthy_threshold: 1
http_health_check:
host: "\x07"
path: "/aaa"
)EOF";

EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed*")
}

TEST_F(HttpHealthCheckerImplTest, InvalidPath) {
const std::string yaml = R"EOF(
timeout: 1s
interval: 1s
no_traffic_interval: 5s
interval_jitter: 1s
unhealthy_threshold: 1
healthy_threshold: 1
http_health_check:
host: "aaa"
path: "\x08"
)EOF";

EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed*")
}

TEST_F(ProdHttpHealthCheckerTest, ProdHttpHealthCheckerH2HealthChecking) {
setupNoServiceValidationHCWithHttp2();
EXPECT_EQ(Http::CodecType::HTTP2,
Expand Down

0 comments on commit b43ea9d

Please sign in to comment.