Skip to content

Support full decoding of reserved expansions#45

Merged
qiwzhang merged 7 commits intogrpc-ecosystem:masterfrom
euroelessar:fully-decode
Nov 13, 2020
Merged

Support full decoding of reserved expansions#45
qiwzhang merged 7 commits intogrpc-ecosystem:masterfrom
euroelessar:fully-decode

Conversation

@euroelessar
Copy link
Copy Markdown
Contributor

Implement underlying logic for google.api.Http.fully_decode_reserved_expansion.
Add a configurable option to always decode all path and query bindings.

Fixes #44

// For multipart matches only unescape non-reserved characters.
binding.value += UrlUnescapeString(parts[i], !is_multipart);
binding.value += UrlUnescapeString(
parts[i], fully_decode_reserved_expansion || !is_multipart);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, we should not decode %2F even with fully_decode_reserved_expansion_

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, not decoding everything beats the purpose of this change..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Depends on how we set this flag fully_decode_reserved_expansion_? If it is from option.http, I think we should follow it.
At least its comment clearly say so.

We can add a flag in envoy grpc_transcode filter_config, as always_decode_reserved_. it may serve your purpose. I will go for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since you are here, maybe we can support both:

  1. one from proto file option.http, and 2) one from grpc_trancode filter_config.

since they are mutually exclusive, we can do: if 2) exists, don't use 1), otherwise check 1).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, let me rename the function/field with corresponding docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Works for me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added support for both options, covered logic of all their combinations by tests

return os;
}

} // namespace
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: this is unrelated change, but it fixes pretty debug printing of Binding type in gtest (operator<< must be in the same namespace as the type it covers).

//
// The default behavior is to not decode RFC 6570 reserved characters in multi
// segment matches.
void SetFullyDecodeReservedExpansion(bool value) {
Copy link
Copy Markdown
Member

@qiwzhang qiwzhang Nov 13, 2020

Choose a reason for hiding this comment

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

  1. I like the names to be more specific for readability. how about UrlUnescapeSpec?

  2. These two bools are mutual exclusive, Can we combine them into one flag with an enum value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated

TEST_F(PathMatcherTest,
OnlyUnreservedCharsAreUnescapedForMultiSegmentMatchAlwaysDecode) {
SetFullyDecodeReservedExpansion(true);
// All %XX are reserved characters, they should be decoded.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

comment is wrong, slash is not be decoded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated

@grpc-ecosystem grpc-ecosystem deleted a comment from euroelessar Nov 13, 2020
always_decode_);
ExtractBindingsFromPath(
method_data->variables, parts, variable_bindings,
unescape_spec_ == UrlUnescapeSpec::kAllCharacters ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should not use two arguments to control one aspect. We should just one one argument. Same as UrlUnescape function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Passed UrlUnescapeSpec all the way through.

@qiwzhang
Copy link
Copy Markdown
Member

Cool, just one minor request.

bool unescape_reserved_chars, bool unescape_slash_char,
char* out) {
UrlUnescapeSpec unescape_spec, char* out) {
const bool unescape_slash_char =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the code readability is bad, you are converting an enum type into two bool, inside the loop, can we just use switch() on the spec. and handle it accordingly. the code will be much easier to read

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

great point, addressed

Copy link
Copy Markdown
Member

@qiwzhang qiwzhang left a comment

Choose a reason for hiding this comment

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

Very good. Thanks

@qiwzhang qiwzhang merged commit 4d095f0 into grpc-ecosystem:master Nov 13, 2020
@qiwzhang
Copy link
Copy Markdown
Member

@euroelessar Thanks for the PR. You need to update envoy dependent to get this change and hook it up. Thanks

htuch pushed a commit to envoyproxy/envoy that referenced this pull request Nov 17, 2020
…#14009)

Functionality is implemented in grpc-ecosystem/grpc-httpjson-transcoding#45, add configuration options and wire them into filter.

The reasoning is provided in grpc-ecosystem/grpc-httpjson-transcoding#44.

Risk Level: Low
Testing: added unit test
Docs Changes: added proto docs
Release Notes: updated

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
lizan pushed a commit to envoyproxy/data-plane-api that referenced this pull request Nov 17, 2020
… (#14009)

Functionality is implemented in grpc-ecosystem/grpc-httpjson-transcoding#45, add configuration options and wire them into filter.

The reasoning is provided in grpc-ecosystem/grpc-httpjson-transcoding#44.

Risk Level: Low
Testing: added unit test
Docs Changes: added proto docs
Release Notes: updated

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>

Mirrored from https://github.com/envoyproxy/envoy @ 39e43e1abb45c96993f2df3323df12bc94937910
andreyprezotto pushed a commit to andreyprezotto/envoy that referenced this pull request Nov 24, 2020
…envoyproxy#14009)

Functionality is implemented in grpc-ecosystem/grpc-httpjson-transcoding#45, add configuration options and wire them into filter.

The reasoning is provided in grpc-ecosystem/grpc-httpjson-transcoding#44.

Risk Level: Low
Testing: added unit test
Docs Changes: added proto docs
Release Notes: updated

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
qqustc pushed a commit to qqustc/envoy that referenced this pull request Nov 24, 2020
…envoyproxy#14009)

Functionality is implemented in grpc-ecosystem/grpc-httpjson-transcoding#45, add configuration options and wire them into filter.

The reasoning is provided in grpc-ecosystem/grpc-httpjson-transcoding#44.

Risk Level: Low
Testing: added unit test
Docs Changes: added proto docs
Release Notes: updated

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
Signed-off-by: Qin Qin <qqin@google.com>
rexengineering pushed a commit to rexengineering/istio-envoy that referenced this pull request Oct 15, 2021
… (#14009)

Functionality is implemented in grpc-ecosystem/grpc-httpjson-transcoding#45, add configuration options and wire them into filter.

The reasoning is provided in grpc-ecosystem/grpc-httpjson-transcoding#44.

Risk Level: Low
Testing: added unit test
Docs Changes: added proto docs
Release Notes: updated

Signed-off-by: Ruslan Nigmatullin <elessar@dropbox.com>
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.

UrlUnescapeString irreversabily transforms data

2 participants