From c043156fbf2d7eff5bed3daa0e92a011a983ed49 Mon Sep 17 00:00:00 2001 From: Adam Gessaman Date: Wed, 3 Jun 2026 14:23:22 -0700 Subject: [PATCH] fix(web_viewer): sanitize contact and node names in HTML templates - Updated `contacts.html` to escape HTML for contact usernames and advertisement data, preventing potential XSS vulnerabilities. - Modified `mesh.html` to escape node names and prefixes in tooltips, ensuring safe rendering in the vis-network. - Removed unnecessary parameters from the `showDeleteConfirmation` method to derive the username directly from the contact data. --- modules/web_viewer/templates/contacts.html | 24 +- modules/web_viewer/templates/mesh.html | 6 +- tests/test_contacts_template_xss.py | 293 +++++++++++++++++++++ 3 files changed, 309 insertions(+), 14 deletions(-) create mode 100644 tests/test_contacts_template_xss.py diff --git a/modules/web_viewer/templates/contacts.html b/modules/web_viewer/templates/contacts.html index 87a71a5..53f382b 100644 --- a/modules/web_viewer/templates/contacts.html +++ b/modules/web_viewer/templates/contacts.html @@ -866,7 +866,6 @@ class ModernContactsManager { renderContactCardHtml(contact) { const uidEsc = this.escapeHtml(contact.user_id); const uidJs = contact.user_id.replace(/'/g, "\\'"); - const nameJs = (contact.username || 'Unknown').replace(/'/g, "\\'"); const checked = this.selectedContactIds.has(contact.user_id) ? 'checked' : ''; const hasGeo = !!(contact.latitude && contact.longitude && contact.latitude !== 0 && contact.longitude !== 0); const starLabel = contact.is_starred ? 'Unstar contact' : 'Star contact'; @@ -880,7 +879,7 @@ class ModernContactsManager {
-
${contact.username || 'Unknown'}
+
${this.escapeHtml(contact.username || 'Unknown')}
${contact.user_id ? contact.user_id.substring(0, 16) + '...' : 'Unknown'}
${this.formatDeviceType(contact)}
@@ -910,7 +909,7 @@ class ModernContactsManager {
  • ${geoMenuItem}
  • -
  • +
  • @@ -949,7 +948,7 @@ class ModernContactsManager { - ${contact.username || 'Unknown'} + ${this.escapeHtml(contact.username || 'Unknown')}
    ${contact.user_id ? contact.user_id.substring(0, 16) + '...' : 'Unknown'} @@ -975,7 +974,7 @@ class ModernContactsManager { ` : '' } - @@ -1958,11 +1957,11 @@ class ModernContactsManager {