Skip to content

Commit 44c65f8

Browse files
authored
fix: remove data: and vbscript: attributes (#7)
1 parent 80480d9 commit 44c65f8

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

.changeset/yellow-cooks-film.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"domiso": patch
33
---
44

5-
feat: better HTML/XML support, remove `javascript:` attributes
5+
feat: better HTML/XML support, remove `data:`, `javascript:` and `vbscript:` attributes

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const sanitizeAttributes = (el: Element) => {
88
for (let i = 0, len = attrs.length; i < len; i++) {
99
const attr = attrs[i]
1010
if (
11-
attr.name.toLowerCase().startsWith('on') ||
12-
attr.value.toLowerCase().startsWith('javascript:')
11+
/^on/i.test(attr.name) ||
12+
/^(?:data|javascript|vbscript):/i.test(attr.value)
1313
) {
1414
el.removeAttributeNode(attr)
1515
// eslint-disable-next-line sonar/updated-loop-counter -- the attribute is removed, the index and length must be rechecked
@@ -39,9 +39,7 @@ function sanitizeNode(el: Document | Element) {
3939
return sanitizeChildren(el)
4040
}
4141

42-
const tagName = el.tagName.toLowerCase()
43-
44-
if (['parsererror', 'script'].includes(tagName)) {
42+
if (['parsererror', 'script'].includes(el.tagName.toLowerCase())) {
4543
el.remove()
4644
return null
4745
}

0 commit comments

Comments
 (0)