mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 17:38:19 +08:00
ui: add limitation for href
This commit is contained in:
1 parent
cf7682fb76
commit
0f03f0e70e
1 file changed
+4
-3
@@ -1,9 +1,9 @@
|
|||||||
import * as Xss from 'xss';
|
import { FilterXSS } from 'xss';
|
||||||
|
|
||||||
const stack = [];
|
const stack = [];
|
||||||
const voidTags = ['br', 'hr', 'input', 'img', 'link', 'source', 'col', 'area', 'base', 'meta', 'embed', 'param', 'track', 'wbr'];
|
const voidTags = ['br', 'hr', 'input', 'img', 'link', 'source', 'col', 'area', 'base', 'meta', 'embed', 'param', 'track', 'wbr'];
|
||||||
|
|
||||||
const tagCheck = new Xss.FilterXSS({
|
const tagCheck = new FilterXSS({
|
||||||
css: false,
|
css: false,
|
||||||
whiteList: {},
|
whiteList: {},
|
||||||
onIgnoreTag(tag, html, options) {
|
onIgnoreTag(tag, html, options) {
|
||||||
@@ -32,7 +32,7 @@ const tagCheck = new Xss.FilterXSS({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const xss = new Xss.FilterXSS({
|
export const xss = new FilterXSS({
|
||||||
whiteList: {
|
whiteList: {
|
||||||
a: ['target', 'href', 'title'],
|
a: ['target', 'href', 'title'],
|
||||||
abbr: ['title'],
|
abbr: ['title'],
|
||||||
@@ -113,6 +113,7 @@ export const xss = new Xss.FilterXSS({
|
|||||||
safeAttrValue(tag, name, value) {
|
safeAttrValue(tag, name, value) {
|
||||||
if (name === 'id') return `xss-id-${value}`;
|
if (name === 'id') return `xss-id-${value}`;
|
||||||
if (name === 'class') return value.replace(/badge/g, 'xss-badge');
|
if (name === 'class') return value.replace(/badge/g, 'xss-badge');
|
||||||
|
if (name === 'href') return value.trim().startsWith('javascript:') ? '#' : value;
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user