security: скачивание админом через короткоживущий тикет, а не JWT в URL
Ревью указало: долгоживущий admin-JWT в query попадает в логи nginx/journal. Замена: POST /api/admin/download_ticket выдаёт HMAC-подпись (SESSION_SECRET), живёт 60с, привязана к (username,tab_id,filename). В URL уходит только exp+sig. file_download проверяет тикет (constant-time), отдаёт FileResponse с Referrer-Policy: no-referrer. JWT остаётся в заголовке. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+13
-6
@@ -282,13 +282,20 @@ async function loadFiles() {
|
||||
tbl.appendChild(tr);
|
||||
}
|
||||
}
|
||||
function adminDownload(url, filename) {
|
||||
// Native download: the browser streams straight to disk, so it works for
|
||||
// multi-GB files. The old fetch→blob approach buffered the whole file in
|
||||
// browser memory and silently failed on large ones. <a> can't set an auth
|
||||
// header, so the endpoint also accepts the token via query param.
|
||||
async function adminDownload(url, filename) {
|
||||
// Native download streams straight to disk (works for multi-GB files; the old
|
||||
// fetch→blob buffered the whole file in memory and failed on large ones).
|
||||
// <a> can't send an auth header, so first fetch a short-lived signed ticket
|
||||
// (with the header) and put only that in the URL — never the JWT.
|
||||
const p = new URLSearchParams(url.split('?')[1]);
|
||||
const r = await fetch('/api/admin/download_ticket', {
|
||||
method: 'POST', headers: {...H, 'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({username: p.get('username'), tab_id: p.get('tab_id'), filename: p.get('filename')}),
|
||||
});
|
||||
if (!r.ok) { alert('Ошибка скачивания: ' + r.status); return; }
|
||||
const t = await r.json();
|
||||
const a = document.createElement('a');
|
||||
a.href = url + '&token=' + encodeURIComponent(token);
|
||||
a.href = url + '&exp=' + t.exp + '&sig=' + encodeURIComponent(t.sig);
|
||||
a.download = filename;
|
||||
document.body.appendChild(a); a.click(); a.remove();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user