Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken test case to sanitize on-event in ie #1051

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions apps/editor/src/js/htmlSanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SVG_ATTR_LIST_RX = new RegExp(

const XSS_ATTR_RX = /href|src|background/gi;
const XSS_VALUE_RX = /((java|vb|live)script|x):/gi;
const ON_EVENT_RX = /^on\S+/;

/**
* htmlSanitizer
Expand Down Expand Up @@ -90,17 +91,19 @@ function isXSSAttribute(attrName, attrValue) {
}

/**
* Removes attributes of blacklist.
* @param {NamedNodeMap} nodeAttrs - all attributes of node
* Removes attributes of blacklist from node.
* @param {HTMLElement} node - node to remove attributes
* @param {NamedNodeMap} blacklistAttrs - attributes of blacklist
* @private
*/
function removeBlacklistAttributes(nodeAttrs, blacklistAttrs) {
function removeBlacklistAttributes(node, blacklistAttrs) {
toArray(blacklistAttrs).forEach(({ name }) => {
// Edge svg attribute name returns uppercase bug. error guard.
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5579311/
if (nodeAttrs.getNamedItem(name)) {
nodeAttrs.removeNamedItem(name);
if (ON_EVENT_RX.test(name)) {
node[name] = null;
}
Comment on lines +101 to +103
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE์˜ ๊ฒฝ์šฐonload, onerror ๋“ฑ ์†์„ฑ์— ํ• ๋‹น๋œ ์ด๋ฒคํŠธ๊ฐ€ ์ œ๊ฑฐ๋˜์ง€ ์•Š์•„์„œ XSS ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฉฐ ์ด๋ฒคํŠธ๋ฅผ ์™„์ „ํ•˜๊ฒŒ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ•ด๋‹น ๋กœ์ง์„ ์ถ”๊ฐ€ํ•จ


if (node.getAttribute(name)) {
node.removeAttribute(name);
}
});
}
Expand All @@ -122,7 +125,7 @@ function leaveOnlyWhitelistAttribute(html) {
return (!htmlAttr && !svgAttr) || xssAttr;
});

removeBlacklistAttributes(attributes, blacklist);
removeBlacklistAttributes(node, blacklist);
});
}

Expand Down
2 changes: 1 addition & 1 deletion apps/editor/test/unit/htmlSanitizer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('htmlSanitizer', function() {
expect(htmlSanitizer(`<TABLE BACKGROUND="javascript:alert('XSS')">`, true)).toBe(
'<table></table>'
);
expect(htmlSanitizer(`<TABLE><TD BACKGROUND="javascript:alert('XSS')">`, true)).toBe(
expect(htmlSanitizer(`<TABLE><TD BACKGROUND="javascript:alert('XSS')"></TD>`, true)).toBe(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE10์—์„œ <td>๋งŒ ๋„˜๊ฒจ์ค„ ๊ฒฝ์šฐ, ์ž๋™์œผ๋กœ ํด๋กœ์ฆˆ ํƒœ๊ทธ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์ง€ ์•Š์•„์„œ ํด๋กœ์ฆˆ ํƒœ๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•จ

'<table><tbody><tr><td></td></tr></tbody></table>'
);
});
Expand Down