fix uhv underscore header sanitization use-after-free path#44086
fix uhv underscore header sanitization use-after-free path#44086Achieve3318 wants to merge 1 commit intoenvoyproxy:mainfrom
Conversation
|
Hi @Achieve3318, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
c30712d to
a5a0ba6
Compare
|
hi, @paul-r-gall Please review my PR |
| // Store owning copies because removing one duplicate header can free the | ||
| // underlying storage for another matching entry. | ||
| std::vector<std::string> drop_headers; | ||
| header_map.iterate([&drop_headers](const ::Envoy::Http::HeaderEntry& header_entry) | ||
| -> ::Envoy::Http::HeaderMap::Iterate { | ||
| const absl::string_view header_name = header_entry.key().getStringView(); | ||
| if (absl::StrContains(header_name, '_')) { | ||
| drop_headers.push_back(header_name); | ||
| drop_headers.emplace_back(header_name); |
There was a problem hiding this comment.
rather than keep a copy, could we keep header name in a absl::flat_hash_set?
|
/wait |
a5a0ba6 to
18b230a
Compare
|
@wbpcode Please review my PR again. Thank your for your review |
| // Store owning copies because removing one duplicate header can free the | ||
| // underlying storage for another matching entry. We only need unique names. | ||
| absl::flat_hash_set<std::string> drop_headers; | ||
| header_map.iterate([&drop_headers](const ::Envoy::Http::HeaderEntry& header_entry) | ||
| -> ::Envoy::Http::HeaderMap::Iterate { | ||
| const absl::string_view header_name = header_entry.key().getStringView(); | ||
| if (absl::StrContains(header_name, '_')) { | ||
| drop_headers.push_back(header_name); | ||
| drop_headers.emplace(header_name); |
There was a problem hiding this comment.
Sorry, I may didn't make it clear. I mean use an absl::flat_hash_set<absl::string_view> drop_headers; to keep the header key, then I think it should also could eliminate the use-after-free?
Use owning underscore header names while sanitizing, and keep names unique via absl::flat_hash_set so duplicate header removals cannot read dangling views. Add HTTP/1 and HTTP/2 regression coverage for duplicate underscore header names. Signed-off-by: Achieve3318 <daniel98518@gmail.com>
18b230a to
88a8949
Compare
|
@wbpcode , Sorry for my mistake. I have fixed again. please check again. Thank you |
Summary
This PR fixes a potential use-after-free path in underscore-header sanitization for Envoy default UHV when
headers_with_underscores_actionisDROP_HEADER.In
sanitizeHeadersWithUnderscores(), header names were collected as non-owningabsl::string_viewvalues and then removed from the same header map. With duplicate underscore headers (for example,x_fooappearing multiple times), removing one header can invalidate storage referenced by later views.This change stores owning copies of header names (
std::string) before mutation, preventing reads from dangling references during removal.Fixes: #44032
Changes
source/extensions/http/header_validators/envoy_default/header_validator.ccstd::vector<absl::string_view>withstd::vector<std::string>push_back(header_name)withemplace_back(header_name)test/extensions/http/header_validators/envoy_default/http1_header_validator_test.cctest/extensions/http/header_validators/envoy_default/http2_header_validator_test.ccTest Plan
//test/extensions/http/header_validators/envoy_default:http1_header_validator_test//test/extensions/http/header_validators/envoy_default:http2_header_validator_test