-
Notifications
You must be signed in to change notification settings - Fork 5.3k
H/2: discard Host header when :authority is present #30005
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2129,6 +2129,18 @@ int ServerConnectionImpl::onHeader(const nghttp2_frame* frame, HeaderString&& na | |
| // For a server connection, we should never get push promise frames. | ||
| ASSERT(frame->hd.type == NGHTTP2_HEADERS); | ||
| ASSERT(frame->headers.cat == NGHTTP2_HCAT_REQUEST || frame->headers.cat == NGHTTP2_HCAT_HEADERS); | ||
| if (Runtime::runtimeFeatureEnabled("envoy.reloadable_features.http2_discard_host_header")) { | ||
| StreamImpl* stream = getStreamUnchecked(frame->hd.stream_id); | ||
| if (stream && name == static_cast<absl::string_view>(Http::Headers::get().HostLegacy)) { | ||
| // Check if there is already the :authority header | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The http2 spec says that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct. I have added a test to validate this. |
||
| const auto result = stream->headers().get(Http::Headers::get().Host); | ||
| if (!result.empty()) { | ||
| // Discard the host header value | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding of https://www.rfc-editor.org/rfc/rfc9113#section-8.3.1 is that discarding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the statements related to the server:
Note that Envoy can not have both :authority and Host headers in the header map, they are treated as one and the same. As a result discarding the Host header is compliant with RFC.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You got me convinced. I agree it makes sense to remove the header and protect it with a runtime flag. |
||
| return 0; | ||
| } | ||
| // Otherwise use host value as :authority | ||
| } | ||
| } | ||
| return saveHeader(frame, std::move(name), std::move(value)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, maybe move this check above the line 2131
envoy/source/common/http/http2/codec_impl.cc
Lines 1474 to 1484 in 518c582
although not sure that check still available for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saveHeaderis called from two places. I would need to duplicate this check. Maybe it is is better to keep it in one place only.