Jsuop Whitelist
Jsuop使用示例代码
使用jsoup HTML Cleaner
方法进行清除,但需要指定一个可配置的 Whitelist
。http://jsoup.org/apidocs/org/jsoup/safety/Whitelist.html (Jsoup whitelist文档)
String unsafe =
"<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>";
String safe = Jsoup.clean(unsafe, Whitelist.basic());
// now: <p><a href="http://example.com/" rel="nofollow">Link</a></p>
public class JsoupUtil { /**
* 使用自带的basicWithImages 白名单
* 允许的便签有a,b,blockquote,br,cite,code,dd,dl,dt,em,i,li,ol,p,pre,q,small,span,
* strike,strong,sub,sup,u,ul,img
* 以及a标签的href,img标签的src,align,alt,height,width,title属性
*/
private static final Whitelist whitelist = Whitelist.basicWithImages();
/** 配置过滤化参数,不对代码进行格式化 */
private static final Document.OutputSettings outputSettings = new Document.OutputSettings().prettyPrint(false);
static {
// 富文本编辑时一些样式是使用style来进行实现的
// 比如红色字体 style="color:red;"
// 所以需要给所有标签添加style属性
whitelist.addAttributes(":all", "style");
} public static String clean(String content) {
return Jsoup.clean(content, "", whitelist, outputSettings);
} public static void main(String[] args) throws FileNotFoundException, IOException {
String text = "<a href=\"http://www.baidu.com/a\" onclick=\"alert(1);\">sss</a><script>alert(0);</script>sss";
System.out.println(clean(text));
} }
Jsuop Whitelist的更多相关文章
- dubbo . dubbo Please check registry access list (whitelist/blacklist) 错误
dubbo Please check registry access list (whitelist/blacklist) dubbo服务调用provider失败.解决办法: 再consumer的服务 ...
- Firewalld中的whitelist并不是规则白名单
原文地址:http://www.excelib.com/article/292/show whitelist的含义 白名单跟防火墙结合在一起大家很容易将其理解为规则白名单,不过在Firewalld中w ...
- Java微信开发_Exception_02_"errcode":40164,"errmsg":"invalid ip 61.172.68.219, not in whitelist hint
ip查询网址: http://www.ip.cn/ 一.异常现象 今天开始做微信开发,在办公室时能正常获取access_token,晚上回家之后获取access_token时却报出下列错误信息: {& ...
- 获取access_token时却报出下列错误信息:{"errcode":40164,"errmsg":"invalid ip 61.172.68.219, not in whitelist hint: [KJZfAa0644e575]"},以及一些其他报错
获取access_token时却报出下列错误信息:{"errcode":40164,"errmsg":"invalid ip 61.172.68.21 ...
- 使用zookeeper报错 stat is not executed because it is not in the whitelist. envi is not executed because it is not in the whitelist.
在使用四字命令或者zk ui界面查看zookeeper集群时,出现如下提示: stat is not executed because it is not in the whitelist. envi ...
- 解决Zookeeper报错:conf is not executed because it is not in the whitelist的解决办法
1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [root@xg61 ...
- 微信开发_Exception_02_"errcode":40164,"errmsg":"invalid ip 61.172.68.219, not in whitelist hint
ip查询网址: http://www.ip.cn/ 一.异常现象 今天开始做微信开发,在办公室时能正常获取access_token,晚上回家之后获取access_token时却报出下列错误信息: {& ...
- zookeeper 异常 :stat is not executed because it is not in the whitelist. Connection closed b
1 .问题 1.启动 zookeeper 后 用指令: telnet 127.0.0.1 2181 连接 提示输入指令 :stat 后报错,然后关闭连接 2.问题解决: 修改启动指令 zkServe ...
- 全本软件白名单 Quanben Software Whitelist
Windows应用软件 Windows Applications (TBU) 全本推荐微软Windows 10操作系统 Quanben recommends Microsoft Windows 10 ...
随机推荐
- 使用area标签实现标签的嵌套
在项目中我们会碰到这种需求:即点击这个整个a标签跳转到一个页面,点击a里面的某个a再跳转到另一个页面.有人会说,这还不简单,直接a标签嵌套a标签,可是事实如此吗,看代码: <a href=&qu ...
- nginx服务器配置说明
总结nginx的一些配置选项: nginx全局配置文件 # 定义nginx运行的用户和组//一个默认同时为用户和组 //没有则默认为nobody user www-data; # nginx进程数,建 ...
- win8.1rtm专业版无法安装net3.5还有iis
win8.1rtm专业版无法安装net3.5还有iis错误代码:0x800F0906 已解决:dism.exe /online /enable-feature /featurename:NetFX3 ...
- Linux就是这个范儿之第一次亲密接触(2)
原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 .作者信息和本声明.否则将追究法律责 1.2 不一样的图形操作 几乎所有Linux的新用户都会认为Linux的图形界面是相当的绚丽又多彩. ...
- OpenLayers基础知识:
OpenLayers是一个开源的js框架,用于在您的浏览器中实现地图浏览的效果和基本的zoom,pan等功能.OpenLayers支持的地图来源 包括了WMS,GoogleMap,KaMap,MSV ...
- 卸载vue-cli
全局安装:npm install vue-cli -g; 全局卸载:npm uninstall vue-cli -g; 查看vue版本,vue -V 回车,查看vue最新的版本.
- JZOJ.5329【NOIP2017模拟8.22】时间机器
Description
- 重新学习python类
之前觉得有java和c++的底子,对python的类没有认真研习,后面到了写项目的时候各种懵逼.终于决定彻底解决python的类问题. 一.python的类定义: class cls_name: de ...
- 邮件欺诈与SPF防御
一.邮件欺诈: 众所周知,现在邮件的发件人是自己生成的,其实发件域名也是可以自己生成的.例如,A得知B组织的邮箱域(前提是B组织邮箱域没有配置SPF),那么A可以自己起一个邮箱服务器,配置相同的域名. ...
- linux下安装F-prot杀毒软件
一. f-prot的安装 1.首先我们要创建一个带有超级权限的用户 sudo passwa root 2.su 切换用户 3.下载F-prot http://www.f-prot.com/downlo ...