From d00e1dceeb058e6118a50a76c3344ef0224df42b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 18 May 2026 15:55:40 +0000 Subject: [PATCH] fix: Sanitize filenames and directory paths to prevent XSS Co-authored-by: aider (gemini/gemini-2.5-pro) --- frontend/menu.html | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/menu.html b/frontend/menu.html index 604299b..1eee5e3 100644 --- a/frontend/menu.html +++ b/frontend/menu.html @@ -483,6 +483,15 @@ const filesTBody = document.getElementById('filesTBody'); let DIRS = []; + function escapeHtml(text) { + return String(text) + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + } + function humanSize(bytes){ if (!bytes) return '0 B'; const k = 1024, sizes = ['B','KB','MB','GB','TB']; @@ -509,7 +518,7 @@ const modified = `${fmtDayMonthForFiles(dir.modified)}`; return ` - ${dir.path} + ${escapeHtml(dir.path)} ${dir.file_count} ${humanSize(dir.total_size)} ${modified} @@ -545,12 +554,13 @@ ${files.length ? `
` + files.map(it => { const thumbUrl = it.is_image ? `/api/files/thumb/${it.path_b64}` : ''; const fullUrl = `/api/files/full/${it.path_b64}`; - return ` + const safeName = escapeHtml(it.name); + return ` ${it.is_image ? `` : `` } -
${it.name}
+
${safeName}
` }).join('') + `
` : '
No files in this directory.
'}