Skip to content
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

fix: Sanitize custom metadata #138

Merged
merged 2 commits into from
Nov 15, 2019
Merged

Conversation

alce
Copy link
Collaborator

@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.

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