如何在与他人共享之前从 HAR 文件中删除 Cookie 值

问题描述

使用 HAR 文件诊断 Web 应用程序很常见,尤其是在向他人寻求技术支持时。但是,HAR 文件包含请求 cookie 等敏感信息。例如,如果遵循 this guide,如果未清理 HAR 文件,它可以将 cookie 值共享给技术支持

所以我更喜欢在共享 HAR 文件之前删除请求 cookie。

有什么简单的命令可以做到吗?

解决方法

不加选择地删除所有 request.cookies:

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

举个例子,给定这个 JSON 文件:

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

我可以用这个命令去掉所有的“bar”键:

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

通过 diff 运行之前和之后:

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

如果我只想摆脱'.foo.bar',我会用这个:

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

再次运行 diff 给我们:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...