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: Fix response status checks #27125

Merged
merged 8 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 26 additions & 2 deletions source/common/http/http2/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,13 @@ void ConnectionImpl::StreamImpl::decodeData() {

void ConnectionImpl::ClientStreamImpl::decodeHeaders() {
auto& headers = absl::get<ResponseHeaderMapPtr>(headers_or_trailers_);
#ifndef ENVOY_ENABLE_UHV
const uint64_t status = Http::Utility::getResponseStatus(*headers);

#ifndef ENVOY_ENABLE_UHV
// Extended CONNECT to H/1 upgrade transformation has moved to UHV
if (!upgrade_type_.empty() && headers->Status()) {
Http::Utility::transformUpgradeResponseFromH2toH1(*headers, upgrade_type_);
}
#endif

// Non-informational headers are non-1xx OR 101-SwitchingProtocols, since 101 implies that further
// proxying is on an upgrade path.
Expand All @@ -544,6 +543,31 @@ void ConnectionImpl::ClientStreamImpl::decodeHeaders() {
} else {
response_decoder_.decodeHeaders(std::move(headers), sendEndStream());
}
#else
// in UHV mode the :status header at this point can be malformed, as it is validated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "in" => "In"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// later on in the response_decoder_.decodeHeaders() call.
// Account for this here.
absl::optional<uint64_t> status_opt = Http::Utility::getResponseStatusOrNullopt(*headers);
if (status_opt.has_value()) {
const uint64_t status = status_opt.value();
// Non-informational headers are non-1xx OR 101-SwitchingProtocols, since 101 implies that
// further proxying is on an upgrade path.
received_noninformational_headers_ =
!CodeUtility::is1xx(status) || status == enumToInt(Http::Code::SwitchingProtocols);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we have he same problem for the other codecs?
would it makes more sense to have isSpecial1xx handle these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Both balsa and EnvoyQuicClientStream validate status, so it does not reach UHV. I will work on fixing this. Balsa fix will need to wait, since Bence is OOO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved the :status header checks for H/2 and H/3 codecs into UHV when it is enabled. For H/1 codec it is a lot more difficult to move status validation in the response line out of the low level parser (http-parser and Balsa), as it will require changing parser API and a few other spots where parser itself is using the code. This may become more tractable once http-parser is decommissioned.

I think keeping status validation in H/1 parser for now is ok, as it just reduces visibility into protocol errors if status is malformed. When the plumbing for the parser error codes into reset reason strings is finished it will reduce this shortcoming.


if (HeaderUtility::isSpecial1xx(*headers)) {
ASSERT(!remote_end_stream_);
response_decoder_.decode1xxHeaders(std::move(headers));
} else {
response_decoder_.decodeHeaders(std::move(headers), sendEndStream());
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's use early return to save a level of nesting:

  if (!status_opt.has_value()) {
    // In case the status is invalid or missing, the response_decoder_.decodeHeaders() will fail the
    // request
    response_decoder_.decodeHeaders(std::move(headers), sendEndStream());
    return;
  }
  const uint64_t status = status_opt.value();
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// In case the status is invalid or missing, the response_decoder_.decodeHeaders() will fail the
// request
response_decoder_.decodeHeaders(std::move(headers), sendEndStream());
}

#endif
}

bool ConnectionImpl::StreamImpl::maybeDeferDecodeTrailers() {
Expand Down
28 changes: 0 additions & 28 deletions test/integration/protocol_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1860,13 +1860,6 @@ TEST_P(ProtocolIntegrationTest, 304WithBody) {
}

TEST_P(ProtocolIntegrationTest, OverflowingResponseCode) {
#ifdef ENVOY_ENABLE_UHV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo hoo!

// TODO(#24945): In UHV case this test breaks in the CONNECT/upgrade normalization code in H/2
// codec
if (upstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
#endif
useAccessLog("%RESPONSE_CODE_DETAILS%");
initialize();

Expand Down Expand Up @@ -1895,13 +1888,6 @@ TEST_P(ProtocolIntegrationTest, OverflowingResponseCode) {
}

TEST_P(ProtocolIntegrationTest, OverflowingResponseCodeStreamError) {
#ifdef ENVOY_ENABLE_UHV
// TODO(#24945): In UHV case this test breaks in the CONNECT/upgrade normalization code in H/2
// codec
if (upstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
#endif
// For H/1 this test is equivalent to OverflowingResponseCode
if (upstreamProtocol() == Http::CodecType::HTTP1) {
return;
Expand All @@ -1927,13 +1913,6 @@ TEST_P(ProtocolIntegrationTest, OverflowingResponseCodeStreamError) {
}

TEST_P(ProtocolIntegrationTest, MissingStatus) {
#ifdef ENVOY_ENABLE_UHV
// TODO(#24945): In UHV case this test breaks in the CONNECT/upgrade normalization code in H/2
// codec
if (upstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
#endif
initialize();

// HTTP1, uses a defined protocol which doesn't split up messages into raw byte frames
Expand Down Expand Up @@ -1973,13 +1952,6 @@ TEST_P(ProtocolIntegrationTest, MissingStatus) {
}

TEST_P(ProtocolIntegrationTest, MissingStatusStreamError) {
#ifdef ENVOY_ENABLE_UHV
// TODO(#24945): In UHV case this test breaks in the CONNECT/upgrade normalization code in H/2
// codec
if (upstreamProtocol() != Http::CodecType::HTTP1) {
return;
}
#endif
// For H/1 this test is equivalent to MissingStatus
if (upstreamProtocol() == Http::CodecType::HTTP1) {
return;
Expand Down