ueditor和xss的二三事
来源:互联网 发布:如何制作淘宝首页模板 编辑:程序博客网 时间:2024/06/06 09:44
富文本编辑器ueditor的引入
虽然经常吐槽百度,但是这个富文本编辑器还是很好使的,尤其是还有良心的兔斯基绿豆蛙等经典表情
- 首先引入三个js文件
<script type="text/javascript" charset="utf-8" src="{:C('PLUGIN_URL')}UEditer/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="{:C('PLUGIN_URL')}UEditer/ueditor.all.min.js"> </script> <script type="text/javascript" charset="utf-8" src="{:C('PLUGIN_URL')}UEditer/lang/zh-cn/zh-cn.js"></script>
- 然后将自己的textarea设置一个id属性
<textarea rows="5" cols="30" id="goods_introduce" name="goods_introduce" style="width:1080px; height:300px"></textarea>
- 最后再执行一段js代码
var ue = UE.getEditor('goods_introduce')
其实在上面的getEditor函数里面可以传入第二个参数,一个json格式的参数,可以定制富文本编辑器的功能按钮,这样在编辑器里面只会出现里面的功能按钮
var ue = UE.getEditor('goods_introduce',{toolbars: [[ 'fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal' ]]});
XSS攻击与htmlpurifier
很奇怪的是XSS全称是Cross Site Scripting,据说为了和CSS区分,由于百度的ueditor自带了一些防范xss攻击的,但是无法阻止在html模式下的js攻击
所以可以借助htmlpurifier来防止类似的攻击,他的原理是,直接删除你不允许的标签(通常是选择不允许出现script标签)
自定义一个函数,引入HTMLPurifier.auto.php文件,然后进行一系列骚操作,比如下面这样的,然后在处理数据的时候调用自己的这个方法的就可以了,比如我这里就调用preventXSS方法
/** * @param $string 待处理的字符串* @return string 处理之后的字符串*/function preventXSS($string){ require_once './Application/Common/Plugin/Htmlpurifier/HTMLPurifier.auto.php'; // 生成配置对象 $cfg = HTMLPurifier_Config::createDefault(); // 以下就是配置: $cfg->set('Core.Encoding', 'UTF-8'); // 设置允许使用的HTML标签 $cfg->set('HTML.Allowed','div,b,strong,i,em,a[href|title],ul,ol,li,br,span[style],img[width|height|alt|src]'); // 设置允许出现的CSS样式属性 $cfg->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align'); // 设置a标签上是否允许使用target="_blank" $cfg->set('HTML.TargetBlank', TRUE); // 使用配置生成过滤用的对象 $obj = new HTMLPurifier($cfg); // 过滤字符串 return $obj->purify($string);}
阅读全文
0 0
- ueditor和xss的二三事
- ueditor的配置和使用
- ueditor的配置和使用
- XSS注入方式和逃避XSS过滤的常用方法
- 百度编辑器ueditor的部署和二次开发
- 编辑器ueditor和springboot 的整合
- artTemplate和uEditor编辑器的问题
- 关于UEditor和thinkphp在一起的问题
- laravel5中ueditor的安装和使用
- PHP xss 和 SQL 注入的问题
- xss注入和防范的方法
- XSS和SQL注入的汇总
- 解决webx的xss和csrf漏洞
- js 前端防xss攻击——百度UEditor解决方案
- 对于xss和sql注入的防范(美团网站xss例子)
- 百度Ueditor的基本配置和照片的上传
- [转]百度Ueditor的基本配置和照片的上传
- CI和UEditor集成
- 18th 【最短路 floyd】智捅马蜂窝
- jQuery-Validate验证插件的使用步骤详解
- 黑化的牛牛
- html笔记
- MySQL更新FROM从句中的字段 mysql [Err] 1093
- ueditor和xss的二三事
- Linux基础—目录结构及相应用途
- Android深入理解JNI(二)类型转换、方法签名和JNIEnv
- 尼科彻斯定理
- 单链表的基本操作
- poj 1852 Ants
- React Native 学习笔记(二)
- Objective-C中的协议(protocol)与委托
- 机器学习基础,入门介绍