This commit is contained in:
tyuXX 2026-10-24 15:19:21 +03:00
parent 68e6fa2353
commit 4714d25724
6 changed files with 86 additions and 20 deletions

View file

@ -185,6 +185,12 @@ string? ExtractBearerToken(HttpRequest request)
}
// REST Endpoints
app.MapGet("/api/csrf-token", (CsrfProtectionService csrf) =>
{
var token = csrf.GenerateToken();
return Results.Ok(new { token });
});
app.MapGet("/api/info", (ServerOptions opt, IAuthService auth, HttpRequest req) =>
{
if (opt.RequireAuthForServerInfo)

View file

@ -665,10 +665,10 @@
inviteToken: inviteToken || null
};
// Generate a simple CSRF token for this request
const csrfToken = Array.from(crypto.getRandomValues(new Uint8Array(16)))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
// Fetch CSRF token from server
const csrfRes = await fetch('/api/csrf-token');
const csrfData = await csrfRes.json();
const csrfToken = csrfData.token || '';
const res = await fetch(endpoint, {
method: 'POST',