From 3f4b67d82b995e6c017dff47e11453043d5e209e Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 17 Jul 2026 22:30:17 +1000 Subject: [PATCH] =?UTF-8?q?fix(security):=20stored-XSS=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B0=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB=D1=8C=20=D1=81=D0=B5?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B9/=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2/?= =?UTF-8?q?=D0=B0=D1=83=D0=B4=D0=B8=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit esc() экранирует last_question/tab_id/username/detail (под контролем юзера) перед innerHTML; tab_id в href через encodeURIComponent; admin_sessions GROUP BY (username, tab_id) — сессии разных юзеров с одним tab_id больше не склеиваются. Найдено Fable. --- static/admin.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/static/admin.html b/static/admin.html index c2b7dd4..23338bd 100644 --- a/static/admin.html +++ b/static/admin.html @@ -199,6 +199,10 @@ function showPage(name) { // Handle hash on load if (location.hash) showPage(location.hash.slice(1)); +// Экранирование пользовательского ввода перед вставкой в innerHTML (stored-XSS на админа: +// last_question/tab_id/username/detail — под контролем обычного юзера). Fable. +function esc(s){ return String(s==null?'':s).replace(/[&<>"']/g, c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); } + // === Dashboard === fetch('/api/admin/stats', {headers: H}).then(r=>r.json()).then(data => { const t = data.totals; @@ -306,10 +310,10 @@ async function loadFiles() { const dlUrl = '/api/admin/file_download?username=' + encodeURIComponent(owner) + '&tab_id=' + encodeURIComponent(f.tab_id) + '&filename=' + encodeURIComponent(f.filename); - const userCol = isAll ? '' + owner + '' : ''; + const userCol = isAll ? '' + esc(owner) + '' : ''; tr.innerHTML = userCol - + '' + f.tab_id + '' - + '' + f.filename.replace(/' + + '' + esc(f.tab_id) + '' + + '' + esc(f.filename) + '' + '' + fmtSize(f.size) + '' + '' + ts + '' + ''; @@ -384,10 +388,10 @@ async function loadAudit(offset) { const d = new Date(row.timestamp < 1e12 ? row.timestamp*1000 : row.timestamp); const ts = d.toLocaleString('ru-RU',{day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit'}); const tr = document.createElement('tr'); - const detail = (row.detail||'').slice(0,80); + const detail = esc((row.detail||'').slice(0,80)); const sc = row.status_code; const scStyle = sc >= 400 ? 'color:var(--accent)' : ''; - tr.innerHTML = `${ts}${row.username||'-'}${row.action}${row.path}${detail}${row.ip||''}${sc||''}`; + tr.innerHTML = `${ts}${esc(row.username||'-')}${esc(row.action)}${esc(row.path)}${detail}${esc(row.ip||'')}${sc||''}`; t.appendChild(tr); } document.getElementById('audit-more').style.display = rows.length >= AUDIT_LIMIT ? '' : 'none'; @@ -441,8 +445,8 @@ fetch('/api/admin/sessions', {headers: H}).then(r=>r.json()).then(sessions => { const d = new Date(s.last_ts < 1e12 ? s.last_ts * 1000 : s.last_ts); const ts = d.toLocaleString('ru-RU', {day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit'}); const tr = document.createElement('tr'); - const q = (s.last_question || '').slice(0, 80); - tr.innerHTML = `${ts}${s.username}${s.msg_count}${q}Открыть`; + const q = esc((s.last_question || '').slice(0, 80)); + tr.innerHTML = `${ts}${esc(s.username)}${s.msg_count}${q}Открыть`; table.appendChild(tr); } }).catch(()=>{});