Skip to content

Commit d875de5

Browse files
committed
fix(runtime-dom): setting innerHTML when patching props should go through trusted types
1 parent 42e8df6 commit d875de5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/runtime-dom/src/modules/props.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// __UNSAFE__
2-
// Reason: potentially setting innerHTML.
3-
// This can come from explicit usage of v-html or innerHTML as a prop in render
4-
51
import { DeprecationTypes, compatUtils, warn } from '@vue/runtime-core'
62
import { includeBooleanAttr } from '@vue/shared'
3+
import { unsafeToTrustedHTML } from '../nodeOps'
74

85
// functions. The user is responsible for using them with only trusted content.
96
export function patchDOMProp(
@@ -12,11 +9,15 @@ export function patchDOMProp(
129
value: any,
1310
parentComponent: any,
1411
): void {
12+
// __UNSAFE__
13+
// Reason: potentially setting innerHTML.
14+
// This can come from explicit usage of v-html or innerHTML as a prop in render
1515
if (key === 'innerHTML' || key === 'textContent') {
1616
// null value case is handled in renderer patchElement before patching
1717
// children
18-
if (value == null) return
19-
el[key] = value
18+
if (value != null) {
19+
el[key] = key === 'innerHTML' ? unsafeToTrustedHTML(value) : value
20+
}
2021
return
2122
}
2223

packages/runtime-dom/src/nodeOps.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ if (tt) {
3131
// This function merely perform a type-level trusted type conversion
3232
// for use in `innerHTML` assignment, etc.
3333
// Be careful of whatever value passed to this function.
34-
const unsafeToTrustedHTML: (value: string) => TrustedHTML | string = policy
35-
? val => policy.createHTML(val)
36-
: val => val
34+
export const unsafeToTrustedHTML: (value: string) => TrustedHTML | string =
35+
policy ? val => policy.createHTML(val) : val => val
3736

3837
export const svgNS = 'http://www.w3.org/2000/svg'
3938
export const mathmlNS = 'http://www.w3.org/1998/Math/MathML'

0 commit comments

Comments
 (0)