Skip to content

Commit be4492b

Browse files
authored
fix(dropdown): possible XSS through select option text
This PR fixes a possible XSS through an entity encoded select option text when converted into a FUI dropdown. Even if preserveHTML: false would prevent this, a select tag cannot contain html at all and if it contains entity encoded HTML instead, it should not be reconverted into html. The PR also fixes recreating the dropdown menu twice when no values are selected in a multiple dropdown Thanks to @brian-codes for reporting
1 parent 17aa72d commit be4492b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/definitions/modules/dropdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@
20762076
values.push({
20772077
name: name,
20782078
value: value,
2079-
text: text,
2079+
text: module.escape.htmlEntities(text, true),
20802080
disabled: disabled,
20812081
});
20822082
}
@@ -3459,7 +3459,7 @@
34593459
selectChanged = false
34603460
;
34613461
$.each(mutations, function (index, mutation) {
3462-
if ($(mutation.target).is('select, option, optgroup') || $(mutation.addedNodes).is('select')) {
3462+
if ($(mutation.target).is('option, optgroup') || $(mutation.addedNodes).is('select') || ($(mutation.target).is('select') && mutation.type !== 'attributes')) {
34633463
selectChanged = true;
34643464

34653465
return false;
@@ -3768,7 +3768,7 @@
37683768

37693769
return text.replace(regExp.escape, '\\$&');
37703770
},
3771-
htmlEntities: function (string) {
3771+
htmlEntities: function (string, forceAmpersand) {
37723772
var
37733773
badChars = /["'<>`]/g,
37743774
shouldEscape = /["&'<>`]/,
@@ -3784,7 +3784,7 @@
37843784
}
37853785
;
37863786
if (shouldEscape.test(string)) {
3787-
string = string.replace(/&(?![\d#a-z]{1,12};)/gi, '&amp;');
3787+
string = string.replace(forceAmpersand ? /&/g : /&(?![\d#a-z]{1,12};)/gi, '&amp;');
37883788

37893789
return string.replace(badChars, escapedChar);
37903790
}

0 commit comments

Comments
 (0)