vue中xss详细配置

xss文件

import xss from 'xss'; // 导入xss包
const options = {
    // 白名单
    whiteList:{
        a: ['style', 'href', 'title', 'target'],
        p:['style'],
        section: ['style'],
        strong: ['style'],
        abbr: ["title",'style'],
        address: ['style'],
        area: ['style',"shape", "coords", "href", "alt"],
        article: ['style'],
        aside: ['style'],
        audio: ['style',"autoplay", "controls", "loop", "preload", "src"],
        b: ['style'],
        bdi: ['style', "dir"],
        bdo: ['style',"dir"],
        big: ['style'],
        blockquote: ['style',"cite"],
        br: ['style'],
        caption: ['style'],
        center: ['style'],
        cite: ['style'],
        code: ['style'],
        col: ['style',"align", "valign", "span", "width"],
        colgroup: ['style',"align", "valign", "span", "width"],
        dd: ['style'],
        del: ['style',"datetime"],
        details: ['style',"open"],
        div: ['style','style'],
        dl: ['style'],
        dt: ['style'],
        em: ['style'],
        font: ['style',"color", "size", "face"],
        footer: ['style'],
        h1: ['style'],
        h2: ['style'],
        h3: ['style'],
        h4: ['style'],
        h5: ['style'],
        h6: ['style'],
        header: ['style'],
        hr: ['style'],
        i: ['style'],
        img: ['style',"src", "alt", "title", "width", "height"],
        ins: ['style',"datetime"],
        li: ['style'],
        mark: ['style'],
        nav: ['style'],
        ol: ['style'],
        pre: ['style'],
        s: ['style'],
        small: ['style'],
        span: ['style'],
        sub: ['style'],
        sup: ['style'],
        table: ["width", "border", "align", "valign","style"],
        tbody: ['style',"align", "valign"],
        td: ["width", "rowspan", "colspan", "align", "valign","style"],
        tfoot: ['style',"align", "valign"],
        th: ['style',"width", "rowspan", "colspan", "align", "valign"],
        thead: ['style',"align", "valign"],
        tr: ['style',"rowspan", "align", "valign"],
        tt: ['style'],
        u: ['style'],
        ul: ['style'],
        video: ['style',"autoplay", "controls", "loop", "preload", "src", "height", "width"],
        style:['style']   //新添
    },
    // 去掉不在白名单上的标签
    stripIgnoreTag: true,
    // 去掉HTML备注
    allowCommentTag: false,
    // 彻底去除script标签
    stripIgnoreTagBody: ["script","noscript"],
};
const myxss = new xss.FilterXSS(options);
export default myxss;

在main.js中配置

import myxss from '../xss';
Vue.prototype.$xss = (val) => {
    return myxss.process(val);
}

在页面中使用

	<div v-html="$xss(content)"></div>
  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值