首页 > 技术文章 > node 解决存储xss风险报告

yu-hailong 2019-05-29 09:44 原文

1. 安装 xss模块

npm install xss

2.在 Node.js 中使用

const xss = require("xss");

// 在项目的接口里面添加

let option = {
        stripIgnoreTag: true,  // 把所有标签替换为空(去掉不在白名单上的标签)

    }
  // 删除默认的div标签
    delete xss.whiteList['div']

let count = xss(params.Content, option);

 

在这里 params.Content 是 你要替换的参数

 

官方的示例:

var xss = require("xss");
var html = xss('<script>alert("xss");</script>');
console.log(html);

 

参考中文 文档: https://github.com/leizongmin/js-xss/blob/master/README.zh.md

参考英文 文档: https://github.com/leizongmin/js-xss

npm 文档: https://www.npmjs.com/package/xss

 

推荐阅读