fix(server): trust forwarded headers only from known proxies

In TLS mode proxy the server accepted X-Forwarded-For/Proto/Host from any
peer, so a client reaching the HTTP port directly could pick a new address
per sign-in (defeating the 5/min/IP limit), forge audit addresses and claim
HTTPS; the admin never warned (SRS-03, SRV-3). Forwarded headers now count
only from TITANO_TRUSTED_PROXIES (addresses or CIDR networks; default
loopback, 10/8, 172.16/12, 192.168/16, fc00::/7), and the Dashboard and
Settings show a "Not via proxy" chip with a tooltip when a page did not
come through a trusted proxy over HTTPS (ProxyWarning in DashboardDto and
ServerSettingsDto).

TITANO_PUBLIC_HTTP_PORT and TITANO_PUBLIC_HTTPS_PORT name the ports clients
reach when a container's ports are published as other host ports: the
admin's HTTP-to-HTTPS redirect and the LAN beacon use them instead of the
bound container ports (DOCKER-4, DOCKER-5). --help lists TITANO_LOG_LEVEL,
the new variables and the container's PUID, PGID and TZ (DOCKER-7); a test
keeps it in step with the variables the server reads.

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 09:27:31 +00:00
1 parent 047cddfe7b
commit 5ec59a2e96
17 files changed
+340 -22

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>