Skip to content

router/stats: handle invalid regexes in config#2420

Merged
zuercher merged 3 commits intoenvoyproxy:masterfrom
turbinelabs:stephan/2406-now-you-have-three-problems
Jan 22, 2018
Merged

router/stats: handle invalid regexes in config#2420
zuercher merged 3 commits intoenvoyproxy:masterfrom
turbinelabs:stephan/2406-now-you-have-three-problems

Conversation

@zuercher
Copy link
Copy Markdown
Member

Description:
The Envoy API accepts regular expressions for several configuration options. If an invalid regular expression is provided, STL throws std::regex_error, which is uncaught and causes the sudden termination of Envoy. Replace use of the std::regex(std::string) constructor with calls to a new utility RegexUtil::parseRegex() which converts the std::regex_error into an EnvoyException, allowing the invalid configuration to be handled gracefully.

Risk Level: Low

Testing:
Unit tests for behavior or new utility function and testing of invalid regular expressions in configuration.

Release Notes: N/A

Fixes: #2406

Signed-off-by: Stephan Zuercher stephan@turbinelabs.io

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Awesome thanks, tiny nit.

std::regex RegexUtil::parseRegex(const std::string& regex, std::regex::flag_type flags) {
try {
return std::regex(regex, flags);
} catch (std::regex_error& e) {
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.

nit: const

}

std::regex RegexUtil::parseRegex(const std::string& regex, std::regex::flag_type flags) {
try {
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.

Nit: I think ideally this would be caught by PGV (https://github.com/lyft/protoc-gen-validate) annotations. The language allows one to express regex validity (e.g. https://github.com/lyft/protoc-gen-validate/blob/6cd364ac742e088e22c2d04e90358ce48e1e33e5/validate/validate.proto#L478).

However, this is not yet implemented for C++, and what form the regexes checking should take is unclear (do we really want RE2?).

@rodaine @akonradi for context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not clear to me that one can write a regular expression to validate that a string is a well-formed regular expression (given arbitrarily nested groups and depending on the library in use). But perhaps PGV will add a well-known rule for regular expressions in the future. I'll add a TODO.

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.

@zuercher I like that idea. Right now (since it's written in Go), it expects RE2 syntax, would need to do some work to support other formats.

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.

Umm, yes, I think I may have linked to the wrong thing. The idea is not to validate a regex with a regex, but to add support in PGV to validate that REs are valid.

htuch
htuch previously approved these changes Jan 22, 2018
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo nit. Maybe add a TODO explaining the PGV connection if you are making any further edit.

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
@mattklein123
Copy link
Copy Markdown
Member

@zuercher FWIW I've seen OSX flaking more often lately. Not sure if it's worth taking a look into.

@zuercher zuercher merged commit 3122ee8 into envoyproxy:master Jan 22, 2018
@zuercher zuercher deleted the stephan/2406-now-you-have-three-problems branch January 22, 2018 20:04
@zuercher
Copy link
Copy Markdown
Member Author

Filed #2428

jpsim pushed a commit that referenced this pull request Nov 28, 2022
Fix isCleartextTrafficPermitted by finding a static method (instead of an object method) and calling
the static method of the AndroidNetworkLibrary class instead of calling the instance method on a string.

Signed-off-by: Ryan Hamilton <rch@google.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Fix isCleartextTrafficPermitted by finding a static method (instead of an object method) and calling
the static method of the AndroidNetworkLibrary class instead of calling the instance method on a string.

Signed-off-by: Ryan Hamilton <rch@google.com>
Signed-off-by: JP Simard <jp@jpsim.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.

4 participants