From 7524819c770938d6adef88fd1704f9c06e40e7b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 11:45:29 +0000 Subject: [PATCH] fix(security): replace innerHTML with DOM API to prevent XSS in common.js - Replace innerHTML assignments with createElement/textContent to prevent XSS - Properly escape user data (display name, picture URL) from OAuth responses - Remove stale 'files copy.html' template file Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- frontend/static/js/common.js | 108 ++++++++++++----- frontend/templates/files copy.html | 185 ----------------------------- 2 files changed, 79 insertions(+), 214 deletions(-) delete mode 100644 frontend/templates/files copy.html diff --git a/frontend/static/js/common.js b/frontend/static/js/common.js index 42524d30..2244ee8e 100644 --- a/frontend/static/js/common.js +++ b/frontend/static/js/common.js @@ -16,56 +16,106 @@ // Get the display name (prefer name, fall back to preferred_username, then email) const displayName = data.name || data.preferred_username || data.email; - // User is logged in - let authHTML = ` -
- `; - + // User is logged in - use DOM API to prevent XSS if (authSection) { - authSection.innerHTML = authHTML; + authSection.textContent = ''; // Clear existing content + const container = document.createElement('div'); + container.className = 'flex items-center'; + + const img = document.createElement('img'); + img.src = data.picture; + img.alt = 'Avatar'; + img.className = 'w-8 h-8 rounded-full mr-2'; + + const span = document.createElement('span'); + span.textContent = displayName; + + const logoutLink = document.createElement('a'); + logoutLink.href = '/logout'; + logoutLink.className = 'ml-3 text-red-600 hover:text-red-800'; + const icon = document.createElement('i'); + icon.className = 'fas fa-sign-out-alt'; + logoutLink.appendChild(icon); + + container.appendChild(img); + container.appendChild(span); + container.appendChild(logoutLink); + authSection.appendChild(container); } if (mobileAuthSection) { - mobileAuthSection.innerHTML = ` -