-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2997 from harvesthq/fix-group-label-xss-vulnerabi…
…lity Escape the `group_label` when rendering it
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe "Bugfixes", -> | ||
it "https://github.com/harvesthq/chosen/issues/2996 - XSS Vulnerability with `include_group_label_in_selected: true`", -> | ||
tmpl = " | ||
<select> | ||
<option value=''></option> | ||
<optgroup label='</script><script>console.log(1)</script>'> | ||
<option>an xss option</option> | ||
</optgroup> | ||
</select> | ||
" | ||
|
||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
|
||
select.chosen | ||
include_group_label_in_selected: true | ||
|
||
# open the drop | ||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") | ||
|
||
xss_option = container.find(".active-result").last() | ||
expect(xss_option.html()).toBe "an xss option" | ||
|
||
# trigger the selection of the xss option | ||
xss_option.trigger("mouseup") | ||
|
||
# make sure the script tags are escaped correctly | ||
label_html = container.find("a.chosen-single").html() | ||
expect(label_html).toContain('</script><script>console.log(1)</script>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
describe "Bugfixes", -> | ||
it "https://github.com/harvesthq/chosen/issues/2996 - XSS Vulnerability with `include_group_label_in_selected: true`", -> | ||
tmpl = " | ||
<select> | ||
<option value=''></option> | ||
<optgroup id='xss' label='</script><script>console.log(1)</script>'> | ||
<option>an xss option</option> | ||
</optgroup> | ||
</select> | ||
" | ||
div = new Element("div") | ||
document.body.insert(div) | ||
div.innerHTML = tmpl | ||
|
||
select = div.down("select") | ||
new Chosen select, | ||
include_group_label_in_selected: true | ||
|
||
# open the drop | ||
container = div.down(".chosen-container") | ||
simulant.fire(container, "mousedown") # open the drop | ||
|
||
xss_option = container.select(".active-result").last() | ||
expect(xss_option.innerHTML).toBe "an xss option" | ||
|
||
# trigger the selection of the xss option | ||
simulant.fire(xss_option, "mouseup") | ||
|
||
# make sure the script tags are escaped correctly | ||
label_html = container.down("a.chosen-single").innerHTML | ||
expect(label_html).toContain('</script><script>console.log(1)</script>') | ||
|