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

Add preprocessing to headers before running filter #2327

Open
aviramha opened this issue Mar 28, 2024 · 2 comments
Open

Add preprocessing to headers before running filter #2327

aviramha opened this issue Mar 28, 2024 · 2 comments

Comments

@aviramha
Copy link
Member

Following https://discord.com/channels/933706914808889356/1222476910370750534

User has a case where there's JWT passing as a header, and they want to filter based on the content of the base64-encoded JWT.

Possible solutions

Preprocess base64 only

In this solution, we split header_filter into Simple vs Advanced where in advanced user can specify what kind of preprocessing to do to a specific value of a header name. The filter then is running against the value only.
Example:

{
  "feature": {
    "network": {
      "incoming": {
        "mode": "steal",
        "http_filter": {
          "header_filter": {
            "preprocess": "base64",
            "name": "X-Auth-Claims",
            "filter": "email.+example.com"
          }
        }
      }
    }
  },
}

Drawbacks

  • Regexing a JSON is a bit clumsy, but possible.

JWT Specific filter

In this solution, we add a new option under http_filter called jwt_filter.
The jwt_filter accepts a header to obtain the JWT header name to be used, then a JSONPath for value to filter, and regex to run against the value.
Example:

{
    "feature":
    {
        "network":
        {
            "incoming":
            {
                "mode": "steal",
                "http_filter": {
                  "jwt_filter": {
                    "header_name": "X-Auth-Claims",
                    "key": "user.email",
                    "filter": "[email protected]$"
                  }
                }
            }
        }
    }
}

Would filter when JWT has the following format (after decoding):

{"user": {"email": "[email protected]"}}

Drawbacks

  • More specific implementation, fits JWT only.
@muenchdo
Copy link

What do you think about merging both solution options into something like this?

{
  "feature": {
    "network": {
      "incoming": {
        "mode": "steal",
        "http_filter": {
          "header_filter": {
            "preprocess": "(base64|jwt)",
            "jsonPath": "user.email", # optional, default filter to regex if not present 
            "filter": "[email protected]"
[...]
}

@aviramha
Copy link
Member Author

In terms of flexibility/customization it is a nice option, but would make the filter display (in mirrord operator status) a bit difficult to understand.
I think the UX around the 2nd solution would be best and also simple.

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

No branches or pull requests

2 participants