Skip to content

fix: Sanitize custom metadata#138

Merged
LucioFranco merged 2 commits intohyperium:masterfrom
alce:reserved-headers
Nov 15, 2019
Merged

fix: Sanitize custom metadata#138
LucioFranco merged 2 commits intohyperium:masterfrom
alce:reserved-headers

Conversation

@alce
Copy link
Contributor

@alce alce commented Nov 13, 2019

Motivation

Tonic's MetadataMap prevents entries with invalid or reserved HTTP2 header names to be inserted but does not disallow headers reserved by the gRPC protocol.

The metadata map is then copied verbatim to HTTP headers and written the wire. Some headers may be updated by inserting new values but some will be written as-is.

Solution

This patch prevents a small set of headers to be written when sending requests or responses. It does not panic or returns errors if entries with these names are added to the metadata map, it just won't copy them to http request or responses.

///
/// assert!(http_map.get("grpc-timeout").is_none());
/// ```
pub fn into_sanitized_headers(mut self) -> http::HeaderMap {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should probably make this pub(crate) for now? Like we do with into http in request/response.

@alce alce requested a review from LucioFranco November 14, 2019 23:51
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Perfect thanks!

@LucioFranco LucioFranco changed the title Sanitize custom metadata fix: Sanitize custom metadata Nov 15, 2019
@LucioFranco LucioFranco merged commit f9502df into hyperium:master Nov 15, 2019
@alce alce deleted the reserved-headers branch November 15, 2019 14:21
rabbitinspace pushed a commit to satelit-project/tonic that referenced this pull request Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants