Commit d9f11fa6 by Torkel Ödegaard Committed by GitHub

Merge pull request #15005 from grafana/xss-filter-allow-class-style

XSS sanitizer allows class and style attributes
parents 909d8907 5c72e4e6
...@@ -44,9 +44,25 @@ export function findMatchesInText(haystack: string, needle: string): TextMatch[] ...@@ -44,9 +44,25 @@ export function findMatchesInText(haystack: string, needle: string): TextMatch[]
return matches; return matches;
} }
const XSSWL = Object.keys(xss.whiteList).reduce((acc, element) => {
acc[element] = xss.whiteList[element].concat(['class', 'style']);
return acc;
}, {});
const sanitizeXSS = new xss.FilterXSS({
whiteList: XSSWL
});
/**
* Returns string safe from XSS attacks.
*
* Even though we allow the style-attribute, there's still default filtering applied to it
* Info: https://github.com/leizongmin/js-xss#customize-css-filter
* Whitelist: https://github.com/leizongmin/js-css-filter/blob/master/lib/default.js
*/
export function sanitize (unsanitizedString: string): string { export function sanitize (unsanitizedString: string): string {
try { try {
return xss(unsanitizedString); return sanitizeXSS.process(unsanitizedString);
} catch (error) { } catch (error) {
console.log('String could not be sanitized', unsanitizedString); console.log('String could not be sanitized', unsanitizedString);
return unsanitizedString; return unsanitizedString;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment