-
Notifications
You must be signed in to change notification settings - Fork 5.3k
HCM: protect against removal of critical response headers by a filter chain. #16745
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
9da66e0
6ad8f4b
fd491bf
b09c2d7
937bc2c
7953e30
1430cd8
46d285a
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -198,13 +198,20 @@ class HeaderUtility { | |||||||||
| */ | ||||||||||
| static absl::string_view::size_type getPortStart(absl::string_view host); | ||||||||||
|
|
||||||||||
| /* Does a common header check ensuring required headers are present. | ||||||||||
| /* Does a common header check ensuring required request headers are present. | ||||||||||
| * Required request headers include :method header, :path for non-CONNECT requests, and | ||||||||||
| * host/authority for HTTP/1.1 or CONNECT requests. | ||||||||||
| * @return Status containing the result. If failed, message includes details on which header was | ||||||||||
| * missing. | ||||||||||
| */ | ||||||||||
| static Http::Status checkRequiredHeaders(const Http::RequestHeaderMap& headers); | ||||||||||
| static Http::Status checkRequiredRequestHeaders(const Http::RequestHeaderMap& headers); | ||||||||||
|
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. I hear your point about calling this from the codec being really messy.
Member
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. In order to do so, we should eliminate all the usage of
I think fixing this is worth a separate PR and discussion, so can I open an issue for now and discuss there?
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. SGTM, and as it's optional don't feel obliged to tackle it (though it would be nice!) |
||||||||||
|
|
||||||||||
| /* Does a common header check ensuring required response headers are present. | ||||||||||
| * Current required response headers only includes :status. | ||||||||||
| * @return Status containing the result. If failed, message includes details on which header was | ||||||||||
| * missing. | ||||||||||
| */ | ||||||||||
| static Http::Status checkRequiredResponseHeaders(const Http::ResponseHeaderMap& headers); | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Returns true if a header may be safely removed without causing additional | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "envoy/registry/registry.h" | ||
| #include "envoy/server/filter_config.h" | ||
|
|
||
| #include "extensions/filters/http/common/pass_through_filter.h" | ||
|
|
||
| #include "test/extensions/filters/http/common/empty_http_filter_config.h" | ||
| #include "test/integration/filters/common.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
||
| // Registers the misbehaving filter which removes all response headers. | ||
| class RemoveResponseHeadersFilter : public Http::PassThroughFilter { | ||
| public: | ||
| constexpr static char name[] = "remove-response-headers-filter"; | ||
| Http::FilterHeadersStatus encodeHeaders(Http::ResponseHeaderMap& headers, bool) override { | ||
| std::vector<std::string> keys; | ||
| headers.iterate([&keys](const Http::HeaderEntry& header) -> Http::HeaderMap::Iterate { | ||
| keys.push_back(std::string(header.key().getStringView())); | ||
| return Http::HeaderMap::Iterate::Continue; | ||
| }); | ||
| for (auto& k : keys) { | ||
| const Http::LowerCaseString lower_key{k}; | ||
| headers.remove(lower_key); | ||
| } | ||
| return Http::FilterHeadersStatus::Continue; | ||
| } | ||
| }; | ||
|
|
||
| static Registry::RegisterFactory<SimpleFilterConfig<RemoveResponseHeadersFilter>, | ||
| Server::Configuration::NamedHttpFilterConfigFactory> | ||
| register_; | ||
|
|
||
| } // namespace Envoy |
Uh oh!
There was an error while loading. Please reload this page.