【问题标题】:How to encode response to JSON in filter without failing XSS如何在不失败 XSS 的情况下在过滤器中编码对 JSON 的响应
【发布时间】:2018-09-19 09:42:45
【问题描述】:

以下是来自 SpotBugs 的静态代码分析报告

XSS_SERVLET:Servlet 中的潜在 XSS 发现了一个潜在的 XSS。它可用于在客户端浏览器中执行不需要的 JavaScript。 (见参考资料)

易受攻击的代码:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
String input1 = req.getParameter("input1");
[...]
resp.getWriter().write(input1);
}

解决方案:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)     throws ServletException, IOException {
    String input1 = req.getParameter("input1");
    [...]
    resp.getWriter().write(Encode.forHtml(input1))

Encode.forJava for JavaScript 正在编写特殊字符,而 JSON 字符串被泄露。

如何使用 Encoder 发送 JSON 字符串。没有失败的安全检查

【问题讨论】:

  • 我可以使用 HandlerInterceptor 代替 Filter 吗?

标签: spring spring-mvc security owasp spotbugs


【解决方案1】:

也许你可以看看 OWASP JSON sanitizer https://www.owasp.org/index.php/OWASP_JSON_Sanitizer#tab=Main ?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多