通過在Java項目中添加一個過濾器類對跨腳本攻擊漏洞進行修復,具體方法如下:
public class XssFilter implements Filter {
@Override
public void destroy() {
}
/**
* 過濾器用來過濾的方法
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//包裝request
XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request);
chain.doFilter(xssRequest, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}