我正在使用 antisamy 库来针对 XSS 清理我的应用程序的输入。我对嵌套标签有疑问,例如:
<<b>script>alert('xss');<</b>/script>
我的消毒方法如下所示:
public String clean(String input) {
if (input == null) {
return null;
}
input = StringEscapeUtils.unescapeHtml(input);
try {
Policy policy = Policy.getInstance(getClass().getResourceAsStream("/antisamy-textonly-policy.xml"));
AntiSamy antiSamy = new AntiSamy();
CleanResults cleanResults = antiSamy.scan(input, policy);
String cleaned = cleanResults.getCleanHTML();
return StringEscapeUtils.unescapeHtml(cleaned);
} catch (PolicyException e) {
....
} catch (ScanException e) {
....
}
}
我对这种类型的输入的测试失败了:
public void doubleTagTest() {
def cleaned = xss.clean("<<b>script>alert('xss');<</b>/script>");
assert cleaned.isEmpty();
}
和:
断言失败:断言已清理.isEmpty() | | | 误报('xss');
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:386)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:658)
你知道如何在没有递归调用的情况下处理它xss.clean()
吗?