Skip to content

Commit af4626a

Browse files
Immediate fix to htmlEncode user added text (#5575)
There are likely problems remaining with the way that initCommentForm is creating its elements. I suspect that a malformed avatar url could be used maliciously.
1 parent 21c70e1 commit af4626a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

public/js/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
function htmlEncode(text) {
4+
return jQuery('<div />').text(text).html()
5+
}
6+
37
var csrf;
48
var suburl;
59

@@ -312,12 +316,12 @@ function initCommentForm() {
312316
switch (input_id) {
313317
case '#milestone_id':
314318
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
315-
$(this).text() + '</a>');
319+
htmlEncode($(this).text()) + '</a>');
316320
break;
317321
case '#assignee_id':
318322
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
319323
'<img class="ui avatar image" src=' + $(this).data('avatar') + '>' +
320-
$(this).text() + '</a>');
324+
htmlEncode($(this).text()) + '</a>');
321325
}
322326
$('.ui' + select_id + '.list .no-select').addClass('hide');
323327
$(input_id).val($(this).data('id'));
@@ -1456,7 +1460,7 @@ function searchUsers() {
14561460
$.each(response.data, function (i, item) {
14571461
var title = item.login;
14581462
if (item.full_name && item.full_name.length > 0) {
1459-
title += ' (' + item.full_name + ')';
1463+
title += ' (' + htmlEncode(item.full_name) + ')';
14601464
}
14611465
items.push({
14621466
title: title,
@@ -2510,7 +2514,7 @@ function initTopicbar() {
25102514
if (res.topics) {
25112515
formattedResponse.success = true;
25122516
for (var i=0;i < res.topics.length;i++) {
2513-
formattedResponse.results.push({"description": res.topics[i].Name, "data-value":res.topics[i].Name})
2517+
formattedResponse.results.push({"description": res.topics[i].Name, "data-value": res.topics[i].Name})
25142518
}
25152519
}
25162520

@@ -2631,7 +2635,7 @@ function initIssueList() {
26312635
// Parse the response from the api to work with our dropdown
26322636
$.each(response, function(index, issue) {
26332637
filteredResponse.results.push({
2634-
'name' : '#' + issue.number + '&nbsp;' + issue.title,
2638+
'name' : '#' + issue.number + '&nbsp;' + htmlEncode(issue.title),
26352639
'value' : issue.id
26362640
});
26372641
});

0 commit comments

Comments
 (0)