File tree 1 file changed +18
-3
lines changed
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,22 @@ function extractTextContentWebVtt(text) {
148
148
. join ( ' ' ) ;
149
149
// Super loose HTML parsing to get HTML entity parsing and removal
150
150
// of WebVTT elements.
151
- const div = < div /> ;
152
- div . /* element is never added to DOM */ innerHTML = text ;
153
- return div . textContent ;
151
+ // Assigning .innerHTML of a <template> node to prevent XSS risk.
152
+ const wrapperTemplate = < template /> ;
153
+ // Make innerHTML assignment Trusted Types compliant for compatible browsers
154
+ if ( self . trustedTypes && self . trustedTypes . createPolicy ) {
155
+ const policy = self . trustedTypes . createPolicy (
156
+ 'semantic-render#extractTextContentWebVtt' ,
157
+ {
158
+ createHTML : function ( unused ) {
159
+ return text ;
160
+ } ,
161
+ }
162
+ ) ;
163
+ wrapperTemplate . /* element is never added to DOM */ innerHTML =
164
+ policy . createHTML ( 'ignored' ) ;
165
+ } else {
166
+ wrapperTemplate . /* element is never added to DOM */ innerHTML = text ;
167
+ }
168
+ return wrapperTemplate . content . textContent ;
154
169
}
You can’t perform that action at this time.
0 commit comments