Skip to content

Commit 7c343a9

Browse files
authored
Merge pull request #13 from baseVISION/fix/customer-view-alert-sanitization
Sanitize remaining XSS gaps in customer view and alert modal/popover
2 parents 1c93926 + 831740d commit 7c343a9

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

ui/src/pages/alerts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ async function showAlertHistory(alertId) {
12941294
let date = new Date(Math.floor(entry) * 1000);
12951295
let dateStr = date.toLocaleString();
12961296
let entryStr = alertData.modification_history[entry];
1297-
entryDiv.append('<div class="row"><div class="col-3">' + dateStr + '</div><div class="col-3">' + entryStr.user + '</div><div class="col-6">'+ entryStr.action +'</div></div>');
1297+
entryDiv.append('<div class="row"><div class="col-3">' + dateStr + '</div><div class="col-3">' + sanitizeHTML(entryStr.user) + '</div><div class="col-6">'+ sanitizeHTML(entryStr.action) +'</div></div>');
12981298

12991299
}
13001300

ui/src/pages/case.asset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ $(document).ready(function(){
401401
let alerts_content = "";
402402

403403
row.alerts.forEach(alert => {
404-
alerts_content += `<i tabindex="0" class="fas fa-bell text-warning mr-2"></i><a href=\"/alerts?alert_ids=${alert.alert_id}&page=1&per_page=1&sort=desc\" target="_blank" rel="noopener">#${alert.alert_id} - ${alert.alert_title.replace(/'/g, "&#39;").replace(/"/g, "&quot;")}</a><br/>`;
404+
alerts_content += `<i tabindex="0" class="fas fa-bell text-warning mr-2"></i><a href=\"/alerts?alert_ids=${alert.alert_id}&page=1&per_page=1&sort=desc\" target="_blank" rel="noopener">#${alert.alert_id} - ${sanitizeHTML(alert.alert_title).replace(/'/g, "&#39;").replace(/"/g, "&quot;")}</a><br/>`;
405405
} );
406406
alerts_content += `<i tabindex="0" class="fas fa-external-link-square mr-2"></i><a href=\"/alerts?alert_assets=${data}" target="_blank" rel="noopener">More..</a>`;
407407

ui/src/pages/view.customers.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ function refresh_client_users(customer_id) {
113113
})
114114
}
115115

116+
// Sanitize only for the 'display' render type — DataTables also calls
117+
// render() with 'sort'/'filter'/'type' to build its internal index, and
118+
// those should compare against the raw value rather than the
119+
// HTML-encoded one, or search/sort silently stops matching values that
120+
// contain HTML-significant characters.
121+
function safeTextRender(data, type) {
122+
return type === 'display' ? sanitizeHTML(data) : data;
123+
}
124+
116125
$(document).ready(function() {
117126

118127
let customer_id = $('#customer_id').val();
@@ -134,16 +143,12 @@ $(document).ready(function() {
134143
},
135144
{
136145
"data": "user_name",
137-
"render": function(data, type, row) {
138-
return sanitizeHTML(data);
139-
}
146+
"render": safeTextRender
140147

141148
},
142149
{
143150
"data": "user_login",
144-
"render": function(data, type, row) {
145-
return sanitizeHTML(data);
146-
}
151+
"render": safeTextRender
147152
},
148153
{
149154
"data": "is_service_account",
@@ -160,28 +165,24 @@ $(document).ready(function() {
160165
"columns": [
161166
{
162167
"data": "asset_name",
163-
"render": function(data, type, row) {
164-
return sanitizeHTML(data);
165-
}
168+
"render": safeTextRender
166169
},
167170
{
168171
"data": "asset_description",
169-
"render": function(data, type, row) {
170-
return sanitizeHTML(data);
171-
}
172-
172+
"render": safeTextRender
173173
},
174174
{
175175
"data": "asset_type",
176176
"render": function(data, type, row) {
177-
return sanitizeHTML(data.asset_name);
177+
if (!data) {
178+
return '';
179+
}
180+
return type === 'display' ? sanitizeHTML(data.asset_name) : data.asset_name;
178181
}
179182
},
180183
{
181184
"data": "asset_ip",
182-
"render": function(data, type, row) {
183-
return sanitizeHTML(data);
184-
}
185+
"render": safeTextRender
185186
},
186187
{
187188
"data": "case_id",
@@ -241,7 +242,7 @@ $(document).ready(function() {
241242
a_anchor.text(data);
242243
return a_anchor.prop('outerHTML');
243244
}
244-
return sanitizeHTML(data);
245+
return data;
245246
}
246247
},
247248
{
@@ -253,17 +254,19 @@ $(document).ready(function() {
253254
{
254255
"data": "state",
255256
"render": function(data, type, row) {
256-
if (data !== null) {
257-
return data.state_name;
258-
} else {
257+
if (!data) {
259258
return 'Unknown';
260259
}
260+
return type === 'display' ? sanitizeHTML(data.state_name) : data.state_name;
261261
}
262262
},
263263
{
264264
"data": "owner",
265265
"render": function(data, type, row) {
266-
return data.user_name;
266+
if (!data) {
267+
return '';
268+
}
269+
return type === 'display' ? sanitizeHTML(data.user_name) : data.user_name;
267270
}
268271
}
269272
],

0 commit comments

Comments
 (0)