How to remove Cookie value from HAR file before sharing it with another person

Viewed 655

It's common to diagnose web app with HAR file especially when seeking technical support from another person. However, HAR file contains sensitive info like request cookies. For example, if following this guide, it could share cookie values to technical support if HAR file is not cleaned up.

So I prefer deleting request cookies before sharing the HAR file.

Is there any simple command to do it?

1 Answers

To indiscriminately delete all request.cookies:

jq 'del(.. | .request?.cookies?)' www.ibm.com.har

As an example, given this JSON file:

$ jq -M . /tmp/hartest.json
{
  "one": {
    "foo": {
      "bar": true,
      "baz": 23
    }
  },
  "two": {
    "foo": {
      "bar": "Hello",
      "baz": "World"
    }
  },
  "three": {
    "fu": {
      "bar": "gone",
      "baz": "forgotten"
    }
  }
}

I can get rid of all 'bar' keys with this command:

jq -M 'del( .. | .bar?)' /tmp/hartest.json

Running the before and after through diff:

$ diff <(jq -M . /tmp/hartest.json) <(jq -M 'del( .. | .bar?)' /tmp/hartest.json )
4d3
<       "bar": true,
10d8
<       "bar": "Hello",
16d13
<       "bar": "gone",

If I just wanted to get rid of '.foo.bar' only, I would use this:

jq -M 'del( .. | .foo?.bar?)' /tmp/hartest.json

which, again, running through diff gives us:

$ diff <(jq -M . /tmp/hartest.json) <(jq -M 'del( .. | .foo?.bar?)' /tmp/hartest.json )
4d3
<       "bar": true,
10d8
<       "bar": "Hello",
Related