我们正在使用fortify来扫描java源代码&它的错误如下:
Method abc() sends unvalidated data to a web browser on line 200, which can result in the browser executing malicious code.我们在第200行有以下代码:
<a href="<%= Util.getProduct(request) %>">Product</a>getProduct方法中的Util.java hsa代码如下:
String prod = request.getParameter("prod");谁能告诉我如何修复这个XSS漏洞?
谢谢!
发布于 2011-11-10 10:22:22
您需要避开Util.getProduct(request)的输出。通常,这是使用JSTL、<c:out>标记和EL完成的:
<a href="<c:out value="${Util.getProduct(request)}"/>" class="left_nav_link">Product</a>要将参数传递给方法,您必须使用相当新的EL实现(根据JSTL or JSP 2.0 EL for getter with argument和Parameters in EL methods)。
由于您的问题中的代码包含scriptlet,我将强烈建议您阅读How to avoid Java code in JSP files?这个问题涵盖了使用JSTL+EL而不是scriptlet的原因,以及关于这两个缩略语实际所指的一些信息。
发布于 2012-01-21 00:12:45
如果您的网站没有JSTL,您可以通过确保只打印有效产品来解决此问题:
public String getProduct( String prod ) throws InputValidationException {
if ( prod.equals( "myProduct1" )
|| prod.equals( "myProduct2" )
|| prod.equals( "myProduct3" )
// etc.
) {
return "/foo/page.jsp?product=" + safeProduct;
}
else {
throw new InputValidationException( "Invalid product key provided." );
}
}https://stackoverflow.com/questions/8074248
复制相似问题