diff --git a/src/utils/sec-utils.ts b/src/utils/sec-utils.ts index 3769a1279..c5d74b1b8 100644 --- a/src/utils/sec-utils.ts +++ b/src/utils/sec-utils.ts @@ -1,7 +1,15 @@ -import { filterXSS } from 'xss'; +import { filterXSS, escapeAttrValue } from 'xss'; + +const xssOpts = { + onIgnoreTagAttr: function(tag: string, name: string, value: string) { + if (tag.match(/^h[0-9]$/) && name === 'id') { + return name + '="' + escapeAttrValue(value) + '"'; + } + }, +}; export function preventXSS(text: string): string { - const encodedText = filterXSS(text); + const encodedText = filterXSS(text, xssOpts); return encodedText; }