fix(server): client address from the page's port, stricter Chronos identity, Host networking notes

Review fixes on top of the public ports change (owner review 3):

- Settings > Network and TLS: opened over HTTPS, the client address uses the port
  the page came through (a container's 8443 published as 8444 with Public HTTPS
  port still empty showed the wrong 8443), and a "Use <port>" button fills that
  port in. Saving a Public HTTPS port other than the page's asks first, since the
  HTTPS redirect follows it at once and a typo would lock the panel's link out.
- GetInfoAsync tells Chronos from other services by stricter rules on both the
  trusted and the untrusted-certificate path: any redirect, any answer that is not
  JSON, more than 1 MB, or an error without the X-Chronos-Api header is not
  Chronos. Another service's certificate is no longer offered for trust after a
  cross-scheme redirect, an error page or a JSON 401/403/404, and a JSON 401 over
  HTTP no longer reads as a wrong password.
- The HTTP port typed without a scheme (TLS to a plain HTTP port) now gives the
  not-Chronos error instead of "the server did not answer".
- The Uploader's certificate question names the address with its port.
- A link-local IPv6 address with a zone index is refused instead of losing it.
- In a container, the first save of the settings removes HttpPort/HttpsPort from
  server.json, so the start-up warning stops; the warning says so.
- Guide, README, compose and template: with network type Host the mappings do
  nothing and CHRONOS_HTTP_PORT / CHRONOS_HTTPS_PORT move the listening ports off
  ones another service uses; the template overview is back to two sentences.
- BRIEF, DECISIONS and CHANGELOG updated; en/it strings added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 10:28:08 +01:00
1 parent 369e754bec
commit 0aa2fb8135
19 files changed
+303 -67

No files matched your search

@@ -21,17 +21,48 @@ namespace Chronos.Server.Tests.Api;
[Category("server")]
public sealed class ServerIdentityTests(TestContext context)
{
/// <summary>Answers of another service, each under its own path.</summary>
private static readonly string[] OtherAnswers =
[
"html/", "redirect/", "away/", "empty/", "json/", "unauthorized/", "missing/", "text/", "failed/", "gateway/", "json401/", "json403/",
"json404/", "huge/", "hugejson/",
];
[Test]
public async Task AnAddressThatAnswersAsSomethingElseIsNotAChronosServer()
{
await using var other = await OtherService.StartAsync(context);
foreach (var path in new[] { "html/", "redirect/", "empty/", "json/", "unauthorized/", "missing/" })
// Over HTTP, and over HTTPS behind the service's own certificate, which nobody trusted.
foreach (var address in new[] { other.Http, other.Https }.SelectMany(root => OtherAnswers.Select(path => new Uri(root, path))))
{
var address = new Uri(other.Http, path);
using var client = new ChronosClient(address, new CertificatePinning([]), "tests");
var error = await Assert.ThrowsAsync<NotChronosServerException>(() => client.GetInfoAsync(context.Cancellation));
Assert.Equal(address, error.Address, path);
var error = await Assert.ThrowsAsync<NotChronosServerException>(() => client.GetInfoAsync(context.Cancellation), address.ToString());
Assert.Equal(address, error.Address, address.ToString());
}
Assert.Equal(0, other.Authorized, "no request carried credentials");
}
[Test]
public async Task TheHttpPortTypedWithoutASchemeIsNotAChronosServer()
{
// "192.168.30.23:8087", the port of the panel's link: HTTPS to a port that answers plain HTTP.
await using var server = await TestServer.StartAsync(context);
Assert.True(ChronosAddress.TryParse($"127.0.0.1:{server.HttpBase.Port}", out var typed));
using var client = new ChronosClient(typed, new CertificatePinning([]), "tests");
var error = await Assert.ThrowsAsync<NotChronosServerException>(() => client.GetInfoAsync(context.Cancellation));
Assert.Equal(typed, error.Address);
await using var other = await OtherService.StartAsync(context);
using var otherClient = new ChronosClient(new UriBuilder(other.Http) { Scheme = "https", Port = other.Http.Port }.Uri, new CertificatePinning([]), "tests");
await Assert.ThrowsAsync<NotChronosServerException>(() => otherClient.GetInfoAsync(context.Cancellation));
// A port where nothing answers is still unreachable, not another service.
var listener = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0);
listener.Start();
var closed = ((IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();
using var nobody = new ChronosClient(new Uri($"https://127.0.0.1:{closed}/"), new CertificatePinning([]), "tests");
await Assert.ThrowsAsync<HttpRequestException>(() => nobody.GetInfoAsync(context.Cancellation));
}
[Test]
@@ -110,6 +141,17 @@ public sealed class ServerIdentityTests(TestContext context)
app.MapGet("/empty/api/v1/server/info", () => Results.Content("{}", "application/json"));
app.MapGet("/json/api/v1/server/info", () => Results.Content("""{"status":"ok","name":"router"}""", "application/json"));
app.MapGet("/unauthorized/api/v1/server/info", () => Results.StatusCode(StatusCodes.Status401Unauthorized));
// An absolute redirect to plain HTTP, which a client never follows from HTTPS.
app.MapGet("/away/api/v1/server/info", (HttpContext http) => Results.Redirect($"http://{http.Request.Host}/login"));
app.MapGet("/text/api/v1/server/info", () => Results.Text("ok"));
app.MapGet("/failed/api/v1/server/info", () => Results.Content("<!doctype html><title>Error</title>", "text/html", statusCode: StatusCodes.Status500InternalServerError));
app.MapGet("/gateway/api/v1/server/info", () => Results.Content("<!doctype html><title>Bad gateway</title>", "text/html", statusCode: StatusCodes.Status502BadGateway));
// Errors in JSON with a code of their own, as many web services write them.
foreach (var (path, status) in new[] { ("json401", 401), ("json403", 403), ("json404", 404) })
app.MapGet($"/{path}/api/v1/server/info", () => Results.Content("""{"code":"denied","message":"Sign in"}""", "application/json", statusCode: status));
// More than a server info ever holds.
app.MapGet("/huge/api/v1/server/info", () => Results.Content("<!doctype html>" + new string('x', 2 << 20), "text/html"));
app.MapGet("/hugejson/api/v1/server/info", () => Results.Content("{\"name\":\"" + new string('x', 2 << 20) + "\"}", "application/json"));
await app.StartAsync(context.Cancellation);
service = new OtherService(app);
return service;