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

http, utility: Allow to optionally decode the parsed param value when parsing query string #11795

Merged
merged 19 commits into from
Jul 10, 2020

Conversation

dio
Copy link
Member

@dio dio commented Jun 29, 2020

Commit Message: This introduces parseAndDecodeQueryString method to parse the URL into percent-decoded query params.

Additional comments: Especially for fixing the Prometheus handler decoding problem as mentioned in #10926.

Risk Level: Low
Testing: Unit
Docs Changes: N/A
Release Notes: N/A
Fixes #10926

Signed-off-by: Dhi Aurrahman dio@tetrate.io

dio added 3 commits June 29, 2020 20:15
This makes sure we do URL decoding when parsing query string.

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@dio dio changed the title http, utility: Do URL decoding when parsing query string http, utility: Optionally do URL decoding when parsing query string Jun 29, 2020
@dio
Copy link
Member Author

dio commented Jun 30, 2020

/azp run envoy-presubmit

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dio dio changed the title http, utility: Optionally do URL decoding when parsing query string http, utility: Introduce Utility::parseAndDecodeQueryString Jul 5, 2020
}

start++;
return parseParameters(PercentEncoding::decode(StringUtil::subspan(url, start, url.size())), 0);
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I apologize. I read this code incorrectly the first time. I thought we could just implement this method as:

return PercentEncoding::decode(parseQueryString(url))

I see now that's percent-decoding the params and then parsing them.

Doesn't this have a bug? If I pass query params with a percent-encoded & (e.g. x=a%26b) then decoding before splitting parameters will split in the wrong location, yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right! Will fix this while waiting for the chance to use GURL (#11670) to arrive.

dio added 2 commits July 8, 2020 06:57
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@dio dio changed the title http, utility: Introduce Utility::parseAndDecodeQueryString http, utility: Allow to optionally decode the parsed param value when parsing query string Jul 8, 2020
dio added 4 commits July 8, 2020 08:04
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
params.emplace(StringUtil::subspan(data, start, start + equal),
StringUtil::subspan(data, start + equal + 1, end));
decode_param_value ? PercentEncoding::decode(param_value) : param_value);
Copy link
Member

Choose a reason for hiding this comment

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

Should decode param names as well?

@@ -264,22 +264,23 @@ std::string Utility::createSslRedirectPath(const RequestHeaderMap& headers) {
return fmt::format("https://{}{}", headers.getHostValue(), headers.getPathValue());
}

Utility::QueryParams Utility::parseQueryString(absl::string_view url) {
Utility::QueryParams Utility::parseQueryString(absl::string_view url, bool decode_param_value) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, but I still think the separate methods was easier to read.

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Ok, last thing.

@@ -490,7 +490,7 @@ bool RouteEntryImplBase::matchRoute(const Http::RequestHeaderMap& headers,
matches &= Http::HeaderUtility::matchHeaders(headers, config_headers_);
if (!config_query_parameters_.empty()) {
Http::Utility::QueryParams query_parameters =
Http::Utility::parseQueryString(headers.getPathValue());
Http::Utility::parseAndDecodeQueryString(headers.getPathValue());
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 can make this the default, but I think we probably need a runtime flag to disable this for people who are matching values with percent encoding enabled.

Same applies to the other filters. I think it's ok to change the behavior in the admin handlers.

Copy link
Member Author

Choose a reason for hiding this comment

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

@zuercher I'll revert the change to places outside admin handler for now and do runtime flagging in different PR. WDYT?

@dio dio merged commit cb03985 into envoyproxy:master Jul 10, 2020
scheler pushed a commit to scheler/envoy that referenced this pull request Aug 4, 2020
…oyproxy#11795)

This introduces `parseAndDecodeQueryString` method to parse the URL into percent-decoded query params. Especially for fixing the Prometheus handler decoding problem as mentioned in envoyproxy#10926.

Risk Level: Low
Testing: Unit
Fixes envoyproxy#10926

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: scheler <santosh.cheler@appdynamics.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.

Envoy /stats/prometheus?filter not working with prometheus due to url percent encoding.
2 participants