Skip to content

Commit febfb0b

Browse files
bug-2032278: escape user-provided field values for /signature graphs tab (#7188)
1 parent 4610e64 commit febfb0b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

webapp/crashstats/signature/static/signature/js/signature_tab_graphs.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,20 @@ SignatureReport.GraphsTab.prototype.formatData = function (data) {
103103
});
104104
});
105105

106+
// By reading back innerHTML, the browser serializes the text node
107+
// into safe HTML thus escaping special characters.
108+
function escapeHTML(str) {
109+
let tmpDiv = document.createElement('div');
110+
tmpDiv.textContent = str;
111+
return tmpDiv.innerHTML;
112+
}
113+
106114
// Make the data object into an array of arrays for Metrics Graphics
107115
// and add the associated legend in the same order.
108-
$.each(lineDataObject, function (key, lineData) {
116+
// The keys of lineDataObject are crash report field values
117+
$.each(lineDataObject, function (fieldValue, lineData) {
109118
lineDataArray.push(lineData);
110-
legend.push(key);
119+
legend.push(escapeHTML(fieldValue));
111120
});
112121

113122
// Return the line data, the legend and also any remaining terms after the
@@ -150,7 +159,7 @@ SignatureReport.GraphsTab.prototype.drawGraph = function (graphData, contentElem
150159
legend_target: '.new-legend',
151160
show_secondary_x_label: false,
152161
mouseover: function (d) {
153-
$('.mg-active-datapoint', contentElement).html(d.term + ': ' + d.count + (d.count === 1 ? ' crash' : ' crashes'));
162+
$('.mg-active-datapoint', contentElement).text(d.term + ': ' + d.count + (d.count === 1 ? ' crash' : ' crashes'));
154163
},
155164
});
156165

0 commit comments

Comments
 (0)