Skip to content

Commit 88e24ba

Browse files
authored
Merge commit from fork
1 parent 58d7535 commit 88e24ba

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

packages/apputils-extension/schema/sanitizer.json

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"title": "Autolink URL replacement",
2020
"description": "Whether to replace URLs with links or not.",
2121
"default": true
22+
},
23+
"allowNamedProperties": {
24+
"type": "boolean",
25+
"title": "Allow named properties",
26+
"description": "Whether to allow untrusted elements to include `name` and `id` attributes. These attributes are stripped by default to prevent DOM clobbering attacks.",
27+
"default": false
2228
}
2329
},
2430
"type": "object"

packages/apputils-extension/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,15 @@ const sanitizer: JupyterFrontEndPlugin<IRenderMime.ISanitizer> = {
693693
.composite as Array<string>;
694694

695695
const autolink = setting.get('autolink').composite as boolean;
696+
const allowNamedProperties = setting.get('allowNamedProperties')
697+
.composite as boolean;
696698

697699
if (allowedSchemes) {
698700
sanitizer.setAllowedSchemes(allowedSchemes);
699701
}
700702

701703
sanitizer.setAutolink(autolink);
704+
sanitizer.setAllowNamedProperties(allowNamedProperties);
702705
};
703706

704707
// Wait for the application to be restored and

packages/apputils/src/sanitizer.ts

+25-13
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ class CssProp {
434434
* A class to sanitize HTML strings.
435435
*/
436436
export class Sanitizer implements IRenderMime.ISanitizer {
437+
constructor() {
438+
this._options = this._generateOptions();
439+
}
437440
/**
438441
* Sanitize an HTML string.
439442
*
@@ -473,9 +476,18 @@ export class Sanitizer implements IRenderMime.ISanitizer {
473476
this._autolink = autolink;
474477
}
475478

476-
private _autolink: boolean = true;
479+
/**
480+
* Set the whether to allow `name` and `id` attributes.
481+
*/
482+
setAllowNamedProperties(allowNamedProperties: boolean): void {
483+
this._allowNamedProperties = allowNamedProperties;
484+
this._options = this._generateOptions();
485+
}
477486

478-
private _options: sanitize.IOptions = {
487+
private _autolink: boolean = true;
488+
private _allowNamedProperties: boolean = false;
489+
private _options: sanitize.IOptions;
490+
private _generateOptions = (): sanitize.IOptions => ({
479491
// HTML tags that are allowed to be used. Tags were extracted from Google Caja
480492
allowedTags: [
481493
'a',
@@ -590,7 +602,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
590602
'dir',
591603
'draggable',
592604
'hidden',
593-
'id',
605+
...(this._allowNamedProperties ? ['id'] : []),
594606
'inert',
595607
'itemprop',
596608
'itemref',
@@ -607,7 +619,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
607619
'coords',
608620
'href',
609621
'hreflang',
610-
'name',
622+
...(this._allowNamedProperties ? ['name'] : []),
611623
'rel',
612624
'shape',
613625
'tabindex',
@@ -641,7 +653,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
641653
'data-commandlinker-args',
642654
'data-commandlinker-command',
643655
'disabled',
644-
'name',
656+
...(this._allowNamedProperties ? ['name'] : []),
645657
'tabindex',
646658
'type',
647659
'value'
@@ -672,7 +684,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
672684
'autocomplete',
673685
'enctype',
674686
'method',
675-
'name',
687+
...(this._allowNamedProperties ? ['name'] : []),
676688
'novalidate'
677689
],
678690
h1: ['align'],
@@ -697,7 +709,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
697709
'height',
698710
'hspace',
699711
'ismap',
700-
'name',
712+
...(this._allowNamedProperties ? ['name'] : []),
701713
'src',
702714
'usemap',
703715
'vspace',
@@ -718,7 +730,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
718730
'maxlength',
719731
'min',
720732
'multiple',
721-
'name',
733+
...(this._allowNamedProperties ? ['name'] : []),
722734
'placeholder',
723735
'readonly',
724736
'required',
@@ -734,13 +746,13 @@ export class Sanitizer implements IRenderMime.ISanitizer {
734746
label: ['accesskey', 'for'],
735747
legend: ['accesskey', 'align'],
736748
li: ['type', 'value'],
737-
map: ['name'],
749+
map: this._allowNamedProperties ? ['name'] : [],
738750
menu: ['compact', 'label', 'type'],
739751
meter: ['high', 'low', 'max', 'min', 'value'],
740752
ol: ['compact', 'reversed', 'start', 'type'],
741753
optgroup: ['disabled', 'label'],
742754
option: ['disabled', 'label', 'selected', 'value'],
743-
output: ['for', 'name'],
755+
output: ['for', ...(this._allowNamedProperties ? ['name'] : [])],
744756
p: ['align'],
745757
pre: ['width'],
746758
progress: ['max', 'min', 'value'],
@@ -749,7 +761,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
749761
'autocomplete',
750762
'disabled',
751763
'multiple',
752-
'name',
764+
...(this._allowNamedProperties ? ['name'] : []),
753765
'required',
754766
'size',
755767
'tabindex'
@@ -789,7 +801,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
789801
'cols',
790802
'disabled',
791803
'inputmode',
792-
'name',
804+
...(this._allowNamedProperties ? ['name'] : []),
793805
'placeholder',
794806
'readonly',
795807
'required',
@@ -982,5 +994,5 @@ export class Sanitizer implements IRenderMime.ISanitizer {
982994
// Since embedded data is no longer deemed to be a threat, validation can be skipped.
983995
// See https://github.com/jupyterlab/jupyterlab/issues/5183
984996
allowedSchemesAppliedToAttributes: ['href', 'cite']
985-
};
997+
});
986998
}

0 commit comments

Comments
 (0)