3

Does JSON Jackson Library have JSON Sanitizing capability like the OWASP JSON Sanitizer ? I went through Jackson documentation but, couldn't find any reference about it. It only talks about Streaming, Traversing and Binding of JSON data and nothing about sanitizing or similar functionality.

Could someone please confirm.

I need a library that can check the JSON data for any malicious or vulnerable content/code.

4

1 回答 1

1

这种消毒是什么意思?您链接到的页面实际上并没有解释它应该做什么。但我猜测它将用于验证输入是有效的 JSON,而不是类似于 JSON 的东西,例如 Javascript 代码。

现在:如果想法是获取声称是 JSON 的任意内容,您可以在流模式下使用 Jackson 来读取然后写入内容。自杰克逊以来:

  1. 只接受有效的 JSON(而不是,例如,可执行的 Javascript),并且
  2. 只生成格式良好的有效 JSON

阅读+写作的结合应该净化输入。您可以执行以下操作:

JsonFactory f = new JsonFactory();
JsonParser p = f.createParser(inputFile);
JsonGenerator g = f.createGenerator(outputFile);

while (p.nextToken() != null) {
  g.copyCurrentStructure(p);
}
p.close();
g.close();

这是确保无效内容不会通过系统的一种非常快速的方法。

于 2015-04-24T22:57:26.487 回答