mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-16 23:07:11 +00:00
27 lines
732 B
JavaScript
27 lines
732 B
JavaScript
const xss = require('xss')
|
|
const excludeTags = ['iframe', 'script']
|
|
|
|
const options = {
|
|
css: false,
|
|
stripIgnoreTagBody: ['script'],
|
|
onTag(tag, html, options) {
|
|
if (excludeTags.indexOf(tag) !== -1) {
|
|
return html.replace(/</g, '<').replace(/>/g, '>')
|
|
}
|
|
},
|
|
// 避免把页面样式过滤掉
|
|
onTagAttr(tag, name, value, isWhiteAttr) {
|
|
// 过滤掉标签上的事件
|
|
if (/^on/.test(name)) {
|
|
return name + '=' + '.'
|
|
}
|
|
if (['src', 'href'].indexOf(name) !== -1) {
|
|
return name + '=' + value.replace('javascript:', 'java:').replace('data:', 'dt:')
|
|
}
|
|
return name + '="' + xss.escapeAttrValue(value) + '"'
|
|
}
|
|
}
|
|
const filter = new xss.FilterXSS(options)
|
|
|
|
export default filter
|