@jupyterlab/apputils 4.6.0-alpha.1 → 4.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/sanitizer.ts CHANGED
@@ -590,14 +590,24 @@ export class Sanitizer implements IRenderMime.ISanitizer {
590
590
  return this._autolink;
591
591
  }
592
592
 
593
+ /**
594
+ * @returns Whether to allow name and id attributes.
595
+ */
596
+ get allowNamedProperties(): boolean {
597
+ return this._allowNamedProperties;
598
+ }
599
+
593
600
  /**
594
601
  * Set the allowed schemes
595
602
  *
596
- * @param scheme Allowed schemes
603
+ * @param scheme Allowed schemes.
604
+ * Automatically regenerates sanitizer options to apply the change.
605
+ * Note: the schemes merge into the current config and does not get overwritten.
597
606
  */
598
607
  setAllowedSchemes(scheme: Array<string>): void {
599
608
  // Force copy of `scheme`
600
- this._options.allowedSchemes = [...scheme];
609
+ this._customAllowedSchemes = [...scheme];
610
+ this._options = this._generateOptions();
601
611
  }
602
612
 
603
613
  /**
@@ -619,551 +629,576 @@ export class Sanitizer implements IRenderMime.ISanitizer {
619
629
 
620
630
  private _autolink: boolean = true;
621
631
  private _allowNamedProperties: boolean = false;
632
+ private _customAllowedSchemes: string[] | undefined;
622
633
  private _options: sanitize.IOptions;
623
- private _generateOptions = (): sanitize.IOptions => ({
624
- // HTML tags that are allowed to be used. Tags were extracted from Google Caja
625
- allowedTags: [
626
- 'a',
627
- 'abbr',
628
- 'acronym',
629
- 'address',
630
- 'area',
631
- 'article',
632
- 'aside',
633
- 'audio',
634
- 'b',
635
- 'bdi',
636
- 'bdo',
637
- 'big',
638
- 'blockquote',
639
- 'br',
640
- 'button',
641
- 'canvas',
642
- 'caption',
643
- 'center',
644
- 'cite',
645
- 'code',
646
- 'col',
647
- 'colgroup',
648
- 'colspan',
649
- 'command',
650
- 'data',
651
- 'datalist',
652
- 'dd',
653
- 'del',
654
- 'details',
655
- 'dfn',
656
- 'dir',
657
- 'div',
658
- 'dl',
659
- 'dt',
660
- 'em',
661
- 'fieldset',
662
- 'figcaption',
663
- 'figure',
664
- 'font',
665
- 'footer',
666
- 'form',
667
- 'h1',
668
- 'h2',
669
- 'h3',
670
- 'h4',
671
- 'h5',
672
- 'h6',
673
- 'header',
674
- 'hgroup',
675
- 'hr',
676
- 'i',
677
- // 'iframe' is allowed by Google Caja, but disallowed by default by sanitize-html
678
- // , 'iframe'
679
- 'img',
680
- 'input',
681
- 'ins',
682
- 'kbd',
683
- 'label',
684
- 'legend',
685
- 'li',
686
- 'map',
687
- 'mark',
688
- 'menu',
689
- 'meter',
690
- 'nav',
691
- 'nobr',
692
- 'ol',
693
- 'optgroup',
694
- 'option',
695
- 'output',
696
- 'p',
697
- 'pre',
698
- 'progress',
699
- 'q',
700
- 'rowspan',
701
- 's',
702
- 'samp',
703
- 'section',
704
- 'select',
705
- 'small',
706
- 'source',
707
- 'span',
708
- 'strike',
709
- 'strong',
710
- 'sub',
711
- 'summary',
712
- 'sup',
713
- 'table',
714
- 'tbody',
715
- 'td',
716
- 'textarea',
717
- 'tfoot',
718
- 'th',
719
- 'thead',
720
- 'time',
721
- 'tr',
722
- 'track',
723
- 'tt',
724
- 'u',
725
- 'ul',
726
- 'var',
727
- 'video',
728
- 'wbr'
729
- ],
730
- // Attributes that HTML tags are allowed to have, extracted from Google Caja.
731
- // See https://github.com/jupyterlab/jupyterlab/issues/1812#issuecomment-285848435
732
- allowedAttributes: {
733
- '*': [
734
- 'class',
735
- 'dir',
736
- 'draggable',
737
- 'hidden',
738
- ...(this._allowNamedProperties ? ['id'] : []),
739
- 'inert',
740
- 'itemprop',
741
- 'itemref',
742
- 'itemscope',
743
- 'lang',
744
- 'spellcheck',
745
- 'style',
746
- 'title',
747
- 'translate'
748
- ],
749
- // 'rel' and 'target' were *not* allowed by Google Caja
750
- a: [
751
- 'accesskey',
752
- 'coords',
753
- 'href',
754
- 'hreflang',
755
- ...(this._allowNamedProperties ? ['name'] : []),
756
- 'rel',
757
- 'shape',
758
- 'tabindex',
759
- 'target',
760
- 'type'
761
- ],
762
- area: [
763
- 'accesskey',
764
- 'alt',
765
- 'coords',
766
- 'href',
767
- 'nohref',
768
- 'shape',
769
- 'tabindex'
770
- ],
771
- // 'autoplay' was *not* allowed by Google Caja
772
- audio: [
773
- 'autoplay',
774
- 'controls',
775
- 'loop',
776
- 'mediagroup',
777
- 'muted',
778
- 'preload',
779
- 'src'
780
- ],
781
- bdo: ['dir'],
782
- blockquote: ['cite'],
783
- br: ['clear'],
784
- button: [
785
- 'accesskey',
786
- 'data-commandlinker-args',
787
- 'data-commandlinker-command',
788
- 'disabled',
789
- ...(this._allowNamedProperties ? ['name'] : []),
790
- 'tabindex',
791
- 'type',
792
- 'value'
793
- ],
794
- canvas: ['height', 'width'],
795
- caption: ['align'],
796
- col: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
797
- colgroup: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
798
- command: [
799
- 'checked',
800
- 'command',
801
- 'disabled',
802
- 'icon',
803
- 'label',
804
- 'radiogroup',
805
- 'type'
806
- ],
807
- data: ['value'],
808
- del: ['cite', 'datetime'],
809
- details: ['open'],
810
- dir: ['compact'],
811
- div: ['align'],
812
- dl: ['compact'],
813
- fieldset: ['disabled'],
814
- font: ['color', 'face', 'size'],
815
- form: [
816
- 'accept',
817
- 'autocomplete',
818
- 'enctype',
819
- 'method',
820
- ...(this._allowNamedProperties ? ['name'] : []),
821
- 'novalidate'
822
- ],
823
- h1: ['align'],
824
- h2: ['align'],
825
- h3: ['align'],
826
- h4: ['align'],
827
- h5: ['align'],
828
- h6: ['align'],
829
- hr: ['align', 'noshade', 'size', 'width'],
830
- iframe: [
831
- 'align',
832
- 'frameborder',
833
- 'height',
834
- 'marginheight',
835
- 'marginwidth',
836
- 'width'
837
- ],
838
- img: [
839
- 'align',
840
- 'alt',
841
- 'border',
842
- 'height',
843
- 'hspace',
844
- 'ismap',
845
- ...(this._allowNamedProperties ? ['name'] : []),
846
- 'src',
847
- 'usemap',
848
- 'vspace',
849
- 'width'
850
- ],
851
- input: [
852
- 'accept',
853
- 'accesskey',
854
- 'align',
855
- 'alt',
856
- 'autocomplete',
857
- 'checked',
858
- 'disabled',
859
- 'inputmode',
860
- 'ismap',
861
- 'list',
862
- 'max',
863
- 'maxlength',
864
- 'min',
865
- 'multiple',
866
- ...(this._allowNamedProperties ? ['name'] : []),
867
- 'placeholder',
868
- 'readonly',
869
- 'required',
870
- 'size',
871
- 'src',
872
- 'step',
873
- 'tabindex',
874
- 'type',
875
- 'usemap',
876
- 'value'
877
- ],
878
- ins: ['cite', 'datetime'],
879
- label: ['accesskey', 'for'],
880
- legend: ['accesskey', 'align'],
881
- li: ['type', 'value'],
882
- map: this._allowNamedProperties ? ['name'] : [],
883
- menu: ['compact', 'label', 'type'],
884
- meter: ['high', 'low', 'max', 'min', 'value'],
885
- ol: ['compact', 'reversed', 'start', 'type'],
886
- optgroup: ['disabled', 'label'],
887
- option: ['disabled', 'label', 'selected', 'value'],
888
- output: ['for', ...(this._allowNamedProperties ? ['name'] : [])],
889
- p: ['align'],
890
- pre: ['width'],
891
- progress: ['max', 'min', 'value'],
892
- q: ['cite'],
893
- select: [
894
- 'autocomplete',
895
- 'disabled',
896
- 'multiple',
897
- ...(this._allowNamedProperties ? ['name'] : []),
898
- 'required',
899
- 'size',
900
- 'tabindex'
901
- ],
902
- source: ['type'],
903
- table: [
904
- 'align',
905
- 'bgcolor',
906
- 'border',
907
- 'cellpadding',
908
- 'cellspacing',
909
- 'frame',
910
- 'rules',
911
- 'summary',
912
- 'width'
913
- ],
914
- tbody: ['align', 'char', 'charoff', 'valign'],
915
- td: [
916
- 'abbr',
917
- 'align',
918
- 'axis',
919
- 'bgcolor',
920
- 'char',
921
- 'charoff',
922
- 'colspan',
923
- 'headers',
924
- 'height',
925
- 'nowrap',
926
- 'rowspan',
927
- 'scope',
928
- 'valign',
929
- 'width'
930
- ],
931
- textarea: [
932
- 'accesskey',
933
- 'autocomplete',
934
- 'cols',
935
- 'disabled',
936
- 'inputmode',
937
- ...(this._allowNamedProperties ? ['name'] : []),
938
- 'placeholder',
939
- 'readonly',
940
- 'required',
941
- 'rows',
942
- 'tabindex',
943
- 'wrap'
944
- ],
945
- tfoot: ['align', 'char', 'charoff', 'valign'],
946
- th: [
634
+ private _generateOptions = (): sanitize.IOptions => {
635
+ const schemesToAllow = Array.isArray(this._customAllowedSchemes)
636
+ ? this._customAllowedSchemes
637
+ : [...sanitize.defaults.allowedSchemes];
638
+
639
+ return {
640
+ // HTML tags that are allowed to be used. Tags were extracted from Google Caja
641
+ allowedTags: [
642
+ 'a',
947
643
  'abbr',
948
- 'align',
949
- 'axis',
950
- 'bgcolor',
951
- 'char',
952
- 'charoff',
644
+ 'acronym',
645
+ 'address',
646
+ 'area',
647
+ 'article',
648
+ 'aside',
649
+ 'audio',
650
+ 'b',
651
+ 'bdi',
652
+ 'bdo',
653
+ 'big',
654
+ 'blockquote',
655
+ 'br',
656
+ 'button',
657
+ 'canvas',
658
+ 'caption',
659
+ 'center',
660
+ 'cite',
661
+ 'code',
662
+ 'col',
663
+ 'colgroup',
953
664
  'colspan',
954
- 'headers',
955
- 'height',
956
- 'nowrap',
665
+ 'command',
666
+ 'data',
667
+ 'datalist',
668
+ 'dd',
669
+ 'del',
670
+ 'details',
671
+ 'dfn',
672
+ 'dir',
673
+ 'div',
674
+ 'dl',
675
+ 'dt',
676
+ 'em',
677
+ 'fieldset',
678
+ 'figcaption',
679
+ 'figure',
680
+ 'font',
681
+ 'footer',
682
+ 'form',
683
+ 'h1',
684
+ 'h2',
685
+ 'h3',
686
+ 'h4',
687
+ 'h5',
688
+ 'h6',
689
+ 'header',
690
+ 'hgroup',
691
+ 'hr',
692
+ 'i',
693
+ // 'iframe' is allowed by Google Caja, but disallowed by default by sanitize-html
694
+ // , 'iframe'
695
+ 'img',
696
+ 'input',
697
+ 'ins',
698
+ 'kbd',
699
+ 'label',
700
+ 'legend',
701
+ 'li',
702
+ 'map',
703
+ 'mark',
704
+ 'menu',
705
+ 'meter',
706
+ 'nav',
707
+ 'nobr',
708
+ 'ol',
709
+ 'optgroup',
710
+ 'option',
711
+ 'output',
712
+ 'p',
713
+ 'pre',
714
+ 'progress',
715
+ 'q',
957
716
  'rowspan',
958
- 'scope',
959
- 'valign',
960
- 'width'
717
+ 's',
718
+ 'samp',
719
+ 'section',
720
+ 'select',
721
+ 'small',
722
+ 'source',
723
+ 'span',
724
+ 'strike',
725
+ 'strong',
726
+ 'sub',
727
+ 'summary',
728
+ 'sup',
729
+ 'table',
730
+ 'tbody',
731
+ 'td',
732
+ 'textarea',
733
+ 'tfoot',
734
+ 'th',
735
+ 'thead',
736
+ 'time',
737
+ 'tr',
738
+ 'track',
739
+ 'tt',
740
+ 'u',
741
+ 'ul',
742
+ 'var',
743
+ 'video',
744
+ 'wbr'
961
745
  ],
962
- thead: ['align', 'char', 'charoff', 'valign'],
963
- tr: ['align', 'bgcolor', 'char', 'charoff', 'valign'],
964
- track: ['default', 'kind', 'label', 'srclang'],
965
- ul: ['compact', 'type'],
966
- video: [
967
- 'autoplay',
968
- 'controls',
969
- 'height',
970
- 'loop',
971
- 'mediagroup',
972
- 'muted',
973
- 'poster',
974
- 'preload',
975
- 'src',
976
- 'width'
977
- ]
978
- },
979
- // Inline CSS styles that HTML tags may have (and their allowed values)
980
- allowedStyles: {
981
- // To simplify the data, all styles are allowed on all tags that allow the style attribute
982
- '*': {
983
- 'backface-visibility': [CssProp.BACKFACE_VISIBILITY],
984
- background: [CssProp.BACKGROUND],
985
- 'background-attachment': [CssProp.BACKGROUND_ATTACHMENT],
986
- 'background-clip': [CssProp.BACKGROUND_CLIP],
987
- 'background-color': [CssProp.BACKGROUND_COLOR],
988
- 'background-image': [CssProp.BACKGROUND_IMAGE],
989
- 'background-origin': [CssProp.BACKGROUND_ORIGIN],
990
- 'background-position': [CssProp.BACKGROUND_POSITION],
991
- 'background-repeat': [CssProp.BACKGROUND_REPEAT],
992
- 'background-size': [CssProp.BACKGROUND_SIZE],
993
- border: [CssProp.BORDER],
994
- 'border-bottom': [CssProp.BORDER_BOTTOM],
995
- 'border-bottom-color': [CssProp.BORDER_BOTTOM_COLOR],
996
- 'border-bottom-left-radius': [CssProp.BORDER_BOTTOM_LEFT_RADIUS],
997
- 'border-bottom-right-radius': [CssProp.BORDER_BOTTOM_RIGHT_RADIUS],
998
- 'border-bottom-style': [CssProp.BORDER_BOTTOM_STYLE],
999
- 'border-bottom-width': [CssProp.BORDER_BOTTOM_WIDTH],
1000
- 'border-collapse': [CssProp.BORDER_COLLAPSE],
1001
- 'border-color': [CssProp.BORDER_COLOR],
1002
- 'border-left': [CssProp.BORDER_LEFT],
1003
- 'border-left-color': [CssProp.BORDER_LEFT_COLOR],
1004
- 'border-left-style': [CssProp.BORDER_LEFT_STYLE],
1005
- 'border-left-width': [CssProp.BORDER_LEFT_WIDTH],
1006
- 'border-radius': [CssProp.BORDER_RADIUS],
1007
- 'border-right': [CssProp.BORDER_RIGHT],
1008
- 'border-right-color': [CssProp.BORDER_RIGHT_COLOR],
1009
- 'border-right-style': [CssProp.BORDER_RIGHT_STYLE],
1010
- 'border-right-width': [CssProp.BORDER_RIGHT_WIDTH],
1011
- 'border-spacing': [CssProp.BORDER_SPACING],
1012
- 'border-style': [CssProp.BORDER_STYLE],
1013
- 'border-top': [CssProp.BORDER_TOP],
1014
- 'border-top-color': [CssProp.BORDER_TOP_COLOR],
1015
- 'border-top-left-radius': [CssProp.BORDER_TOP_LEFT_RADIUS],
1016
- 'border-top-right-radius': [CssProp.BORDER_TOP_RIGHT_RADIUS],
1017
- 'border-top-style': [CssProp.BORDER_TOP_STYLE],
1018
- 'border-top-width': [CssProp.BORDER_TOP_WIDTH],
1019
- 'border-width': [CssProp.BORDER_WIDTH],
1020
- bottom: [CssProp.BOTTOM],
1021
- box: [CssProp.BOX],
1022
- 'box-shadow': [CssProp.BOX_SHADOW],
1023
- 'box-sizing': [CssProp.BOX_SIZING],
1024
- 'caption-side': [CssProp.CAPTION_SIDE],
1025
- clear: [CssProp.CLEAR],
1026
- clip: [CssProp.CLIP],
1027
- color: [CssProp.COLOR],
1028
- cursor: [CssProp.CURSOR],
1029
- direction: [CssProp.DIRECTION],
1030
- display: [CssProp.DISPLAY],
1031
- 'display-inside': [CssProp.DISPLAY_INSIDE],
1032
- 'display-outside': [CssProp.DISPLAY_OUTSIDE],
1033
- elevation: [CssProp.ELEVATION],
1034
- 'empty-cells': [CssProp.EMPTY_CELLS],
1035
- float: [CssProp.FLOAT],
1036
- font: [CssProp.FONT],
1037
- 'font-family': [CssProp.FONT_FAMILY],
1038
- 'font-size': [CssProp.FONT_SIZE],
1039
- 'font-stretch': [CssProp.FONT_STRETCH],
1040
- 'font-style': [CssProp.FONT_STYLE],
1041
- 'font-variant': [CssProp.FONT_VARIANT],
1042
- 'font-weight': [CssProp.FONT_WEIGHT],
1043
- height: [CssProp.HEIGHT],
1044
- left: [CssProp.LEFT],
1045
- 'letter-spacing': [CssProp.LETTER_SPACING],
1046
- 'line-height': [CssProp.LINE_HEIGHT],
1047
- 'list-style': [CssProp.LIST_STYLE],
1048
- 'list-style-image': [CssProp.LIST_STYLE_IMAGE],
1049
- 'list-style-position': [CssProp.LIST_STYLE_POSITION],
1050
- 'list-style-type': [CssProp.LIST_STYLE_TYPE],
1051
- margin: [CssProp.MARGIN],
1052
- 'margin-bottom': [CssProp.MARGIN_BOTTOM],
1053
- 'margin-left': [CssProp.MARGIN_LEFT],
1054
- 'margin-right': [CssProp.MARGIN_RIGHT],
1055
- 'margin-top': [CssProp.MARGIN_TOP],
1056
- 'max-height': [CssProp.MAX_HEIGHT],
1057
- 'max-width': [CssProp.MAX_WIDTH],
1058
- 'min-height': [CssProp.MIN_HEIGHT],
1059
- 'min-width': [CssProp.MIN_WIDTH],
1060
- opacity: [CssProp.OPACITY],
1061
- outline: [CssProp.OUTLINE],
1062
- 'outline-color': [CssProp.OUTLINE_COLOR],
1063
- 'outline-style': [CssProp.OUTLINE_STYLE],
1064
- 'outline-width': [CssProp.OUTLINE_WIDTH],
1065
- overflow: [CssProp.OVERFLOW],
1066
- 'overflow-wrap': [CssProp.OVERFLOW_WRAP],
1067
- 'overflow-x': [CssProp.OVERFLOW_X],
1068
- 'overflow-y': [CssProp.OVERFLOW_Y],
1069
- padding: [CssProp.PADDING],
1070
- 'padding-bottom': [CssProp.PADDING_BOTTOM],
1071
- 'padding-left': [CssProp.PADDING_LEFT],
1072
- 'padding-right': [CssProp.PADDING_RIGHT],
1073
- 'padding-top': [CssProp.PADDING_TOP],
1074
- 'page-break-after': [CssProp.PAGE_BREAK_AFTER],
1075
- 'page-break-before': [CssProp.PAGE_BREAK_BEFORE],
1076
- 'page-break-inside': [CssProp.PAGE_BREAK_INSIDE],
1077
- 'pause-after': [CssProp.PAUSE_AFTER],
1078
- perspective: [CssProp.PERSPECTIVE],
1079
- pitch: [CssProp.PITCH],
1080
- 'pitch-range': [CssProp.PITCH_RANGE],
1081
- position: [CssProp.POSITION],
1082
- quotes: [CssProp.QUOTES],
1083
- resize: [CssProp.RESIZE],
1084
- richness: [CssProp.RICHNESS],
1085
- right: [CssProp.RIGHT],
1086
- speak: [CssProp.SPEAK],
1087
- 'speak-header': [CssProp.SPEAK_HEADER],
1088
- 'speak-numeral': [CssProp.SPEAK_NUMERAL],
1089
- 'speak-punctuation': [CssProp.SPEAK_PUNCTUATION],
1090
- 'speech-rate': [CssProp.SPEECH_RATE],
1091
- stress: [CssProp.STRESS],
1092
- 'table-layout': [CssProp.TABLE_LAYOUT],
1093
- 'text-align': [CssProp.TEXT_ALIGN],
1094
- 'text-decoration': [CssProp.TEXT_DECORATION],
1095
- 'text-indent': [CssProp.TEXT_INDENT],
1096
- 'text-overflow': [CssProp.TEXT_OVERFLOW],
1097
- 'text-shadow': [CssProp.TEXT_SHADOW],
1098
- 'text-transform': [CssProp.TEXT_TRANSFORM],
1099
- 'text-wrap': [CssProp.TEXT_WRAP],
1100
- top: [CssProp.TOP],
1101
- 'unicode-bidi': [CssProp.UNICODE_BIDI],
1102
- 'vertical-align': [CssProp.VERTICAL_ALIGN],
1103
- visibility: [CssProp.VISIBILITY],
1104
- volume: [CssProp.VOLUME],
1105
- 'white-space': [CssProp.WHITE_SPACE],
1106
- width: [CssProp.WIDTH],
1107
- 'word-break': [CssProp.WORD_BREAK],
1108
- 'word-spacing': [CssProp.WORD_SPACING],
1109
- 'word-wrap': [CssProp.WORD_WRAP],
1110
- 'z-index': [CssProp.Z_INDEX],
1111
- zoom: [CssProp.ZOOM],
1112
- // Flexbox and Grid properties
1113
- 'align-content': [CssProp.ALIGN_CONTENT],
1114
- 'align-items': [CssProp.ALIGN_ITEMS],
1115
- 'align-self': [CssProp.ALIGN_SELF],
1116
- flex: [CssProp.FLEX],
1117
- 'flex-basis': [CssProp.FLEX_BASIS],
1118
- 'flex-direction': [CssProp.FLEX_DIRECTION],
1119
- 'flex-grow': [CssProp.FLEX_GROW],
1120
- 'flex-shrink': [CssProp.FLEX_SHRINK],
1121
- 'flex-wrap': [CssProp.FLEX_WRAP],
1122
- grid: [CssProp.GRID],
1123
- 'grid-area': [CssProp.GRID_AREA],
1124
- 'grid-auto-columns': [CssProp.GRID_AUTO_COLUMNS],
1125
- 'grid-auto-flow': [CssProp.GRID_AUTO_FLOW],
1126
- 'grid-auto-rows': [CssProp.GRID_AUTO_ROWS],
1127
- 'grid-column': [CssProp.GRID_COLUMN],
1128
- 'grid-column-end': [CssProp.GRID_COLUMN_END],
1129
- 'grid-column-gap': [CssProp.GRID_COLUMN_GAP],
1130
- 'grid-column-start': [CssProp.GRID_COLUMN_START],
1131
- 'grid-gap': [CssProp.GRID_GAP],
1132
- 'grid-row': [CssProp.GRID_ROW],
1133
- 'grid-row-end': [CssProp.GRID_ROW_END],
1134
- 'grid-row-gap': [CssProp.GRID_ROW_GAP],
1135
- 'grid-row-start': [CssProp.GRID_ROW_START],
1136
- 'grid-template': [CssProp.GRID_TEMPLATE],
1137
- 'grid-template-areas': [CssProp.GRID_TEMPLATE_AREAS],
1138
- 'grid-template-columns': [CssProp.GRID_TEMPLATE_COLUMNS],
1139
- 'grid-template-rows': [CssProp.GRID_TEMPLATE_ROWS],
1140
- gap: [CssProp.GAP],
1141
- 'row-gap': [CssProp.ROW_GAP],
1142
- 'column-gap': [CssProp.COLUMN_GAP],
1143
- 'justify-content': [CssProp.JUSTIFY_CONTENT],
1144
- 'justify-items': [CssProp.JUSTIFY_ITEMS],
1145
- 'justify-self': [CssProp.JUSTIFY_SELF],
1146
- order: [CssProp.ORDER],
1147
- 'place-content': [CssProp.PLACE_CONTENT],
1148
- 'place-items': [CssProp.PLACE_ITEMS],
1149
- 'place-self': [CssProp.PLACE_SELF]
1150
- }
1151
- },
1152
- transformTags: {
1153
- // Set the "rel" attribute for <a> tags to "nofollow".
1154
- a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
1155
- // Set the "disabled" attribute for <input> tags.
1156
- input: sanitize.simpleTransform('input', { disabled: 'disabled' })
1157
- },
1158
- allowedSchemes: [...sanitize.defaults.allowedSchemes],
1159
- allowedSchemesByTag: {
1160
- // Allow 'attachment:' img src (used for markdown cell attachments).
1161
- img: sanitize.defaults.allowedSchemes.concat(['attachment'])
1162
- },
1163
- // Override of the default option, so we can skip 'src' attribute validation.
1164
- // 'src' Attributes are validated to be URIs, which does not allow for embedded (image) data.
1165
- // Since embedded data is no longer deemed to be a threat, validation can be skipped.
1166
- // See https://github.com/jupyterlab/jupyterlab/issues/5183
1167
- allowedSchemesAppliedToAttributes: ['href', 'cite']
1168
- });
746
+ // Attributes that HTML tags are allowed to have, extracted from Google Caja.
747
+ // See https://github.com/jupyterlab/jupyterlab/issues/1812#issuecomment-285848435
748
+ allowedAttributes: {
749
+ '*': [
750
+ 'class',
751
+ 'data-jupyter-id',
752
+ 'dir',
753
+ 'draggable',
754
+ 'hidden',
755
+ 'id',
756
+ 'inert',
757
+ 'itemprop',
758
+ 'itemref',
759
+ 'itemscope',
760
+ 'lang',
761
+ 'spellcheck',
762
+ 'style',
763
+ 'title',
764
+ 'translate'
765
+ ],
766
+ // 'rel' and 'target' were *not* allowed by Google Caja
767
+ a: [
768
+ 'accesskey',
769
+ 'coords',
770
+ 'href',
771
+ 'hreflang',
772
+ ...(this._allowNamedProperties ? ['name'] : []),
773
+ 'rel',
774
+ 'shape',
775
+ 'tabindex',
776
+ 'target',
777
+ 'type'
778
+ ],
779
+ area: [
780
+ 'accesskey',
781
+ 'alt',
782
+ 'coords',
783
+ 'href',
784
+ 'nohref',
785
+ 'shape',
786
+ 'tabindex'
787
+ ],
788
+ // 'autoplay' was *not* allowed by Google Caja
789
+ audio: [
790
+ 'autoplay',
791
+ 'controls',
792
+ 'loop',
793
+ 'mediagroup',
794
+ 'muted',
795
+ 'preload',
796
+ 'src'
797
+ ],
798
+ bdo: ['dir'],
799
+ blockquote: ['cite'],
800
+ br: ['clear'],
801
+ button: [
802
+ 'accesskey',
803
+ 'data-commandlinker-args',
804
+ 'data-commandlinker-command',
805
+ 'disabled',
806
+ ...(this._allowNamedProperties ? ['name'] : []),
807
+ 'tabindex',
808
+ 'type',
809
+ 'value'
810
+ ],
811
+ canvas: ['height', 'width'],
812
+ caption: ['align'],
813
+ col: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
814
+ colgroup: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
815
+ command: [
816
+ 'checked',
817
+ 'command',
818
+ 'disabled',
819
+ 'icon',
820
+ 'label',
821
+ 'radiogroup',
822
+ 'type'
823
+ ],
824
+ data: ['value'],
825
+ del: ['cite', 'datetime'],
826
+ details: ['open'],
827
+ dir: ['compact'],
828
+ div: ['align'],
829
+ dl: ['compact'],
830
+ fieldset: ['disabled'],
831
+ font: ['color', 'face', 'size'],
832
+ form: [
833
+ 'accept',
834
+ 'autocomplete',
835
+ 'enctype',
836
+ 'method',
837
+ ...(this._allowNamedProperties ? ['name'] : []),
838
+ 'novalidate'
839
+ ],
840
+ h1: ['align'],
841
+ h2: ['align'],
842
+ h3: ['align'],
843
+ h4: ['align'],
844
+ h5: ['align'],
845
+ h6: ['align'],
846
+ hr: ['align', 'noshade', 'size', 'width'],
847
+ iframe: [
848
+ 'align',
849
+ 'frameborder',
850
+ 'height',
851
+ 'marginheight',
852
+ 'marginwidth',
853
+ 'width'
854
+ ],
855
+ img: [
856
+ 'align',
857
+ 'alt',
858
+ 'border',
859
+ 'height',
860
+ 'hspace',
861
+ 'ismap',
862
+ ...(this._allowNamedProperties ? ['name'] : []),
863
+ 'src',
864
+ 'usemap',
865
+ 'vspace',
866
+ 'width'
867
+ ],
868
+ input: [
869
+ 'accept',
870
+ 'accesskey',
871
+ 'align',
872
+ 'alt',
873
+ 'autocomplete',
874
+ 'checked',
875
+ 'disabled',
876
+ 'inputmode',
877
+ 'ismap',
878
+ 'list',
879
+ 'max',
880
+ 'maxlength',
881
+ 'min',
882
+ 'multiple',
883
+ ...(this._allowNamedProperties ? ['name'] : []),
884
+ 'placeholder',
885
+ 'readonly',
886
+ 'required',
887
+ 'size',
888
+ 'src',
889
+ 'step',
890
+ 'tabindex',
891
+ 'type',
892
+ 'usemap',
893
+ 'value'
894
+ ],
895
+ ins: ['cite', 'datetime'],
896
+ label: ['accesskey', 'for'],
897
+ legend: ['accesskey', 'align'],
898
+ li: ['type', 'value'],
899
+ map: this._allowNamedProperties ? ['name'] : [],
900
+ menu: ['compact', 'label', 'type'],
901
+ meter: ['high', 'low', 'max', 'min', 'value'],
902
+ ol: ['compact', 'reversed', 'start', 'type'],
903
+ optgroup: ['disabled', 'label'],
904
+ option: ['disabled', 'label', 'selected', 'value'],
905
+ output: ['for', ...(this._allowNamedProperties ? ['name'] : [])],
906
+ p: ['align'],
907
+ pre: ['width'],
908
+ progress: ['max', 'min', 'value'],
909
+ q: ['cite'],
910
+ select: [
911
+ 'autocomplete',
912
+ 'disabled',
913
+ 'multiple',
914
+ ...(this._allowNamedProperties ? ['name'] : []),
915
+ 'required',
916
+ 'size',
917
+ 'tabindex'
918
+ ],
919
+ source: ['type'],
920
+ table: [
921
+ 'align',
922
+ 'bgcolor',
923
+ 'border',
924
+ 'cellpadding',
925
+ 'cellspacing',
926
+ 'frame',
927
+ 'rules',
928
+ 'summary',
929
+ 'width'
930
+ ],
931
+ tbody: ['align', 'char', 'charoff', 'valign'],
932
+ td: [
933
+ 'abbr',
934
+ 'align',
935
+ 'axis',
936
+ 'bgcolor',
937
+ 'char',
938
+ 'charoff',
939
+ 'colspan',
940
+ 'headers',
941
+ 'height',
942
+ 'nowrap',
943
+ 'rowspan',
944
+ 'scope',
945
+ 'valign',
946
+ 'width'
947
+ ],
948
+ textarea: [
949
+ 'accesskey',
950
+ 'autocomplete',
951
+ 'cols',
952
+ 'disabled',
953
+ 'inputmode',
954
+ ...(this._allowNamedProperties ? ['name'] : []),
955
+ 'placeholder',
956
+ 'readonly',
957
+ 'required',
958
+ 'rows',
959
+ 'tabindex',
960
+ 'wrap'
961
+ ],
962
+ tfoot: ['align', 'char', 'charoff', 'valign'],
963
+ th: [
964
+ 'abbr',
965
+ 'align',
966
+ 'axis',
967
+ 'bgcolor',
968
+ 'char',
969
+ 'charoff',
970
+ 'colspan',
971
+ 'headers',
972
+ 'height',
973
+ 'nowrap',
974
+ 'rowspan',
975
+ 'scope',
976
+ 'valign',
977
+ 'width'
978
+ ],
979
+ thead: ['align', 'char', 'charoff', 'valign'],
980
+ tr: ['align', 'bgcolor', 'char', 'charoff', 'valign'],
981
+ track: ['default', 'kind', 'label', 'srclang'],
982
+ ul: ['compact', 'type'],
983
+ video: [
984
+ 'autoplay',
985
+ 'controls',
986
+ 'height',
987
+ 'loop',
988
+ 'mediagroup',
989
+ 'muted',
990
+ 'poster',
991
+ 'preload',
992
+ 'src',
993
+ 'width'
994
+ ]
995
+ },
996
+ // Inline CSS styles that HTML tags may have (and their allowed values)
997
+ allowedStyles: {
998
+ // To simplify the data, all styles are allowed on all tags that allow the style attribute
999
+ '*': {
1000
+ 'backface-visibility': [CssProp.BACKFACE_VISIBILITY],
1001
+ background: [CssProp.BACKGROUND],
1002
+ 'background-attachment': [CssProp.BACKGROUND_ATTACHMENT],
1003
+ 'background-clip': [CssProp.BACKGROUND_CLIP],
1004
+ 'background-color': [CssProp.BACKGROUND_COLOR],
1005
+ 'background-image': [CssProp.BACKGROUND_IMAGE],
1006
+ 'background-origin': [CssProp.BACKGROUND_ORIGIN],
1007
+ 'background-position': [CssProp.BACKGROUND_POSITION],
1008
+ 'background-repeat': [CssProp.BACKGROUND_REPEAT],
1009
+ 'background-size': [CssProp.BACKGROUND_SIZE],
1010
+ border: [CssProp.BORDER],
1011
+ 'border-bottom': [CssProp.BORDER_BOTTOM],
1012
+ 'border-bottom-color': [CssProp.BORDER_BOTTOM_COLOR],
1013
+ 'border-bottom-left-radius': [CssProp.BORDER_BOTTOM_LEFT_RADIUS],
1014
+ 'border-bottom-right-radius': [CssProp.BORDER_BOTTOM_RIGHT_RADIUS],
1015
+ 'border-bottom-style': [CssProp.BORDER_BOTTOM_STYLE],
1016
+ 'border-bottom-width': [CssProp.BORDER_BOTTOM_WIDTH],
1017
+ 'border-collapse': [CssProp.BORDER_COLLAPSE],
1018
+ 'border-color': [CssProp.BORDER_COLOR],
1019
+ 'border-left': [CssProp.BORDER_LEFT],
1020
+ 'border-left-color': [CssProp.BORDER_LEFT_COLOR],
1021
+ 'border-left-style': [CssProp.BORDER_LEFT_STYLE],
1022
+ 'border-left-width': [CssProp.BORDER_LEFT_WIDTH],
1023
+ 'border-radius': [CssProp.BORDER_RADIUS],
1024
+ 'border-right': [CssProp.BORDER_RIGHT],
1025
+ 'border-right-color': [CssProp.BORDER_RIGHT_COLOR],
1026
+ 'border-right-style': [CssProp.BORDER_RIGHT_STYLE],
1027
+ 'border-right-width': [CssProp.BORDER_RIGHT_WIDTH],
1028
+ 'border-spacing': [CssProp.BORDER_SPACING],
1029
+ 'border-style': [CssProp.BORDER_STYLE],
1030
+ 'border-top': [CssProp.BORDER_TOP],
1031
+ 'border-top-color': [CssProp.BORDER_TOP_COLOR],
1032
+ 'border-top-left-radius': [CssProp.BORDER_TOP_LEFT_RADIUS],
1033
+ 'border-top-right-radius': [CssProp.BORDER_TOP_RIGHT_RADIUS],
1034
+ 'border-top-style': [CssProp.BORDER_TOP_STYLE],
1035
+ 'border-top-width': [CssProp.BORDER_TOP_WIDTH],
1036
+ 'border-width': [CssProp.BORDER_WIDTH],
1037
+ bottom: [CssProp.BOTTOM],
1038
+ box: [CssProp.BOX],
1039
+ 'box-shadow': [CssProp.BOX_SHADOW],
1040
+ 'box-sizing': [CssProp.BOX_SIZING],
1041
+ 'caption-side': [CssProp.CAPTION_SIDE],
1042
+ clear: [CssProp.CLEAR],
1043
+ clip: [CssProp.CLIP],
1044
+ color: [CssProp.COLOR],
1045
+ cursor: [CssProp.CURSOR],
1046
+ direction: [CssProp.DIRECTION],
1047
+ display: [CssProp.DISPLAY],
1048
+ 'display-inside': [CssProp.DISPLAY_INSIDE],
1049
+ 'display-outside': [CssProp.DISPLAY_OUTSIDE],
1050
+ elevation: [CssProp.ELEVATION],
1051
+ 'empty-cells': [CssProp.EMPTY_CELLS],
1052
+ float: [CssProp.FLOAT],
1053
+ font: [CssProp.FONT],
1054
+ 'font-family': [CssProp.FONT_FAMILY],
1055
+ 'font-size': [CssProp.FONT_SIZE],
1056
+ 'font-stretch': [CssProp.FONT_STRETCH],
1057
+ 'font-style': [CssProp.FONT_STYLE],
1058
+ 'font-variant': [CssProp.FONT_VARIANT],
1059
+ 'font-weight': [CssProp.FONT_WEIGHT],
1060
+ height: [CssProp.HEIGHT],
1061
+ left: [CssProp.LEFT],
1062
+ 'letter-spacing': [CssProp.LETTER_SPACING],
1063
+ 'line-height': [CssProp.LINE_HEIGHT],
1064
+ 'list-style': [CssProp.LIST_STYLE],
1065
+ 'list-style-image': [CssProp.LIST_STYLE_IMAGE],
1066
+ 'list-style-position': [CssProp.LIST_STYLE_POSITION],
1067
+ 'list-style-type': [CssProp.LIST_STYLE_TYPE],
1068
+ margin: [CssProp.MARGIN],
1069
+ 'margin-bottom': [CssProp.MARGIN_BOTTOM],
1070
+ 'margin-left': [CssProp.MARGIN_LEFT],
1071
+ 'margin-right': [CssProp.MARGIN_RIGHT],
1072
+ 'margin-top': [CssProp.MARGIN_TOP],
1073
+ 'max-height': [CssProp.MAX_HEIGHT],
1074
+ 'max-width': [CssProp.MAX_WIDTH],
1075
+ 'min-height': [CssProp.MIN_HEIGHT],
1076
+ 'min-width': [CssProp.MIN_WIDTH],
1077
+ opacity: [CssProp.OPACITY],
1078
+ outline: [CssProp.OUTLINE],
1079
+ 'outline-color': [CssProp.OUTLINE_COLOR],
1080
+ 'outline-style': [CssProp.OUTLINE_STYLE],
1081
+ 'outline-width': [CssProp.OUTLINE_WIDTH],
1082
+ overflow: [CssProp.OVERFLOW],
1083
+ 'overflow-wrap': [CssProp.OVERFLOW_WRAP],
1084
+ 'overflow-x': [CssProp.OVERFLOW_X],
1085
+ 'overflow-y': [CssProp.OVERFLOW_Y],
1086
+ padding: [CssProp.PADDING],
1087
+ 'padding-bottom': [CssProp.PADDING_BOTTOM],
1088
+ 'padding-left': [CssProp.PADDING_LEFT],
1089
+ 'padding-right': [CssProp.PADDING_RIGHT],
1090
+ 'padding-top': [CssProp.PADDING_TOP],
1091
+ 'page-break-after': [CssProp.PAGE_BREAK_AFTER],
1092
+ 'page-break-before': [CssProp.PAGE_BREAK_BEFORE],
1093
+ 'page-break-inside': [CssProp.PAGE_BREAK_INSIDE],
1094
+ 'pause-after': [CssProp.PAUSE_AFTER],
1095
+ perspective: [CssProp.PERSPECTIVE],
1096
+ pitch: [CssProp.PITCH],
1097
+ 'pitch-range': [CssProp.PITCH_RANGE],
1098
+ position: [CssProp.POSITION],
1099
+ quotes: [CssProp.QUOTES],
1100
+ resize: [CssProp.RESIZE],
1101
+ richness: [CssProp.RICHNESS],
1102
+ right: [CssProp.RIGHT],
1103
+ speak: [CssProp.SPEAK],
1104
+ 'speak-header': [CssProp.SPEAK_HEADER],
1105
+ 'speak-numeral': [CssProp.SPEAK_NUMERAL],
1106
+ 'speak-punctuation': [CssProp.SPEAK_PUNCTUATION],
1107
+ 'speech-rate': [CssProp.SPEECH_RATE],
1108
+ stress: [CssProp.STRESS],
1109
+ 'table-layout': [CssProp.TABLE_LAYOUT],
1110
+ 'text-align': [CssProp.TEXT_ALIGN],
1111
+ 'text-decoration': [CssProp.TEXT_DECORATION],
1112
+ 'text-indent': [CssProp.TEXT_INDENT],
1113
+ 'text-overflow': [CssProp.TEXT_OVERFLOW],
1114
+ 'text-shadow': [CssProp.TEXT_SHADOW],
1115
+ 'text-transform': [CssProp.TEXT_TRANSFORM],
1116
+ 'text-wrap': [CssProp.TEXT_WRAP],
1117
+ top: [CssProp.TOP],
1118
+ 'unicode-bidi': [CssProp.UNICODE_BIDI],
1119
+ 'vertical-align': [CssProp.VERTICAL_ALIGN],
1120
+ visibility: [CssProp.VISIBILITY],
1121
+ volume: [CssProp.VOLUME],
1122
+ 'white-space': [CssProp.WHITE_SPACE],
1123
+ width: [CssProp.WIDTH],
1124
+ 'word-break': [CssProp.WORD_BREAK],
1125
+ 'word-spacing': [CssProp.WORD_SPACING],
1126
+ 'word-wrap': [CssProp.WORD_WRAP],
1127
+ 'z-index': [CssProp.Z_INDEX],
1128
+ zoom: [CssProp.ZOOM],
1129
+ // Flexbox and Grid properties
1130
+ 'align-content': [CssProp.ALIGN_CONTENT],
1131
+ 'align-items': [CssProp.ALIGN_ITEMS],
1132
+ 'align-self': [CssProp.ALIGN_SELF],
1133
+ flex: [CssProp.FLEX],
1134
+ 'flex-basis': [CssProp.FLEX_BASIS],
1135
+ 'flex-direction': [CssProp.FLEX_DIRECTION],
1136
+ 'flex-grow': [CssProp.FLEX_GROW],
1137
+ 'flex-shrink': [CssProp.FLEX_SHRINK],
1138
+ 'flex-wrap': [CssProp.FLEX_WRAP],
1139
+ grid: [CssProp.GRID],
1140
+ 'grid-area': [CssProp.GRID_AREA],
1141
+ 'grid-auto-columns': [CssProp.GRID_AUTO_COLUMNS],
1142
+ 'grid-auto-flow': [CssProp.GRID_AUTO_FLOW],
1143
+ 'grid-auto-rows': [CssProp.GRID_AUTO_ROWS],
1144
+ 'grid-column': [CssProp.GRID_COLUMN],
1145
+ 'grid-column-end': [CssProp.GRID_COLUMN_END],
1146
+ 'grid-column-gap': [CssProp.GRID_COLUMN_GAP],
1147
+ 'grid-column-start': [CssProp.GRID_COLUMN_START],
1148
+ 'grid-gap': [CssProp.GRID_GAP],
1149
+ 'grid-row': [CssProp.GRID_ROW],
1150
+ 'grid-row-end': [CssProp.GRID_ROW_END],
1151
+ 'grid-row-gap': [CssProp.GRID_ROW_GAP],
1152
+ 'grid-row-start': [CssProp.GRID_ROW_START],
1153
+ 'grid-template': [CssProp.GRID_TEMPLATE],
1154
+ 'grid-template-areas': [CssProp.GRID_TEMPLATE_AREAS],
1155
+ 'grid-template-columns': [CssProp.GRID_TEMPLATE_COLUMNS],
1156
+ 'grid-template-rows': [CssProp.GRID_TEMPLATE_ROWS],
1157
+ gap: [CssProp.GAP],
1158
+ 'row-gap': [CssProp.ROW_GAP],
1159
+ 'column-gap': [CssProp.COLUMN_GAP],
1160
+ 'justify-content': [CssProp.JUSTIFY_CONTENT],
1161
+ 'justify-items': [CssProp.JUSTIFY_ITEMS],
1162
+ 'justify-self': [CssProp.JUSTIFY_SELF],
1163
+ order: [CssProp.ORDER],
1164
+ 'place-content': [CssProp.PLACE_CONTENT],
1165
+ 'place-items': [CssProp.PLACE_ITEMS],
1166
+ 'place-self': [CssProp.PLACE_SELF]
1167
+ }
1168
+ },
1169
+ transformTags: {
1170
+ // Set the "rel" attribute for <a> tags to "nofollow".
1171
+ a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
1172
+ // Set the "disabled" attribute for <input> tags.
1173
+ input: sanitize.simpleTransform('input', { disabled: 'disabled' }),
1174
+ // Replace "id" attribute by "data-jupyter-id" if "id" is not allowed.
1175
+ ...(this._allowNamedProperties
1176
+ ? {}
1177
+ : {
1178
+ '*': function (tagName: string, attribs: sanitize.Attributes) {
1179
+ if (attribs.id !== undefined) {
1180
+ attribs['data-jupyter-id'] = attribs.id;
1181
+ delete attribs.id;
1182
+ }
1183
+ return {
1184
+ tagName,
1185
+ attribs: {
1186
+ ...attribs
1187
+ }
1188
+ };
1189
+ }
1190
+ })
1191
+ },
1192
+ allowedSchemes: schemesToAllow,
1193
+ allowedSchemesByTag: {
1194
+ // Allow 'attachment:' img src (used for markdown cell attachments).
1195
+ img: [...schemesToAllow, 'attachment']
1196
+ },
1197
+ // Override of the default option, so we can skip 'src' attribute validation.
1198
+ // 'src' Attributes are validated to be URIs, which does not allow for embedded (image) data.
1199
+ // Since embedded data is no longer deemed to be a threat, validation can be skipped.
1200
+ // See https://github.com/jupyterlab/jupyterlab/issues/5183
1201
+ allowedSchemesAppliedToAttributes: ['href', 'cite']
1202
+ };
1203
+ };
1169
1204
  }