antisamy java_antisamy的使用方法

标 题: 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路径

86b57d7456e4df1a20f7411e1b59d7d6.png

输入测试代码

pageEncoding="UTF-8"%>

Insert title here

String 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<>

输出时被转义

f5eabdb337aecce7bb50d0eaabcfbaf4.png 输入test

被白名单过滤

100825_hrIZ_866512.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值