标 题: antisamy的使用方法
作 者: 狂逆着风
链 接: http://blog.sina.com.cn/s/blog_47d78bed0100wnrs.html antisamy是owasp的开源项目,它用来确保用户输入的HTML/CSS符合应用规范的API,可以有效防止xss攻击
有.net和java两个版本,.net推荐用antixss来做,请看使用antixss防御xss
antisamy项目地址:
https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project
下载地址:
http://code.google.com/p/owaspantisamy/downloads/list
最新版本下载:http://search.maven.org/ 搜索 antisamy 选择最新版下载即可 我们下载
antisamy-1.4.4.jar
antisamy-required-libs-1.2.zip
antisamy-slashdot-1.4.4.xml
required-libs解压后,所有jar需要导入项目库,我直接拷贝到/web-inf/lib下了,antisamy-1.4.4解压之后的antisamy-1.4.4.jar也拷贝到此目录
策略文件slashdot.xml放入web路径
输入测试代码
pageEncoding="UTF-8"%>
Insert title hereString id_d = request.getParameter("id");
if(id_d == null)
id_d = "";
Policy policy = Policy.getInstance("D:\\antisamy\\antisamy-slashdot-1.4.4.xml");
AntiSamy as = new AntiSamy();
CleanResults cr = as.scan(id_d, policy);
String id = cr.getCleanHTML();
out.println(id);
%>
id输入test<>
输出时被转义
输入test
被白名单过滤