-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce safe regex matcher based on re2 engine
The libstdc++ std::regex implementation is not safe in all cases for user provided input. This change deprecates the used of std::regex in all user facing paths and introduces a new safe regex matcher with an explicitly configurable engine, right now limited to Google's re2 regex engine. This is not a drop in replacement for std::regex as all language features are not supported. As such we will go through a deprecation period for the old regex engine. Fixes #7728 Signed-off-by: Matt Klein <[email protected]>
- Loading branch information
1 parent
e03936e
commit ec6e30a
Showing
45 changed files
with
605 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.type.matcher; | ||
|
||
option java_outer_classname = "StringProto"; | ||
option java_multiple_files = true; | ||
option java_package = "io.envoyproxy.envoy.type.matcher"; | ||
option go_package = "matcher"; | ||
|
||
import "validate/validate.proto"; | ||
|
||
// [#protodoc-title: RegexMatcher] | ||
|
||
// A regex matcher designed for safety when used with untrusted input. | ||
message RegexMatcher { | ||
// Google's `re2 <https://github.com/google/re2>`_ regex engine. The regex string must adhere to | ||
// the documented `syntax <https://github.com/google/re2/wiki/Syntax>`_. The engine is designed | ||
// to complete execution in linear time as well as limit the amount of memory used. In the future | ||
// different aspects of the engine may be made configurable. | ||
message GoogleReEngine { | ||
} | ||
|
||
oneof engine_type { | ||
option (validate.required) = true; | ||
|
||
// Google's re2 regex engine. | ||
GoogleReEngine google_re_engine = 1 [(validate.rules).message.required = true]; | ||
} | ||
|
||
// The regex match string. The string must be supported by the configured engine. | ||
string regex = 2 [(validate.rules).string.min_bytes = 1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "envoy/common/pure.h" | ||
|
||
#include "absl/strings/string_view.h" | ||
|
||
namespace Envoy { | ||
namespace Regex { | ||
|
||
/** | ||
* A compiled regex expression matcher which uses an abstract regex engine. | ||
*/ | ||
class CompiledMatcher { | ||
public: | ||
virtual ~CompiledMatcher() = default; | ||
|
||
/** | ||
* @return whether the value matches the compiled regex expression. | ||
*/ | ||
virtual bool match(absl::string_view value) const PURE; | ||
}; | ||
|
||
using CompiledMatcherPtr = std::unique_ptr<const CompiledMatcher>; | ||
|
||
} // namespace Regex | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.