Skip to content

Commit d393c1d

Browse files
committed
[FIX] Sanitize remaining customer-view columns and preserve raw sort/filter values
- 'owner' (case owner username) and 'asset_type' were left unsanitized by the previous sanitation pass in this same table config. - sanitizeHTML was being applied unconditionally for every DataTables render call (display/sort/filter/type), causing the search box and sort order to operate on the HTML-encoded value instead of the raw one. Sanitize only for the 'display' type via a shared helper. - Guard asset_type/owner renderers against a null value (asset_type_id and case owner are both nullable).
1 parent 1c93926 commit d393c1d

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

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 === null) {
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)