Skip to content

Introduce New header match type to avoid Regex - Contains #12590

@shivanshu21

Description

@shivanshu21

Title: Introduce New header match type to avoid Regex - Contains

Description:
For matching values in the header that might be somewhere in the middle of the header, the present option is to use Regex in the form .*Search-Pattern.*. This can cause catastrophic backtracking as described here:
#7728

As a solution, in our build used in eBay Traffic engineering, we have introduced another header match type called contains which is based on absl::StrContains(). It works well for us.

The API is exactly the same as suffix match for headers:

  |   |   |  
  |   |   | // If specified, header match will be performed based on whether the header value contains
  |   |   | // the value specified in this option.
  |   |   | // Note: empty contains match is not allowed, please use present_match instead.
  |   |   | //
  |   |   | // Examples:
  |   |   | //
  |   |   | // * The contains *abc* matches the value *xyzabcdpqrs*, but not for *xyzbcdpqrs*.
  |   |   | string contains_match = 11 [(validate.rules).string.min_bytes = 1];

Please let me know if this is required/acceptable upstream, I can cherry-pick and raise a PR. Here is a snippet from our change to further illustrate:

   case HeaderMatchType::Contains:
        match = absl::StrContains(header->value().getStringView(), header_data.value_);
        break;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions