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

@@ -12,7 +12,8 @@ namespace Titano.Server.Hosting;
/// <summary>
/// LAN discovery (BRIEF §14.9, <c>TITANO_DISCOVERY</c>): every few seconds a <see cref="DiscoveryBeacon"/> is broadcast on
/// UDP port <see cref="DiscoveryBeacon.Port"/> of every IPv4 network, so clients can offer this server on first run.
/// Switching discovery off in the settings stops it without a restart.
/// Switching discovery off in the settings stops it without a restart. In a container the broadcasts reach the LAN
/// only with host networking; on a bridge network they stay on the bridge.
/// </summary>
public sealed class DiscoveryBeaconService(ServerOptions options, ServerState state, IServer server, ILogger<DiscoveryBeaconService> logger) : BackgroundService
{
@@ -51,12 +52,15 @@ public sealed class DiscoveryBeaconService(ServerOptions options, ServerState st
}
}
/// <summary>The beacon for the ports Kestrel actually listens on (HTTPS 0 when TLS is terminated elsewhere).</summary>
/// <summary>
/// The beacon for the ports clients reach: the public ports when set, else the ports Kestrel actually listens on
/// (HTTPS 0 when TLS is terminated elsewhere).
/// </summary>
public DiscoveryBeacon CreateBeacon() => new(
options.ServerName,
SystemEndpoints.Version,
BoundPort(Uri.UriSchemeHttp) ?? options.HttpPort,
state.TlsFingerprint is null ? 0 : BoundPort(Uri.UriSchemeHttps) ?? options.HttpsPort,
options.PublicHttpPort ?? BoundPort(Uri.UriSchemeHttp) ?? options.HttpPort,
state.TlsFingerprint is null ? 0 : options.PublicHttpsPort ?? BoundPort(Uri.UriSchemeHttps) ?? options.HttpsPort,
state.TlsFingerprint);
public async Task SendOnceAsync(UdpClient udp, IEnumerable<IPEndPoint> targets, CancellationToken cancellationToken)