Merge branch 'fix/server-hardening': Windows secrets, trusted proxies, Docker and Unraid fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 11:10:50 +00:00
commit 24ad790c37
33 files changed
+1261 -49

No files matched your search

+8 -4
View File
@@ -3,6 +3,7 @@ using Titano.Core.Model;
using Titano.Data;
using Titano.Protocol;
using Titano.Server.Configuration;
using Titano.Server.Hosting;
using Titano.Server.Jobs;
using Titano.Server.Security;
using Titano.Server.Storage;
@@ -18,7 +19,8 @@ public static class AdminEndpoints
public static void Map(RouteGroupBuilder api)
{
api.MapGet("/server/dashboard", DashboardAsync).Requires(Permissions.ManageArchive | Permissions.ManageUsers);
api.MapGet("/server/settings", (ServerSettingsStore store) => Results.Json(store.Current(), ProtocolJson.Default.ServerSettingsDto))
api.MapGet("/server/settings", (HttpContext context, ServerSettingsStore store, ServerOptions options) =>
Results.Json(store.Current() with { ProxyWarning = AdminPanel.BypassesProxy(context, options) }, ProtocolJson.Default.ServerSettingsDto))
.Requires(Permissions.ManageArchive);
api.MapPut("/server/settings", SaveSettingsAsync).Requires(Permissions.ManageArchive);
api.MapGet("/audit", AuditAsync).Requires(Permissions.ManageUsers | Permissions.ManageArchive);
@@ -65,11 +67,13 @@ public static class AdminEndpoints
[.. nodes.Select(n => Dto.Node(n, names.GetValueOrDefault(n.UserId, string.Empty)))],
[.. uploads.Select(u => new UploadDayDto(u.Day, u.Count, u.Bytes))],
[.. activity.Items.Select(Dto.Audit)],
[.. running.Items.Concat(queued.Items.OrderByDescending(j => j.Priority).ThenBy(j => j.Created)).Take(10).Select(Dto.Job)]),
[.. running.Items.Concat(queued.Items.OrderByDescending(j => j.Priority).ThenBy(j => j.Created)).Take(10).Select(Dto.Job)],
AdminPanel.BypassesProxy(context, options)),
ProtocolJson.Default.DashboardDto);
}
private static async Task<IResult> SaveSettingsAsync(HttpContext context, Caller caller, ServerSettingsDto request, ServerSettingsStore store, AuditLog audit)
private static async Task<IResult> SaveSettingsAsync(HttpContext context, Caller caller, ServerSettingsDto request, ServerSettingsStore store, ServerOptions options,
AuditLog audit)
{
switch (store.Save(request))
{
@@ -79,7 +83,7 @@ public static class AdminEndpoints
return ApiErrors.BadRequest(context, code, setting, setting);
}
await audit.WriteAsync(caller, context, "server_settings", "server", null, request.ServerName);
return Results.Json(store.Current(), ProtocolJson.Default.ServerSettingsDto);
return Results.Json(store.Current() with { ProxyWarning = AdminPanel.BypassesProxy(context, options) }, ProtocolJson.Default.ServerSettingsDto);
}
/// <summary>The audit log, newest first; <c>action</c> may list several actions separated by commas (<c>login,login_failed</c>).</summary>
+12 -2
View File
@@ -18,8 +18,18 @@ public static class AuthEndpoints
api.MapGet("/auth/me", (Caller caller) => Results.Json(Dto.User(caller.User), ProtocolJson.Default.UserDto)).AllowDuringPasswordChange();
}
/// <summary>
/// Why the <c>Secure</c> session cookie cannot be set for this request, or null when it can (HTTPS, or the machine
/// itself). In TLS mode proxy only a trusted proxy makes a request HTTPS, so the refusal names that setting.
/// </summary>
internal static string? CookieRefusal(HttpContext context, ServerOptions options)
{
if (SessionCookies.IsSecureTransport(context)) return null;
return options.TlsMode == TlsMode.Proxy ? "proxy_untrusted" : "https_required";
}
private static async Task<IResult> LoginAsync(HttpContext context, LoginRequest request, TitanoDatabase db, TokenService tokens, LoginGuard guard,
AuditLog audit, TimeProvider time)
AuditLog audit, TimeProvider time, ServerOptions options)
{
var ct = context.RequestAborted;
if (!guard.TryAttempt(context.Connection.RemoteIpAddress?.ToString() ?? "unknown", out var wait)) return TooMany(context, "rate_limited", wait);
@@ -27,7 +37,7 @@ public static class AuthEndpoints
if (!Accounts.IsValidUsername(account) || string.IsNullOrEmpty(request.Password))
return ApiErrors.Result(context, StatusCodes.Status401Unauthorized, "invalid_credentials");
if (guard.IsLocked(account, out wait)) return TooMany(context, "account_locked", wait);
if (request.Cookie && !SessionCookies.IsSecureTransport(context)) return ApiErrors.BadRequest(context, "https_required");
if (request.Cookie && CookieRefusal(context, options) is { } refusal) return ApiErrors.BadRequest(context, refusal);
var user = await db.Users.GetByUsernameAsync(account, ct);
bool valid;