【发布时间】: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