@@ -15,6 +15,7 @@ import * as platform from 'vs/base/common/platform';
15
15
import { URI } from 'vs/base/common/uri' ;
16
16
import { FileAccess , RemoteAuthorities } from 'vs/base/common/network' ;
17
17
import { BrowserFeatures } from 'vs/base/browser/canIUse' ;
18
+ import { insane , InsaneOptions } from 'vs/base/common/insane/insane' ;
18
19
19
20
export function clearNode ( node : HTMLElement ) : void {
20
21
while ( node . firstChild ) {
@@ -1311,3 +1312,48 @@ export function detectFullscreen(): IDetectedFullscreen | null {
1311
1312
// Not in fullscreen
1312
1313
return null ;
1313
1314
}
1315
+
1316
+ // -- sanitize and trusted html
1317
+
1318
+ function newInsaneOptions ( allowedTags : string [ ] , allowedAttributesForAll : string [ ] , allowedAttributes : Record < string , string [ ] > ) : InsaneOptions {
1319
+ for ( let tag of allowedTags ) {
1320
+ let array = allowedAttributes [ tag ] ;
1321
+ if ( ! array ) {
1322
+ array = allowedAttributesForAll ;
1323
+ } else {
1324
+ array = array . concat ( allowedAttributesForAll ) ;
1325
+ }
1326
+ allowedAttributes [ tag ] = array ;
1327
+ }
1328
+ const value : InsaneOptions = {
1329
+ allowedTags,
1330
+ allowedAttributes,
1331
+ } ;
1332
+ return value ;
1333
+ }
1334
+
1335
+
1336
+ const _ttpStaticHtml = window . trustedTypes ?. createPolicy ( 'staticHtml' , {
1337
+ createHTML ( value , options : InsaneOptions ) {
1338
+ return insane ( value , options ) ;
1339
+ }
1340
+ } ) ;
1341
+
1342
+ export function sanitizeStaticHtml ( value : string ) : TrustedHTML | string {
1343
+
1344
+ const options = newInsaneOptions (
1345
+ [ 'a' , 'button' , 'code' , 'div' , 'h1' , 'h2' , 'h3' , 'input' , 'label' , 'li' , 'p' , 'pre' , 'select' , 'small' , 'span' , 'textarea' , 'ul' ] ,
1346
+ [ 'class' , 'id' , 'role' , 'tabindex' ] ,
1347
+ {
1348
+ 'a' : [ 'href' ] ,
1349
+ 'button' : [ 'data-href' ] ,
1350
+ 'input' : [ 'type' , 'placeholder' , 'checked' , 'required' ] ,
1351
+ 'label' : [ 'for' ] ,
1352
+ 'select' : [ 'required' ] ,
1353
+ 'span' : [ 'data-command' , 'role' ] ,
1354
+ 'textarea' : [ 'name' , 'placeholder' , 'required' ] ,
1355
+ }
1356
+ ) ;
1357
+
1358
+ return _ttpStaticHtml ?. createHTML ( value , options ) ?? insane ( value , options ) ;
1359
+ }
0 commit comments