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路径

输入测试代码
 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page language="java" import="org.owasp.validator.html.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
 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);
%>
</body>
</html>

id输入test<>


输出时被转义
输入test<script>

被白名单过滤

转载于:https://my.oschina.net/backtract/blog/133625

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值