fix uhv underscore header sanitization use-after-free path#44086
Open
Achieve3318 wants to merge 1 commit intoenvoyproxy:mainfrom
Open
fix uhv underscore header sanitization use-after-free path#44086Achieve3318 wants to merge 1 commit intoenvoyproxy:mainfrom
Achieve3318 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. |
Use owning header-name copies when collecting underscore headers to drop, 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>
c30712d to
a5a0ba6
Compare
Author
|
hi, @paul-r-gall Please review my PR |
wbpcode
reviewed
Mar 25, 2026
Comment on lines
+637
to
+644
| // 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); |
Member
There was a problem hiding this comment.
rather than keep a copy, could we keep header name in a absl::flat_hash_set?
Member
|
/wait |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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