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(()=>{});