Skip to content

Commit 328bf05

Browse files
committed
fix(material-experimental/mdc-slider): make small fixes needed to implement the gmat mdc slider internally
* change imports of @material/base to @material/base/types * explicitly check attributes when calling setAttribute to prevent xss
1 parent 5832463 commit 328bf05

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/material-experimental/mdc-slider/global-change-and-input-listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, NgZone, OnDestroy} from '@angular/core';
11-
import {SpecificEventListener} from '@material/base';
11+
import {SpecificEventListener} from '@material/base/types';
1212
import {fromEvent, Observable, Subject, Subscription} from 'rxjs';
1313
import {finalize, share, takeUntil} from 'rxjs/operators';
1414

src/material-experimental/mdc-slider/slider.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
RippleRef,
5252
RippleState,
5353
} from '@angular/material/core';
54-
import {SpecificEventListener, EventType} from '@material/base';
54+
import {SpecificEventListener, EventType} from '@material/base/types';
5555
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
5656
import {Subscription} from 'rxjs';
5757
import {GlobalChangeAndInputListener} from './global-change-and-input-listener';
@@ -977,7 +977,15 @@ class SliderAdapter implements MDCSliderAdapter {
977977
return this._delegate._getInputElement(thumbPosition).getAttribute(attribute);
978978
}
979979
setInputAttribute = (attribute: string, value: string, thumbPosition: Thumb): void => {
980-
this._delegate._getInputElement(thumbPosition).setAttribute(attribute, value);
980+
const input = this._delegate._getInputElement(thumbPosition);
981+
982+
// Explicitly check the attribute we are setting to prevent xss.
983+
if (attribute === 'aria-valuetext') { input.setAttribute('aria-valuetext', value); }
984+
else if (attribute === 'disabled') { input.setAttribute('disabled', value); }
985+
else if (attribute === 'min') { input.setAttribute('min', value); }
986+
else if (attribute === 'max') { input.setAttribute('max', value); }
987+
else if (attribute === 'value') { input.setAttribute('value', value); }
988+
else if (attribute === 'step') { input.setAttribute('step', value); }
981989
}
982990
removeInputAttribute = (attribute: string, thumbPosition: Thumb): void => {
983991
this._delegate._getInputElement(thumbPosition).removeAttribute(attribute);

0 commit comments

Comments
 (0)