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