@jupyterlab/apputils 4.4.6 → 4.4.8

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
@@ -408,514 +408,519 @@ export class Sanitizer {
408
408
  constructor() {
409
409
  this._autolink = true;
410
410
  this._allowNamedProperties = false;
411
- this._generateOptions = () => ({
412
- // HTML tags that are allowed to be used. Tags were extracted from Google Caja
413
- allowedTags: [
414
- 'a',
415
- 'abbr',
416
- 'acronym',
417
- 'address',
418
- 'area',
419
- 'article',
420
- 'aside',
421
- 'audio',
422
- 'b',
423
- 'bdi',
424
- 'bdo',
425
- 'big',
426
- 'blockquote',
427
- 'br',
428
- 'button',
429
- 'canvas',
430
- 'caption',
431
- 'center',
432
- 'cite',
433
- 'code',
434
- 'col',
435
- 'colgroup',
436
- 'colspan',
437
- 'command',
438
- 'data',
439
- 'datalist',
440
- 'dd',
441
- 'del',
442
- 'details',
443
- 'dfn',
444
- 'dir',
445
- 'div',
446
- 'dl',
447
- 'dt',
448
- 'em',
449
- 'fieldset',
450
- 'figcaption',
451
- 'figure',
452
- 'font',
453
- 'footer',
454
- 'form',
455
- 'h1',
456
- 'h2',
457
- 'h3',
458
- 'h4',
459
- 'h5',
460
- 'h6',
461
- 'header',
462
- 'hgroup',
463
- 'hr',
464
- 'i',
465
- // 'iframe' is allowed by Google Caja, but disallowed by default by sanitize-html
466
- // , 'iframe'
467
- 'img',
468
- 'input',
469
- 'ins',
470
- 'kbd',
471
- 'label',
472
- 'legend',
473
- 'li',
474
- 'map',
475
- 'mark',
476
- 'menu',
477
- 'meter',
478
- 'nav',
479
- 'nobr',
480
- 'ol',
481
- 'optgroup',
482
- 'option',
483
- 'output',
484
- 'p',
485
- 'pre',
486
- 'progress',
487
- 'q',
488
- 'rowspan',
489
- 's',
490
- 'samp',
491
- 'section',
492
- 'select',
493
- 'small',
494
- 'source',
495
- 'span',
496
- 'strike',
497
- 'strong',
498
- 'sub',
499
- 'summary',
500
- 'sup',
501
- 'table',
502
- 'tbody',
503
- 'td',
504
- 'textarea',
505
- 'tfoot',
506
- 'th',
507
- 'thead',
508
- 'time',
509
- 'tr',
510
- 'track',
511
- 'tt',
512
- 'u',
513
- 'ul',
514
- 'var',
515
- 'video',
516
- 'wbr'
517
- ],
518
- // Attributes that HTML tags are allowed to have, extracted from Google Caja.
519
- // See https://github.com/jupyterlab/jupyterlab/issues/1812#issuecomment-285848435
520
- allowedAttributes: {
521
- '*': [
522
- 'class',
523
- 'dir',
524
- 'draggable',
525
- 'hidden',
526
- ...(this._allowNamedProperties ? ['id'] : []),
527
- 'inert',
528
- 'itemprop',
529
- 'itemref',
530
- 'itemscope',
531
- 'lang',
532
- 'spellcheck',
533
- 'style',
534
- 'title',
535
- 'translate'
536
- ],
537
- // 'rel' and 'target' were *not* allowed by Google Caja
538
- a: [
539
- 'accesskey',
540
- 'coords',
541
- 'href',
542
- 'hreflang',
543
- ...(this._allowNamedProperties ? ['name'] : []),
544
- 'rel',
545
- 'shape',
546
- 'tabindex',
547
- 'target',
548
- 'type'
549
- ],
550
- area: [
551
- 'accesskey',
552
- 'alt',
553
- 'coords',
554
- 'href',
555
- 'nohref',
556
- 'shape',
557
- 'tabindex'
558
- ],
559
- // 'autoplay' was *not* allowed by Google Caja
560
- audio: [
561
- 'autoplay',
562
- 'controls',
563
- 'loop',
564
- 'mediagroup',
565
- 'muted',
566
- 'preload',
567
- 'src'
568
- ],
569
- bdo: ['dir'],
570
- blockquote: ['cite'],
571
- br: ['clear'],
572
- button: [
573
- 'accesskey',
574
- 'data-commandlinker-args',
575
- 'data-commandlinker-command',
576
- 'disabled',
577
- ...(this._allowNamedProperties ? ['name'] : []),
578
- 'tabindex',
579
- 'type',
580
- 'value'
581
- ],
582
- canvas: ['height', 'width'],
583
- caption: ['align'],
584
- col: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
585
- colgroup: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
586
- command: [
587
- 'checked',
588
- 'command',
589
- 'disabled',
590
- 'icon',
591
- 'label',
592
- 'radiogroup',
593
- 'type'
594
- ],
595
- data: ['value'],
596
- del: ['cite', 'datetime'],
597
- details: ['open'],
598
- dir: ['compact'],
599
- div: ['align'],
600
- dl: ['compact'],
601
- fieldset: ['disabled'],
602
- font: ['color', 'face', 'size'],
603
- form: [
604
- 'accept',
605
- 'autocomplete',
606
- 'enctype',
607
- 'method',
608
- ...(this._allowNamedProperties ? ['name'] : []),
609
- 'novalidate'
610
- ],
611
- h1: ['align'],
612
- h2: ['align'],
613
- h3: ['align'],
614
- h4: ['align'],
615
- h5: ['align'],
616
- h6: ['align'],
617
- hr: ['align', 'noshade', 'size', 'width'],
618
- iframe: [
619
- 'align',
620
- 'frameborder',
621
- 'height',
622
- 'marginheight',
623
- 'marginwidth',
624
- 'width'
625
- ],
626
- img: [
627
- 'align',
628
- 'alt',
629
- 'border',
630
- 'height',
631
- 'hspace',
632
- 'ismap',
633
- ...(this._allowNamedProperties ? ['name'] : []),
634
- 'src',
635
- 'usemap',
636
- 'vspace',
637
- 'width'
638
- ],
639
- input: [
640
- 'accept',
641
- 'accesskey',
642
- 'align',
643
- 'alt',
644
- 'autocomplete',
645
- 'checked',
646
- 'disabled',
647
- 'inputmode',
648
- 'ismap',
649
- 'list',
650
- 'max',
651
- 'maxlength',
652
- 'min',
653
- 'multiple',
654
- ...(this._allowNamedProperties ? ['name'] : []),
655
- 'placeholder',
656
- 'readonly',
657
- 'required',
658
- 'size',
659
- 'src',
660
- 'step',
661
- 'tabindex',
662
- 'type',
663
- 'usemap',
664
- 'value'
665
- ],
666
- ins: ['cite', 'datetime'],
667
- label: ['accesskey', 'for'],
668
- legend: ['accesskey', 'align'],
669
- li: ['type', 'value'],
670
- map: this._allowNamedProperties ? ['name'] : [],
671
- menu: ['compact', 'label', 'type'],
672
- meter: ['high', 'low', 'max', 'min', 'value'],
673
- ol: ['compact', 'reversed', 'start', 'type'],
674
- optgroup: ['disabled', 'label'],
675
- option: ['disabled', 'label', 'selected', 'value'],
676
- output: ['for', ...(this._allowNamedProperties ? ['name'] : [])],
677
- p: ['align'],
678
- pre: ['width'],
679
- progress: ['max', 'min', 'value'],
680
- q: ['cite'],
681
- select: [
682
- 'autocomplete',
683
- 'disabled',
684
- 'multiple',
685
- ...(this._allowNamedProperties ? ['name'] : []),
686
- 'required',
687
- 'size',
688
- 'tabindex'
689
- ],
690
- source: ['type'],
691
- table: [
692
- 'align',
693
- 'bgcolor',
694
- 'border',
695
- 'cellpadding',
696
- 'cellspacing',
697
- 'frame',
698
- 'rules',
699
- 'summary',
700
- 'width'
701
- ],
702
- tbody: ['align', 'char', 'charoff', 'valign'],
703
- td: [
411
+ this._generateOptions = () => {
412
+ const schemesToAllow = Array.isArray(this._customAllowedSchemes)
413
+ ? this._customAllowedSchemes
414
+ : [...sanitize.defaults.allowedSchemes];
415
+ return {
416
+ // HTML tags that are allowed to be used. Tags were extracted from Google Caja
417
+ allowedTags: [
418
+ 'a',
704
419
  'abbr',
705
- 'align',
706
- 'axis',
707
- 'bgcolor',
708
- 'char',
709
- 'charoff',
420
+ 'acronym',
421
+ 'address',
422
+ 'area',
423
+ 'article',
424
+ 'aside',
425
+ 'audio',
426
+ 'b',
427
+ 'bdi',
428
+ 'bdo',
429
+ 'big',
430
+ 'blockquote',
431
+ 'br',
432
+ 'button',
433
+ 'canvas',
434
+ 'caption',
435
+ 'center',
436
+ 'cite',
437
+ 'code',
438
+ 'col',
439
+ 'colgroup',
710
440
  'colspan',
711
- 'headers',
712
- 'height',
713
- 'nowrap',
714
- 'rowspan',
715
- 'scope',
716
- 'valign',
717
- 'width'
718
- ],
719
- textarea: [
720
- 'accesskey',
721
- 'autocomplete',
722
- 'cols',
723
- 'disabled',
724
- 'inputmode',
725
- ...(this._allowNamedProperties ? ['name'] : []),
726
- 'placeholder',
727
- 'readonly',
728
- 'required',
729
- 'rows',
730
- 'tabindex',
731
- 'wrap'
732
- ],
733
- tfoot: ['align', 'char', 'charoff', 'valign'],
734
- th: [
735
- 'abbr',
736
- 'align',
737
- 'axis',
738
- 'bgcolor',
739
- 'char',
740
- 'charoff',
741
- 'colspan',
742
- 'headers',
743
- 'height',
744
- 'nowrap',
441
+ 'command',
442
+ 'data',
443
+ 'datalist',
444
+ 'dd',
445
+ 'del',
446
+ 'details',
447
+ 'dfn',
448
+ 'dir',
449
+ 'div',
450
+ 'dl',
451
+ 'dt',
452
+ 'em',
453
+ 'fieldset',
454
+ 'figcaption',
455
+ 'figure',
456
+ 'font',
457
+ 'footer',
458
+ 'form',
459
+ 'h1',
460
+ 'h2',
461
+ 'h3',
462
+ 'h4',
463
+ 'h5',
464
+ 'h6',
465
+ 'header',
466
+ 'hgroup',
467
+ 'hr',
468
+ 'i',
469
+ // 'iframe' is allowed by Google Caja, but disallowed by default by sanitize-html
470
+ // , 'iframe'
471
+ 'img',
472
+ 'input',
473
+ 'ins',
474
+ 'kbd',
475
+ 'label',
476
+ 'legend',
477
+ 'li',
478
+ 'map',
479
+ 'mark',
480
+ 'menu',
481
+ 'meter',
482
+ 'nav',
483
+ 'nobr',
484
+ 'ol',
485
+ 'optgroup',
486
+ 'option',
487
+ 'output',
488
+ 'p',
489
+ 'pre',
490
+ 'progress',
491
+ 'q',
745
492
  'rowspan',
746
- 'scope',
747
- 'valign',
748
- 'width'
493
+ 's',
494
+ 'samp',
495
+ 'section',
496
+ 'select',
497
+ 'small',
498
+ 'source',
499
+ 'span',
500
+ 'strike',
501
+ 'strong',
502
+ 'sub',
503
+ 'summary',
504
+ 'sup',
505
+ 'table',
506
+ 'tbody',
507
+ 'td',
508
+ 'textarea',
509
+ 'tfoot',
510
+ 'th',
511
+ 'thead',
512
+ 'time',
513
+ 'tr',
514
+ 'track',
515
+ 'tt',
516
+ 'u',
517
+ 'ul',
518
+ 'var',
519
+ 'video',
520
+ 'wbr'
749
521
  ],
750
- thead: ['align', 'char', 'charoff', 'valign'],
751
- tr: ['align', 'bgcolor', 'char', 'charoff', 'valign'],
752
- track: ['default', 'kind', 'label', 'srclang'],
753
- ul: ['compact', 'type'],
754
- video: [
755
- 'autoplay',
756
- 'controls',
757
- 'height',
758
- 'loop',
759
- 'mediagroup',
760
- 'muted',
761
- 'poster',
762
- 'preload',
763
- 'src',
764
- 'width'
765
- ]
766
- },
767
- // Inline CSS styles that HTML tags may have (and their allowed values)
768
- allowedStyles: {
769
- // To simplify the data, all styles are allowed on all tags that allow the style attribute
770
- '*': {
771
- 'backface-visibility': [CssProp.BACKFACE_VISIBILITY],
772
- background: [CssProp.BACKGROUND],
773
- 'background-attachment': [CssProp.BACKGROUND_ATTACHMENT],
774
- 'background-clip': [CssProp.BACKGROUND_CLIP],
775
- 'background-color': [CssProp.BACKGROUND_COLOR],
776
- 'background-image': [CssProp.BACKGROUND_IMAGE],
777
- 'background-origin': [CssProp.BACKGROUND_ORIGIN],
778
- 'background-position': [CssProp.BACKGROUND_POSITION],
779
- 'background-repeat': [CssProp.BACKGROUND_REPEAT],
780
- 'background-size': [CssProp.BACKGROUND_SIZE],
781
- border: [CssProp.BORDER],
782
- 'border-bottom': [CssProp.BORDER_BOTTOM],
783
- 'border-bottom-color': [CssProp.BORDER_BOTTOM_COLOR],
784
- 'border-bottom-left-radius': [CssProp.BORDER_BOTTOM_LEFT_RADIUS],
785
- 'border-bottom-right-radius': [CssProp.BORDER_BOTTOM_RIGHT_RADIUS],
786
- 'border-bottom-style': [CssProp.BORDER_BOTTOM_STYLE],
787
- 'border-bottom-width': [CssProp.BORDER_BOTTOM_WIDTH],
788
- 'border-collapse': [CssProp.BORDER_COLLAPSE],
789
- 'border-color': [CssProp.BORDER_COLOR],
790
- 'border-left': [CssProp.BORDER_LEFT],
791
- 'border-left-color': [CssProp.BORDER_LEFT_COLOR],
792
- 'border-left-style': [CssProp.BORDER_LEFT_STYLE],
793
- 'border-left-width': [CssProp.BORDER_LEFT_WIDTH],
794
- 'border-radius': [CssProp.BORDER_RADIUS],
795
- 'border-right': [CssProp.BORDER_RIGHT],
796
- 'border-right-color': [CssProp.BORDER_RIGHT_COLOR],
797
- 'border-right-style': [CssProp.BORDER_RIGHT_STYLE],
798
- 'border-right-width': [CssProp.BORDER_RIGHT_WIDTH],
799
- 'border-spacing': [CssProp.BORDER_SPACING],
800
- 'border-style': [CssProp.BORDER_STYLE],
801
- 'border-top': [CssProp.BORDER_TOP],
802
- 'border-top-color': [CssProp.BORDER_TOP_COLOR],
803
- 'border-top-left-radius': [CssProp.BORDER_TOP_LEFT_RADIUS],
804
- 'border-top-right-radius': [CssProp.BORDER_TOP_RIGHT_RADIUS],
805
- 'border-top-style': [CssProp.BORDER_TOP_STYLE],
806
- 'border-top-width': [CssProp.BORDER_TOP_WIDTH],
807
- 'border-width': [CssProp.BORDER_WIDTH],
808
- bottom: [CssProp.BOTTOM],
809
- box: [CssProp.BOX],
810
- 'box-shadow': [CssProp.BOX_SHADOW],
811
- 'box-sizing': [CssProp.BOX_SIZING],
812
- 'caption-side': [CssProp.CAPTION_SIDE],
813
- clear: [CssProp.CLEAR],
814
- clip: [CssProp.CLIP],
815
- color: [CssProp.COLOR],
816
- cursor: [CssProp.CURSOR],
817
- direction: [CssProp.DIRECTION],
818
- display: [CssProp.DISPLAY],
819
- 'display-inside': [CssProp.DISPLAY_INSIDE],
820
- 'display-outside': [CssProp.DISPLAY_OUTSIDE],
821
- elevation: [CssProp.ELEVATION],
822
- 'empty-cells': [CssProp.EMPTY_CELLS],
823
- float: [CssProp.FLOAT],
824
- font: [CssProp.FONT],
825
- 'font-family': [CssProp.FONT_FAMILY],
826
- 'font-size': [CssProp.FONT_SIZE],
827
- 'font-stretch': [CssProp.FONT_STRETCH],
828
- 'font-style': [CssProp.FONT_STYLE],
829
- 'font-variant': [CssProp.FONT_VARIANT],
830
- 'font-weight': [CssProp.FONT_WEIGHT],
831
- height: [CssProp.HEIGHT],
832
- left: [CssProp.LEFT],
833
- 'letter-spacing': [CssProp.LETTER_SPACING],
834
- 'line-height': [CssProp.LINE_HEIGHT],
835
- 'list-style': [CssProp.LIST_STYLE],
836
- 'list-style-image': [CssProp.LIST_STYLE_IMAGE],
837
- 'list-style-position': [CssProp.LIST_STYLE_POSITION],
838
- 'list-style-type': [CssProp.LIST_STYLE_TYPE],
839
- margin: [CssProp.MARGIN],
840
- 'margin-bottom': [CssProp.MARGIN_BOTTOM],
841
- 'margin-left': [CssProp.MARGIN_LEFT],
842
- 'margin-right': [CssProp.MARGIN_RIGHT],
843
- 'margin-top': [CssProp.MARGIN_TOP],
844
- 'max-height': [CssProp.MAX_HEIGHT],
845
- 'max-width': [CssProp.MAX_WIDTH],
846
- 'min-height': [CssProp.MIN_HEIGHT],
847
- 'min-width': [CssProp.MIN_WIDTH],
848
- opacity: [CssProp.OPACITY],
849
- outline: [CssProp.OUTLINE],
850
- 'outline-color': [CssProp.OUTLINE_COLOR],
851
- 'outline-style': [CssProp.OUTLINE_STYLE],
852
- 'outline-width': [CssProp.OUTLINE_WIDTH],
853
- overflow: [CssProp.OVERFLOW],
854
- 'overflow-wrap': [CssProp.OVERFLOW_WRAP],
855
- 'overflow-x': [CssProp.OVERFLOW_X],
856
- 'overflow-y': [CssProp.OVERFLOW_Y],
857
- padding: [CssProp.PADDING],
858
- 'padding-bottom': [CssProp.PADDING_BOTTOM],
859
- 'padding-left': [CssProp.PADDING_LEFT],
860
- 'padding-right': [CssProp.PADDING_RIGHT],
861
- 'padding-top': [CssProp.PADDING_TOP],
862
- 'page-break-after': [CssProp.PAGE_BREAK_AFTER],
863
- 'page-break-before': [CssProp.PAGE_BREAK_BEFORE],
864
- 'page-break-inside': [CssProp.PAGE_BREAK_INSIDE],
865
- 'pause-after': [CssProp.PAUSE_AFTER],
866
- perspective: [CssProp.PERSPECTIVE],
867
- pitch: [CssProp.PITCH],
868
- 'pitch-range': [CssProp.PITCH_RANGE],
869
- position: [CssProp.POSITION],
870
- quotes: [CssProp.QUOTES],
871
- resize: [CssProp.RESIZE],
872
- richness: [CssProp.RICHNESS],
873
- right: [CssProp.RIGHT],
874
- speak: [CssProp.SPEAK],
875
- 'speak-header': [CssProp.SPEAK_HEADER],
876
- 'speak-numeral': [CssProp.SPEAK_NUMERAL],
877
- 'speak-punctuation': [CssProp.SPEAK_PUNCTUATION],
878
- 'speech-rate': [CssProp.SPEECH_RATE],
879
- stress: [CssProp.STRESS],
880
- 'table-layout': [CssProp.TABLE_LAYOUT],
881
- 'text-align': [CssProp.TEXT_ALIGN],
882
- 'text-decoration': [CssProp.TEXT_DECORATION],
883
- 'text-indent': [CssProp.TEXT_INDENT],
884
- 'text-overflow': [CssProp.TEXT_OVERFLOW],
885
- 'text-shadow': [CssProp.TEXT_SHADOW],
886
- 'text-transform': [CssProp.TEXT_TRANSFORM],
887
- 'text-wrap': [CssProp.TEXT_WRAP],
888
- top: [CssProp.TOP],
889
- 'unicode-bidi': [CssProp.UNICODE_BIDI],
890
- 'vertical-align': [CssProp.VERTICAL_ALIGN],
891
- visibility: [CssProp.VISIBILITY],
892
- volume: [CssProp.VOLUME],
893
- 'white-space': [CssProp.WHITE_SPACE],
894
- width: [CssProp.WIDTH],
895
- 'word-break': [CssProp.WORD_BREAK],
896
- 'word-spacing': [CssProp.WORD_SPACING],
897
- 'word-wrap': [CssProp.WORD_WRAP],
898
- 'z-index': [CssProp.Z_INDEX],
899
- zoom: [CssProp.ZOOM]
900
- }
901
- },
902
- transformTags: {
903
- // Set the "rel" attribute for <a> tags to "nofollow".
904
- a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
905
- // Set the "disabled" attribute for <input> tags.
906
- input: sanitize.simpleTransform('input', { disabled: 'disabled' })
907
- },
908
- allowedSchemes: [...sanitize.defaults.allowedSchemes],
909
- allowedSchemesByTag: {
910
- // Allow 'attachment:' img src (used for markdown cell attachments).
911
- img: sanitize.defaults.allowedSchemes.concat(['attachment'])
912
- },
913
- // Override of the default option, so we can skip 'src' attribute validation.
914
- // 'src' Attributes are validated to be URIs, which does not allow for embedded (image) data.
915
- // Since embedded data is no longer deemed to be a threat, validation can be skipped.
916
- // See https://github.com/jupyterlab/jupyterlab/issues/5183
917
- allowedSchemesAppliedToAttributes: ['href', 'cite']
918
- });
522
+ // Attributes that HTML tags are allowed to have, extracted from Google Caja.
523
+ // See https://github.com/jupyterlab/jupyterlab/issues/1812#issuecomment-285848435
524
+ allowedAttributes: {
525
+ '*': [
526
+ 'class',
527
+ 'dir',
528
+ 'draggable',
529
+ 'hidden',
530
+ ...(this._allowNamedProperties ? ['id'] : []),
531
+ 'inert',
532
+ 'itemprop',
533
+ 'itemref',
534
+ 'itemscope',
535
+ 'lang',
536
+ 'spellcheck',
537
+ 'style',
538
+ 'title',
539
+ 'translate'
540
+ ],
541
+ // 'rel' and 'target' were *not* allowed by Google Caja
542
+ a: [
543
+ 'accesskey',
544
+ 'coords',
545
+ 'href',
546
+ 'hreflang',
547
+ ...(this._allowNamedProperties ? ['name'] : []),
548
+ 'rel',
549
+ 'shape',
550
+ 'tabindex',
551
+ 'target',
552
+ 'type'
553
+ ],
554
+ area: [
555
+ 'accesskey',
556
+ 'alt',
557
+ 'coords',
558
+ 'href',
559
+ 'nohref',
560
+ 'shape',
561
+ 'tabindex'
562
+ ],
563
+ // 'autoplay' was *not* allowed by Google Caja
564
+ audio: [
565
+ 'autoplay',
566
+ 'controls',
567
+ 'loop',
568
+ 'mediagroup',
569
+ 'muted',
570
+ 'preload',
571
+ 'src'
572
+ ],
573
+ bdo: ['dir'],
574
+ blockquote: ['cite'],
575
+ br: ['clear'],
576
+ button: [
577
+ 'accesskey',
578
+ 'data-commandlinker-args',
579
+ 'data-commandlinker-command',
580
+ 'disabled',
581
+ ...(this._allowNamedProperties ? ['name'] : []),
582
+ 'tabindex',
583
+ 'type',
584
+ 'value'
585
+ ],
586
+ canvas: ['height', 'width'],
587
+ caption: ['align'],
588
+ col: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
589
+ colgroup: ['align', 'char', 'charoff', 'span', 'valign', 'width'],
590
+ command: [
591
+ 'checked',
592
+ 'command',
593
+ 'disabled',
594
+ 'icon',
595
+ 'label',
596
+ 'radiogroup',
597
+ 'type'
598
+ ],
599
+ data: ['value'],
600
+ del: ['cite', 'datetime'],
601
+ details: ['open'],
602
+ dir: ['compact'],
603
+ div: ['align'],
604
+ dl: ['compact'],
605
+ fieldset: ['disabled'],
606
+ font: ['color', 'face', 'size'],
607
+ form: [
608
+ 'accept',
609
+ 'autocomplete',
610
+ 'enctype',
611
+ 'method',
612
+ ...(this._allowNamedProperties ? ['name'] : []),
613
+ 'novalidate'
614
+ ],
615
+ h1: ['align'],
616
+ h2: ['align'],
617
+ h3: ['align'],
618
+ h4: ['align'],
619
+ h5: ['align'],
620
+ h6: ['align'],
621
+ hr: ['align', 'noshade', 'size', 'width'],
622
+ iframe: [
623
+ 'align',
624
+ 'frameborder',
625
+ 'height',
626
+ 'marginheight',
627
+ 'marginwidth',
628
+ 'width'
629
+ ],
630
+ img: [
631
+ 'align',
632
+ 'alt',
633
+ 'border',
634
+ 'height',
635
+ 'hspace',
636
+ 'ismap',
637
+ ...(this._allowNamedProperties ? ['name'] : []),
638
+ 'src',
639
+ 'usemap',
640
+ 'vspace',
641
+ 'width'
642
+ ],
643
+ input: [
644
+ 'accept',
645
+ 'accesskey',
646
+ 'align',
647
+ 'alt',
648
+ 'autocomplete',
649
+ 'checked',
650
+ 'disabled',
651
+ 'inputmode',
652
+ 'ismap',
653
+ 'list',
654
+ 'max',
655
+ 'maxlength',
656
+ 'min',
657
+ 'multiple',
658
+ ...(this._allowNamedProperties ? ['name'] : []),
659
+ 'placeholder',
660
+ 'readonly',
661
+ 'required',
662
+ 'size',
663
+ 'src',
664
+ 'step',
665
+ 'tabindex',
666
+ 'type',
667
+ 'usemap',
668
+ 'value'
669
+ ],
670
+ ins: ['cite', 'datetime'],
671
+ label: ['accesskey', 'for'],
672
+ legend: ['accesskey', 'align'],
673
+ li: ['type', 'value'],
674
+ map: this._allowNamedProperties ? ['name'] : [],
675
+ menu: ['compact', 'label', 'type'],
676
+ meter: ['high', 'low', 'max', 'min', 'value'],
677
+ ol: ['compact', 'reversed', 'start', 'type'],
678
+ optgroup: ['disabled', 'label'],
679
+ option: ['disabled', 'label', 'selected', 'value'],
680
+ output: ['for', ...(this._allowNamedProperties ? ['name'] : [])],
681
+ p: ['align'],
682
+ pre: ['width'],
683
+ progress: ['max', 'min', 'value'],
684
+ q: ['cite'],
685
+ select: [
686
+ 'autocomplete',
687
+ 'disabled',
688
+ 'multiple',
689
+ ...(this._allowNamedProperties ? ['name'] : []),
690
+ 'required',
691
+ 'size',
692
+ 'tabindex'
693
+ ],
694
+ source: ['type'],
695
+ table: [
696
+ 'align',
697
+ 'bgcolor',
698
+ 'border',
699
+ 'cellpadding',
700
+ 'cellspacing',
701
+ 'frame',
702
+ 'rules',
703
+ 'summary',
704
+ 'width'
705
+ ],
706
+ tbody: ['align', 'char', 'charoff', 'valign'],
707
+ td: [
708
+ 'abbr',
709
+ 'align',
710
+ 'axis',
711
+ 'bgcolor',
712
+ 'char',
713
+ 'charoff',
714
+ 'colspan',
715
+ 'headers',
716
+ 'height',
717
+ 'nowrap',
718
+ 'rowspan',
719
+ 'scope',
720
+ 'valign',
721
+ 'width'
722
+ ],
723
+ textarea: [
724
+ 'accesskey',
725
+ 'autocomplete',
726
+ 'cols',
727
+ 'disabled',
728
+ 'inputmode',
729
+ ...(this._allowNamedProperties ? ['name'] : []),
730
+ 'placeholder',
731
+ 'readonly',
732
+ 'required',
733
+ 'rows',
734
+ 'tabindex',
735
+ 'wrap'
736
+ ],
737
+ tfoot: ['align', 'char', 'charoff', 'valign'],
738
+ th: [
739
+ 'abbr',
740
+ 'align',
741
+ 'axis',
742
+ 'bgcolor',
743
+ 'char',
744
+ 'charoff',
745
+ 'colspan',
746
+ 'headers',
747
+ 'height',
748
+ 'nowrap',
749
+ 'rowspan',
750
+ 'scope',
751
+ 'valign',
752
+ 'width'
753
+ ],
754
+ thead: ['align', 'char', 'charoff', 'valign'],
755
+ tr: ['align', 'bgcolor', 'char', 'charoff', 'valign'],
756
+ track: ['default', 'kind', 'label', 'srclang'],
757
+ ul: ['compact', 'type'],
758
+ video: [
759
+ 'autoplay',
760
+ 'controls',
761
+ 'height',
762
+ 'loop',
763
+ 'mediagroup',
764
+ 'muted',
765
+ 'poster',
766
+ 'preload',
767
+ 'src',
768
+ 'width'
769
+ ]
770
+ },
771
+ // Inline CSS styles that HTML tags may have (and their allowed values)
772
+ allowedStyles: {
773
+ // To simplify the data, all styles are allowed on all tags that allow the style attribute
774
+ '*': {
775
+ 'backface-visibility': [CssProp.BACKFACE_VISIBILITY],
776
+ background: [CssProp.BACKGROUND],
777
+ 'background-attachment': [CssProp.BACKGROUND_ATTACHMENT],
778
+ 'background-clip': [CssProp.BACKGROUND_CLIP],
779
+ 'background-color': [CssProp.BACKGROUND_COLOR],
780
+ 'background-image': [CssProp.BACKGROUND_IMAGE],
781
+ 'background-origin': [CssProp.BACKGROUND_ORIGIN],
782
+ 'background-position': [CssProp.BACKGROUND_POSITION],
783
+ 'background-repeat': [CssProp.BACKGROUND_REPEAT],
784
+ 'background-size': [CssProp.BACKGROUND_SIZE],
785
+ border: [CssProp.BORDER],
786
+ 'border-bottom': [CssProp.BORDER_BOTTOM],
787
+ 'border-bottom-color': [CssProp.BORDER_BOTTOM_COLOR],
788
+ 'border-bottom-left-radius': [CssProp.BORDER_BOTTOM_LEFT_RADIUS],
789
+ 'border-bottom-right-radius': [CssProp.BORDER_BOTTOM_RIGHT_RADIUS],
790
+ 'border-bottom-style': [CssProp.BORDER_BOTTOM_STYLE],
791
+ 'border-bottom-width': [CssProp.BORDER_BOTTOM_WIDTH],
792
+ 'border-collapse': [CssProp.BORDER_COLLAPSE],
793
+ 'border-color': [CssProp.BORDER_COLOR],
794
+ 'border-left': [CssProp.BORDER_LEFT],
795
+ 'border-left-color': [CssProp.BORDER_LEFT_COLOR],
796
+ 'border-left-style': [CssProp.BORDER_LEFT_STYLE],
797
+ 'border-left-width': [CssProp.BORDER_LEFT_WIDTH],
798
+ 'border-radius': [CssProp.BORDER_RADIUS],
799
+ 'border-right': [CssProp.BORDER_RIGHT],
800
+ 'border-right-color': [CssProp.BORDER_RIGHT_COLOR],
801
+ 'border-right-style': [CssProp.BORDER_RIGHT_STYLE],
802
+ 'border-right-width': [CssProp.BORDER_RIGHT_WIDTH],
803
+ 'border-spacing': [CssProp.BORDER_SPACING],
804
+ 'border-style': [CssProp.BORDER_STYLE],
805
+ 'border-top': [CssProp.BORDER_TOP],
806
+ 'border-top-color': [CssProp.BORDER_TOP_COLOR],
807
+ 'border-top-left-radius': [CssProp.BORDER_TOP_LEFT_RADIUS],
808
+ 'border-top-right-radius': [CssProp.BORDER_TOP_RIGHT_RADIUS],
809
+ 'border-top-style': [CssProp.BORDER_TOP_STYLE],
810
+ 'border-top-width': [CssProp.BORDER_TOP_WIDTH],
811
+ 'border-width': [CssProp.BORDER_WIDTH],
812
+ bottom: [CssProp.BOTTOM],
813
+ box: [CssProp.BOX],
814
+ 'box-shadow': [CssProp.BOX_SHADOW],
815
+ 'box-sizing': [CssProp.BOX_SIZING],
816
+ 'caption-side': [CssProp.CAPTION_SIDE],
817
+ clear: [CssProp.CLEAR],
818
+ clip: [CssProp.CLIP],
819
+ color: [CssProp.COLOR],
820
+ cursor: [CssProp.CURSOR],
821
+ direction: [CssProp.DIRECTION],
822
+ display: [CssProp.DISPLAY],
823
+ 'display-inside': [CssProp.DISPLAY_INSIDE],
824
+ 'display-outside': [CssProp.DISPLAY_OUTSIDE],
825
+ elevation: [CssProp.ELEVATION],
826
+ 'empty-cells': [CssProp.EMPTY_CELLS],
827
+ float: [CssProp.FLOAT],
828
+ font: [CssProp.FONT],
829
+ 'font-family': [CssProp.FONT_FAMILY],
830
+ 'font-size': [CssProp.FONT_SIZE],
831
+ 'font-stretch': [CssProp.FONT_STRETCH],
832
+ 'font-style': [CssProp.FONT_STYLE],
833
+ 'font-variant': [CssProp.FONT_VARIANT],
834
+ 'font-weight': [CssProp.FONT_WEIGHT],
835
+ height: [CssProp.HEIGHT],
836
+ left: [CssProp.LEFT],
837
+ 'letter-spacing': [CssProp.LETTER_SPACING],
838
+ 'line-height': [CssProp.LINE_HEIGHT],
839
+ 'list-style': [CssProp.LIST_STYLE],
840
+ 'list-style-image': [CssProp.LIST_STYLE_IMAGE],
841
+ 'list-style-position': [CssProp.LIST_STYLE_POSITION],
842
+ 'list-style-type': [CssProp.LIST_STYLE_TYPE],
843
+ margin: [CssProp.MARGIN],
844
+ 'margin-bottom': [CssProp.MARGIN_BOTTOM],
845
+ 'margin-left': [CssProp.MARGIN_LEFT],
846
+ 'margin-right': [CssProp.MARGIN_RIGHT],
847
+ 'margin-top': [CssProp.MARGIN_TOP],
848
+ 'max-height': [CssProp.MAX_HEIGHT],
849
+ 'max-width': [CssProp.MAX_WIDTH],
850
+ 'min-height': [CssProp.MIN_HEIGHT],
851
+ 'min-width': [CssProp.MIN_WIDTH],
852
+ opacity: [CssProp.OPACITY],
853
+ outline: [CssProp.OUTLINE],
854
+ 'outline-color': [CssProp.OUTLINE_COLOR],
855
+ 'outline-style': [CssProp.OUTLINE_STYLE],
856
+ 'outline-width': [CssProp.OUTLINE_WIDTH],
857
+ overflow: [CssProp.OVERFLOW],
858
+ 'overflow-wrap': [CssProp.OVERFLOW_WRAP],
859
+ 'overflow-x': [CssProp.OVERFLOW_X],
860
+ 'overflow-y': [CssProp.OVERFLOW_Y],
861
+ padding: [CssProp.PADDING],
862
+ 'padding-bottom': [CssProp.PADDING_BOTTOM],
863
+ 'padding-left': [CssProp.PADDING_LEFT],
864
+ 'padding-right': [CssProp.PADDING_RIGHT],
865
+ 'padding-top': [CssProp.PADDING_TOP],
866
+ 'page-break-after': [CssProp.PAGE_BREAK_AFTER],
867
+ 'page-break-before': [CssProp.PAGE_BREAK_BEFORE],
868
+ 'page-break-inside': [CssProp.PAGE_BREAK_INSIDE],
869
+ 'pause-after': [CssProp.PAUSE_AFTER],
870
+ perspective: [CssProp.PERSPECTIVE],
871
+ pitch: [CssProp.PITCH],
872
+ 'pitch-range': [CssProp.PITCH_RANGE],
873
+ position: [CssProp.POSITION],
874
+ quotes: [CssProp.QUOTES],
875
+ resize: [CssProp.RESIZE],
876
+ richness: [CssProp.RICHNESS],
877
+ right: [CssProp.RIGHT],
878
+ speak: [CssProp.SPEAK],
879
+ 'speak-header': [CssProp.SPEAK_HEADER],
880
+ 'speak-numeral': [CssProp.SPEAK_NUMERAL],
881
+ 'speak-punctuation': [CssProp.SPEAK_PUNCTUATION],
882
+ 'speech-rate': [CssProp.SPEECH_RATE],
883
+ stress: [CssProp.STRESS],
884
+ 'table-layout': [CssProp.TABLE_LAYOUT],
885
+ 'text-align': [CssProp.TEXT_ALIGN],
886
+ 'text-decoration': [CssProp.TEXT_DECORATION],
887
+ 'text-indent': [CssProp.TEXT_INDENT],
888
+ 'text-overflow': [CssProp.TEXT_OVERFLOW],
889
+ 'text-shadow': [CssProp.TEXT_SHADOW],
890
+ 'text-transform': [CssProp.TEXT_TRANSFORM],
891
+ 'text-wrap': [CssProp.TEXT_WRAP],
892
+ top: [CssProp.TOP],
893
+ 'unicode-bidi': [CssProp.UNICODE_BIDI],
894
+ 'vertical-align': [CssProp.VERTICAL_ALIGN],
895
+ visibility: [CssProp.VISIBILITY],
896
+ volume: [CssProp.VOLUME],
897
+ 'white-space': [CssProp.WHITE_SPACE],
898
+ width: [CssProp.WIDTH],
899
+ 'word-break': [CssProp.WORD_BREAK],
900
+ 'word-spacing': [CssProp.WORD_SPACING],
901
+ 'word-wrap': [CssProp.WORD_WRAP],
902
+ 'z-index': [CssProp.Z_INDEX],
903
+ zoom: [CssProp.ZOOM]
904
+ }
905
+ },
906
+ transformTags: {
907
+ // Set the "rel" attribute for <a> tags to "nofollow".
908
+ a: sanitize.simpleTransform('a', { rel: 'nofollow' }),
909
+ // Set the "disabled" attribute for <input> tags.
910
+ input: sanitize.simpleTransform('input', { disabled: 'disabled' })
911
+ },
912
+ allowedSchemes: schemesToAllow,
913
+ allowedSchemesByTag: {
914
+ // Allow 'attachment:' img src (used for markdown cell attachments).
915
+ img: [...schemesToAllow, 'attachment']
916
+ },
917
+ // Override of the default option, so we can skip 'src' attribute validation.
918
+ // 'src' Attributes are validated to be URIs, which does not allow for embedded (image) data.
919
+ // Since embedded data is no longer deemed to be a threat, validation can be skipped.
920
+ // See https://github.com/jupyterlab/jupyterlab/issues/5183
921
+ allowedSchemesAppliedToAttributes: ['href', 'cite']
922
+ };
923
+ };
919
924
  this._options = this._generateOptions();
920
925
  }
921
926
  /**
@@ -939,11 +944,14 @@ export class Sanitizer {
939
944
  /**
940
945
  * Set the allowed schemes
941
946
  *
942
- * @param scheme Allowed schemes
947
+ * @param scheme Allowed schemes.
948
+ * Automatically regenerates sanitizer options to apply the change.
949
+ * Note: the schemes merge into the current config and does not get overwritten.
943
950
  */
944
951
  setAllowedSchemes(scheme) {
945
952
  // Force copy of `scheme`
946
- this._options.allowedSchemes = [...scheme];
953
+ this._customAllowedSchemes = [...scheme];
954
+ this._options = this._generateOptions();
947
955
  }
948
956
  /**
949
957
  * Set the URL replacement boolean.