🛡️ Sentinel: [HIGH] Fix DOM-based XSS in file upload
- Added `_escapeHtml` helper to sanitize user-controlled file name. - Used it to sanitize `file.name` before appending it to `row.innerHTML`. - Applied changes to `frontend/static/js/upload.js`. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -169,6 +169,21 @@ function _onUploadSuccess() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to sanitize strings before injecting into HTML.
|
||||||
|
* @param {string} str
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function _escapeHtml(str) {
|
||||||
|
if (!str) return '';
|
||||||
|
return String(str)
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
}
|
||||||
|
|
||||||
// ── Directory traversal helpers ───────────────────────────────────────────────
|
// ── Directory traversal helpers ───────────────────────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,9 +312,10 @@ function processFiles(files, progressContainer, statusMessage) {
|
|||||||
const queueItems = fileArray.map((file) => {
|
const queueItems = fileArray.map((file) => {
|
||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
row.className = 'flex flex-col mb-2';
|
row.className = 'flex flex-col mb-2';
|
||||||
|
const safeName = _escapeHtml(file.name);
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<span class="text-sm truncate" title="${file.name}">${file.name}</span>
|
<span class="text-sm truncate" title="${safeName}">${safeName}</span>
|
||||||
<span class="text-xs text-gray-500">${formatFileSize(file.size)}</span>
|
<span class="text-xs text-gray-500">${formatFileSize(file.size)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full bg-gray-200 h-2 rounded-full mt-1">
|
<div class="w-full bg-gray-200 h-2 rounded-full mt-1">
|
||||||
|
|||||||
Reference in New Issue
Block a user