Skip to content

Commit dbb5581

Browse files
committed
fix: check innerHTML is a string when applying XSS fixes
Relates to nuxt/nuxt#24388, nuxt-modules/fontaine#350, #278
1 parent 7fbeb3f commit dbb5581

File tree

1 file changed

+2
-1
lines changed
  • packages/unhead/src/plugins

1 file changed

+2
-1
lines changed

packages/unhead/src/plugins/xss.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineHeadPlugin({
44
hooks: {
55
'tags:afterResolve': function (ctx) {
66
for (const tag of ctx.tags) {
7-
if (tag.innerHTML) {
7+
if (typeof tag.innerHTML === 'string') {
88
if (tag.innerHTML && ['application/ld+json', 'application/json'].includes(tag.props.type))
99
// ensure </script> tags get encoded, this is only for JSON, it will break HTML if used
1010
{ tag.innerHTML = tag.innerHTML.replace(/</g, '\\u003C') }
@@ -15,6 +15,7 @@ export default defineHeadPlugin({
1515
.replace(new RegExp(`</${tag.tag}`, 'g'), `<\\/${tag.tag}`)
1616
}
1717
}
18+
// TODO delete innerHTML otherwise
1819
}
1920
},
2021
},

0 commit comments

Comments
 (0)