security upgrade

This commit is contained in:
Mateusz Gruszczyński
2026-07-30 09:57:43 +02:00
parent 2274cf57c9
commit f6b8e016a8
24 changed files with 1100 additions and 272 deletions
+3 -5
View File
@@ -33,6 +33,7 @@ function formatBytes(bytes) {
}
function clearExpiredSession() {
localStorage.removeItem("rustpad:auth-state");
localStorage.removeItem("rustpad:auth-token");
sessionStorage.removeItem("rustpad:auth-token");
localStorage.removeItem("rustpad:nickname");
@@ -42,11 +43,9 @@ function clearExpiredSession() {
}
async function clearSessionIfInvalid() {
const token = localStorage.getItem("rustpad:auth-token") || sessionStorage.getItem("rustpad:auth-token");
if (!token) return;
if (!localStorage.getItem("rustpad:auth-state")) return;
try {
const response = await fetch("/api/auth/me", {
headers: { Authorization: `Bearer ${token}` },
signal: AbortSignal.timeout(5000),
});
if (response.status === 401) clearExpiredSession();
@@ -70,8 +69,7 @@ function validateUploadSize(body) {
function requestHeaders(options, body) {
const headers = new Headers(options.headers || {});
const authToken = localStorage.getItem("rustpad:auth-token") || sessionStorage.getItem("rustpad:auth-token");
if (authToken && !headers.has("authorization")) headers.set("authorization", `Bearer ${authToken}`);
headers.delete("x-rustpad-user-token");
if (!(body instanceof FormData) && !headers.has("content-type")) headers.set("content-type", "application/json");
return headers;
}