ui: fix xss (#775)

This commit is contained in:
Yang Gao authored and GitHub committed 2024-04-01 23:42:09 +08:00
1 parent 36c6faf736
commit 09ac293e22
1 file changed
+5 -5
@@ -1,4 +1,4 @@
import { FilterXSS, safeAttrValue } from 'xss';
import { escapeAttrValue, FilterXSS, safeAttrValue } from 'xss';
const stack = [];
const voidTags = ['br', 'hr', 'input', 'img', 'link', 'source', 'col', 'area', 'base', 'meta', 'embed', 'param', 'track', 'wbr'];
@@ -112,8 +112,8 @@ export const xss = new FilterXSS({
allowCommentTag: false,
stripIgnoreTagBody: ['script'],
safeAttrValue(tag, name, value) {
if (name === 'id') return `xss-id-${value}`;
if (name === 'class') return value.replace(/badge/g, 'xss-badge');
if (name === 'id') return escapeAttrValue(`xss-id-${value}`);
if (name === 'class') return escapeAttrValue(value.replace(/badge/g, 'xss-badge'));
return safeAttrValue(tag, name, value, this.cssFilter);
},
});
@@ -168,8 +168,8 @@ export const xssInline = new FilterXSS({
stripIgnoreTag: true,
stripIgnoreTagBody: ['script'],
safeAttrValue(tag, name, value) {
if (name === 'id') return `xss-id-${value}`;
if (name === 'class') return value.replace(/badge/g, 'xss-badge');
if (name === 'id') return escapeAttrValue(`xss-id-${value}`);
if (name === 'class') return escapeAttrValue(value.replace(/badge/g, 'xss-badge'));
return safeAttrValue(tag, name, value, this.cssFilter);
},
});