fix(server): refuse planted Windows data, guard new archives, trust only loopback proxies

- Windows data folder: the folder and everything in it must belong to SYSTEM,
  Administrators or the server's account and hold no link, checked before the
  ACL is rewritten; otherwise the server stops and names the entry. server.json
  is read only after its owner is checked on the open handle. Secrets are
  deleted and created anew with the private ACL, so a planted file's owner
  loses its rights.
- Windows archive: a folder the server creates is changeable only by those
  accounts (users may read it) and a .titano folder it creates is private; an
  existing archive others can change is logged as a warning at start.
- Proxy mode: only loopback is trusted by default, since LAN clients reach the
  HTTP port from private addresses; a cookie sign-in that did not come through
  a trusted proxy over HTTPS answers proxy_untrusted, naming
  TITANO_TRUSTED_PROXIES.

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:08:12 +00:00
1 parent 650a82a8f7
commit df2d4b4316
11 files changed
+497 -64

No files matched your search

@@ -3,6 +3,7 @@ using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using Titano.Data;
using Titano.Server.Hosting;
namespace Titano.Server.Configuration;
@@ -59,10 +60,12 @@ public sealed class ServerOptions
];
/// <summary>
/// Reverse proxies whose <c>X-Forwarded-*</c> headers count in TLS mode proxy: loopback and the private networks a
/// compose or Unraid proxy container connects from (RFC 1918, IPv6 unique local).
/// Reverse proxies whose <c>X-Forwarded-*</c> headers count in TLS mode proxy when none are configured: loopback only.
/// A home network's machines reach the HTTP port directly from private addresses (also through Docker's port
/// publishing, which keeps the client's address), so trusting a private network would let them pick their own
/// address again; a proxy in another container or on another machine is listed by its address or network.
/// </summary>
public const string DefaultTrustedProxies = "127.0.0.0/8, ::1/128, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7";
public const string DefaultTrustedProxies = "127.0.0.0/8, ::1/128";
/// <summary>The environment variables the server reads (<c>--help</c> lists them all).</summary>
public static IEnumerable<string> EnvironmentVariables => Variables.Select(v => v.Variable).Prepend("TITANO_DATA_PATH");
@@ -170,7 +173,8 @@ public sealed class ServerOptions
{
try
{
options = JsonSerializer.Deserialize(File.ReadAllText(file), ServerOptionsJson.Default.ServerOptions) ?? options;
// Its owner is checked first: a file another user planted would choose the archive, database and TLS key.
options = JsonSerializer.Deserialize(DataFolderAccess.ReadTrustedText(file), ServerOptionsJson.Default.ServerOptions) ?? options;
}
catch (JsonException ex)
{