Skip to content

Commit

Permalink
Added a mitigation against a problem with templates inside select
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Aug 10, 2021
1 parent ded85d9 commit e32ca24
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
18 changes: 17 additions & 1 deletion dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion dist/purify.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.es.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ function createDOMPurify(window = getGlobal()) {
return true;
}

/* Mitigate a problem with templates inside select */
if (
tagName === 'select' &&
regExpTest(/<template/i, currentNode.innerHTML)
) {
_forceRemove(currentNode);
return true;
}

/* Remove element if anything forbids its presence */
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
/* Keep content except for bad-listed elements */
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,5 +1200,11 @@ module.exports = [
"<b is=\"\">bar</b>",
"<b>bar</b>"
]
}, {
"title": "Tests against removal of templates inside select elements",
"payload": "<select><template></template></select>",
"expected": [
""
]
}
];

0 comments on commit e32ca24

Please sign in to comment.