Skip to content

Commit db11eb7

Browse files
Potential fix for code scanning alert no. 39: Incomplete multi-character sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1a150a4 commit db11eb7

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

assets/src/js/base/supersearch.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ $(document).ready(function () {
3232
sidebarSearchWidget.attr('data-widget-disabled', 'true');
3333
}
3434

35+
/**
36+
* Escape a string for safe use inside HTML attribute values.
37+
* Converts characters that could break out of the attribute context
38+
* or be interpreted as HTML markup.
39+
*
40+
* @param {string} value
41+
* @returns {string}
42+
*/
43+
function escapeHtmlAttribute(value) {
44+
if (value == null) {
45+
return '';
46+
}
47+
return String(value)
48+
.replace(/&/g, '&amp;')
49+
.replace(/</g, '&lt;')
50+
.replace(/>/g, '&gt;')
51+
.replace(/"/g, '&quot;')
52+
.replace(/'/g, '&#39;');
53+
}
54+
3555
// Disabilita anche eventuali event listener di AdminLTE già attaccati
3656
searchInput.off('.adminlte.sidebar-search');
3757
searchInput.parent().off('.adminlte.sidebar-search');
@@ -279,7 +299,7 @@ $(document).ready(function () {
279299
// Sostituisci la classe highlight con search-highlight per coerenza
280300
processedLabels = processedLabels.replace(/class=['"]highlight['"]/g, 'class="search-highlight"');
281301

282-
const cleanLabels = labels.replace(/<[^>]*>/g, ''); // Rimuovi HTML per il tooltip
302+
const cleanLabels = escapeHtmlAttribute(labels.replace(/<[^>]*>/g, '')); // Rimuovi HTML per il tooltip ed effettua l'escape per l'attributo
283303

284304
// Evidenzia il termine di ricerca nel titolo
285305
const highlightedTitle = highlightSearchTerm(title, searchTerm);

0 commit comments

Comments
 (0)