@@ -434,6 +434,9 @@ class CssProp {
434
434
* A class to sanitize HTML strings.
435
435
*/
436
436
export class Sanitizer implements IRenderMime . ISanitizer {
437
+ constructor ( ) {
438
+ this . _options = this . _generateOptions ( ) ;
439
+ }
437
440
/**
438
441
* Sanitize an HTML string.
439
442
*
@@ -473,9 +476,18 @@ export class Sanitizer implements IRenderMime.ISanitizer {
473
476
this . _autolink = autolink ;
474
477
}
475
478
476
- private _autolink : boolean = true ;
479
+ /**
480
+ * Set the whether to allow `name` and `id` attributes.
481
+ */
482
+ setAllowNamedProperties ( allowNamedProperties : boolean ) : void {
483
+ this . _allowNamedProperties = allowNamedProperties ;
484
+ this . _options = this . _generateOptions ( ) ;
485
+ }
477
486
478
- private _options : sanitize . IOptions = {
487
+ private _autolink : boolean = true ;
488
+ private _allowNamedProperties : boolean = false ;
489
+ private _options : sanitize . IOptions ;
490
+ private _generateOptions = ( ) : sanitize . IOptions => ( {
479
491
// HTML tags that are allowed to be used. Tags were extracted from Google Caja
480
492
allowedTags : [
481
493
'a' ,
@@ -590,7 +602,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
590
602
'dir' ,
591
603
'draggable' ,
592
604
'hidden' ,
593
- 'id' ,
605
+ ... ( this . _allowNamedProperties ? [ 'id' ] : [ ] ) ,
594
606
'inert' ,
595
607
'itemprop' ,
596
608
'itemref' ,
@@ -607,7 +619,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
607
619
'coords' ,
608
620
'href' ,
609
621
'hreflang' ,
610
- 'name' ,
622
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
611
623
'rel' ,
612
624
'shape' ,
613
625
'tabindex' ,
@@ -641,7 +653,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
641
653
'data-commandlinker-args' ,
642
654
'data-commandlinker-command' ,
643
655
'disabled' ,
644
- 'name' ,
656
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
645
657
'tabindex' ,
646
658
'type' ,
647
659
'value'
@@ -672,7 +684,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
672
684
'autocomplete' ,
673
685
'enctype' ,
674
686
'method' ,
675
- 'name' ,
687
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
676
688
'novalidate'
677
689
] ,
678
690
h1 : [ 'align' ] ,
@@ -697,7 +709,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
697
709
'height' ,
698
710
'hspace' ,
699
711
'ismap' ,
700
- 'name' ,
712
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
701
713
'src' ,
702
714
'usemap' ,
703
715
'vspace' ,
@@ -718,7 +730,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
718
730
'maxlength' ,
719
731
'min' ,
720
732
'multiple' ,
721
- 'name' ,
733
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
722
734
'placeholder' ,
723
735
'readonly' ,
724
736
'required' ,
@@ -734,13 +746,13 @@ export class Sanitizer implements IRenderMime.ISanitizer {
734
746
label : [ 'accesskey' , 'for' ] ,
735
747
legend : [ 'accesskey' , 'align' ] ,
736
748
li : [ 'type' , 'value' ] ,
737
- map : [ 'name' ] ,
749
+ map : this . _allowNamedProperties ? [ 'name' ] : [ ] ,
738
750
menu : [ 'compact' , 'label' , 'type' ] ,
739
751
meter : [ 'high' , 'low' , 'max' , 'min' , 'value' ] ,
740
752
ol : [ 'compact' , 'reversed' , 'start' , 'type' ] ,
741
753
optgroup : [ 'disabled' , 'label' ] ,
742
754
option : [ 'disabled' , 'label' , 'selected' , 'value' ] ,
743
- output : [ 'for' , 'name' ] ,
755
+ output : [ 'for' , ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ] ,
744
756
p : [ 'align' ] ,
745
757
pre : [ 'width' ] ,
746
758
progress : [ 'max' , 'min' , 'value' ] ,
@@ -749,7 +761,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
749
761
'autocomplete' ,
750
762
'disabled' ,
751
763
'multiple' ,
752
- 'name' ,
764
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
753
765
'required' ,
754
766
'size' ,
755
767
'tabindex'
@@ -789,7 +801,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
789
801
'cols' ,
790
802
'disabled' ,
791
803
'inputmode' ,
792
- 'name' ,
804
+ ... ( this . _allowNamedProperties ? [ 'name' ] : [ ] ) ,
793
805
'placeholder' ,
794
806
'readonly' ,
795
807
'required' ,
@@ -982,5 +994,5 @@ export class Sanitizer implements IRenderMime.ISanitizer {
982
994
// Since embedded data is no longer deemed to be a threat, validation can be skipped.
983
995
// See https://github.com/jupyterlab/jupyterlab/issues/5183
984
996
allowedSchemesAppliedToAttributes : [ 'href' , 'cite' ]
985
- } ;
997
+ } ) ;
986
998
}
0 commit comments