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

Obfuscate json body fields using json path or json pointer #1641

Closed
karim-elngr opened this issue Oct 5, 2023 · 1 comment
Closed

Obfuscate json body fields using json path or json pointer #1641

karim-elngr opened this issue Oct 5, 2023 · 1 comment
Labels

Comments

@karim-elngr
Copy link

I would like to propose a new change to allow to obfuscate json body fields by specifying a json pointer such as /child/elem

Detailed Description

I am proposing a new change so that we can provide the following configuration

logbook:
  obfuscate:
    json-body-fields:
      - /user/name/
    replacement: ZZZ

Which will obfuscate the following payload without issues

{
  "user": {
    "name": "karim"
  },
  "resource": {
    "name": "resource name"
  }
}

Into

{
  "user": {
    "name": "ZZZ"
  },
  "resource": {
    "name": "resource name"
  }
}

Context

This change is useful because currently we are only able to obfuscate by providing name of the field without context about its location so for example we obfuscate all fields with name name instead of only obfuscating the /user/name

Possible Implementation

Changing the implementation of JacksonJsonFieldBodyFilter::filter to JacksonJsonFieldBodyFilter - L63

if (nextToken == JsonToken.FIELD_NAME && fields.contains(parser.getParsingContext().pathAsPointer().toString())) {

Your Environment

  • Version used: 3.5.0
@whiskeysierra
Copy link
Collaborator

by specifying a json pointer

I'm not sure a JSON Pointer is the right tool here. A JSON Pointer will always uniquely identify a single node within the JSON tree. As soon as you have arrays you end up in a situation where you can't say something like /users/*/name.

More powerful, for this use case, is JSON Path - for which Logbook already has support: https://github.com/zalando/logbook#jsonpath-body-filtering-experimental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants