http - Servlet 反射跨站脚本漏洞

标签 http servlets xss findbugs spotbugs

我用 Findbugs 分析了一段代码,它报告了一个警告

servlet reflected cross site scripting vulnerability.

代码就是这样,第三行抛出警告:

String tickName = request.getParameter("ticko");
PrintWriter w = response.getWriter();
w.println("Unable to perform tickonem '" + tickName +"' because no tick with that name is active!"); //this line throws warning.

它的真正原因是什么以及如何解决它?

最佳答案

这样做的原因是将用户提供的数据附加到响应中而不进行任何转义。这很容易注入(inject)将在用户浏览器中执行的 javascript。为避免此类漏洞,您应该在发送回每个用户提供的数据之前对每个用户提供的数据进行 html 转义。您可以使用一些现有的库来为您执行转义,例如 StringEscapeUtils

关于http - Servlet 反射跨站脚本漏洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22899609/

相关文章:

api - REST 风格的 API : Were to put the custom application errors?

rest - 使用 Http Post 发送状态数据是一个好习惯吗?

java - Spring MVC DispatcherServlet 的延迟实例化?

jquery - 如何使用 JSP/Servlet 和 Ajax 将文件上传到服务器?

java - @WebFilter 未在我的 Glassfish 中处理

vue.js - 如何将 Buefy 的 Dialog 组件与用户提供的内容一起使用并确保 XSS 安全

iphone - 如何在防火墙后面的 iPhone 上设置 http 服务器

delphi - 如何在 Delphi 中使用 http 身份验证打开 url?

android - Google Play 警告 : Your app contains a File-based XSS issue? JavaScript 启用 = True

java - 从请求中过滤掉编码的 javascript 内容