Fix DOM-based XSS in upload.js by sanitizing file.name

This commit resolves a DOM-based Cross-Site Scripting (XSS) vulnerability in `frontend/static/js/upload.js`. Previously, the user-controlled `file.name` was directly interpolated into the DOM using `innerHTML` without any HTML entity escaping. A maliciously crafted filename could lead to script execution.

A local `_escapeHtml` function has been introduced to safely escape characters like `<`, `>`, `&`, `"`, and `'` before rendering.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot]
2026-05-29 03:02:29 +00:00
parent 6e4824cb74
commit 5f530a28b3
2 changed files with 16 additions and 1 deletions
+12 -1
View File
@@ -293,13 +293,24 @@ function processFiles(files, progressContainer, statusMessage) {
updateStatus();
}
function _escapeHtml(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
// Pre-create one progress row per file.
const queueItems = fileArray.map((file) => {
const row = document.createElement('div');
row.className = 'flex flex-col mb-2';
const escapedName = _escapeHtml(file.name);
row.innerHTML = `
<div class="flex justify-between">
<span class="text-sm truncate" title="${file.name}">${file.name}</span>
<span class="text-sm truncate" title="${escapedName}">${escapedName}</span>
<span class="text-xs text-gray-500">${formatFileSize(file.size)}</span>
</div>
<div class="w-full bg-gray-200 h-2 rounded-full mt-1">