springMVC中的xss攻击

最近系统安全升级,然后第三方安全检测公司检测出系统中有接口存在存储型跨站漏洞,网上查了下,说是xss攻击漏洞。现在给系统添加XssFilter相关的代码配置,但是不知道添加了Filter后的代码能否预防xss攻击。而我在网上找的都是如何防范xss的攻击,请问该如何测试模拟springMVC中的xss攻击呢?

还可以在页面输入框中输入任何 html 页面元素,如能被后台拦截,说明防护是成功的,例如:

<button value="测试"/>

如果提交后提示错误或者,回显时被转义掉了,就说明没问题。否则页面回显时可能某项信息就是一个可视的按钮了。

在添加数据的地方输入:

<script>alert(123)</script>

,然后提交保存到数据库,刷新页面,查看刚刚的那条数据

问题解决了,是我局限与一个接口中了,其实如何系统中存在xss攻击漏洞的话,那么这个漏洞将是针对整个系统的。然后我找了个有输入框的接口,输入如“alert(&#39;xss&#39;)”这样的代码后,如果访问调用后的接口有弹框显示“xss”则说明系统存在此漏洞。没有则表示系统有过滤掉“script”之类的标签功能。
为了帮助后来者,这里说明下我的系统是如何处理的xss攻击漏洞:
创建一个XssFilter(类名你可以自定义的)Filter实现类,其中的关键代码如下(同时感谢一下回答我问题的朋友们)

private static List<Object[]> getXssPatternList()
    {
        List<Object[]> ret = new ArrayList<Object[]>();

        ret.add(new Object[]{"<(no)?script[^>]*>.*?</(no)?script>", Pattern.CASE_INSENSITIVE});
        ret.add(new Object[]{"</script>", Pattern.CASE_INSENSITIVE});
        ret.add(new Object[]{"<script(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        ret.add(new Object[]{"eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        ret.add(new Object[]{"expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        ret.add(new Object[]{"(javascript:|vbscript:|view-source:)*", Pattern.CASE_INSENSITIVE});
        ret.add(new Object[]{"<(\"[^\"]*\"|\'[^\']*\'|[^\'\">])*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        ret.add(new Object[]{"(window\\.location|window\\.|\\.location|document\\.cookie|document\\.|alert\\(.*?\\)|window\\.open\\()*", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        ret.add(new Object[]{"<+\\s*\\w*\\s*(oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondblclick|ondeactivate|ondrag|ondragend|ondragenter|ondragleave|ondragover|ondragstart|ondrop|onerror=|onerroupdate|onfilterchange|onfinish|onfocus|onfocusin|onfocusout|onhelp|onkeydown|onkeypress|onkeyup|onlayoutcomplete|onload|onlosecapture|onmousedown|onmouseenter|onmouseleave|onmousemove|onmousout|onmouseover|onmouseup|onmousewheel|onmove|onmoveend|onmovestart|onabort|onactivate|onafterprint|onafterupdate|onbefore|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onblur|onbounce|oncellchange|onchange|onclick|oncontextmenu|onpaste|onpropertychange|onreadystatechange|onreset|onresize|onresizend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onselect|onselectionchange|onselectstart|onstart|onstop|onsubmit|onunload)+\\s*=+",
                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL});
        return ret;
    }

不局限与一个接口中,学到了。