Allow additional trusted hosts for web console sign-in

Use case

We package Stalwart for StartOS, a self-hosted server OS. A StartOS server reaches each service at several addresses at once: its public hostname (for example https://mail.example.com), a LAN mDNS name with its own port (https://myserver.local:64341), its LAN IP, and a Tor .onion address. StartOS terminates TLS at every one of those addresses and proxies plain HTTP to Stalwart’s port 8080. When a user opens the web console from any of them, they expect to be able to sign in. Often they do this before public DNS and the Let’s Encrypt certificate for the public hostname are working, which is when they most need the console.

What happens in 1.0.2

The console loads at https://myserver.local:64341/admin/, but signing in fails with “Unable to continue. Client metadata documents are disabled.”

As far as we can tell from the v1.0.2 source, this is by design. The console’s client_id (https://myserver.local:64341/admin/oauth-client.json) is recognized as the built-in application only when its authority is a trusted host (AppOriginPolicy::TrustedHosts in crates/common/src/auth/oauth/client.rs). Otherwise resolution falls through to the client metadata document path, which is disabled by default. The trusted hosts come from ResourceIdentifiers::build in crates/common/src/config/resource.rs: the host in the public URL plus one hostname per JMAP/CalDAV/CardDAV/WebDAV service. The same list also governs the OAuth resource origin (resource_origin in crates/http/src/auth/oauth/authorize.rs) and the token audience check (authenticate_external_token in crates/common/src/auth/authentication.rs).

So there is currently no way to trust a second console origin. We considered the workarounds available to us, and none of them works:

  • Setting the public URL to the LAN address would make that address the only trusted host, and it would pin JMAP and OIDC discovery to it for every mail client.
  • Setting a DAV service’s hostname to the LAN address would break that protocol’s client discovery, and it would cover only one extra address.
  • Registering an OAuth client for each LAN address would get past client resolution, but the resource origin and audience checks would still reject the origin.
  • Enabling client metadata documents would make the server fetch its own .local URL, and sameDomain mode requires the public registrable domain anyway.

Request

Please add a setting that holds a list of additional trusted hosts (authorities, port included), for example on the Http or OidcProvider singleton. Each entry would be added to ResourceIdentifiers::trusted_hosts and identifiers, so that the first-party console client, the resource origin and the token audience all accept it. The public URL would remain the issuer and the only address advertised for discovery. The extra hosts would only allow the console and the account manager to sign in from those origins.

A same-origin allowance limited to private-network and .local/.onion authorities would also solve our case, but an explicit list seems simpler and easier to reason about.

Thank you for Stalwart.

I may be encountering a related issue with TLS termination during bootstrap on Stalwart 1.0.3.

My reverse proxy serves https://stalwart.example.com and forwards requests to Stalwart over plain HTTP on port 8080. The container has STALWART_PUBLIC_URL=https://stalwart.example.com set, which I verified using docker exec.

However, Stalwart starts in bootstrap mode with “No configuration file was found”. Both the OIDC discovery document and /admin/oauth-client.json contain http://stalwart.example.com URLs. Signing in through the HTTPS proxy fails with “Client metadata documents are disabled”.

Unlike the original request, I only need one public origin. Is bootstrap behind a TLS-terminating reverse proxy intentionally unsupported, or should the configured public HTTPS URL be honored in this mode?

Developer made some comments on this issue in another recent thread

Now that I’m thinking a little more about this, it doesn’t make sense that we should have to even expose the Admin Panel or user manager for the domain on the domain itself (or any other public domain). It would be much better for operational security if this were not a check in the first place, in Stalwart upstream. Perhaps I will attempt a PR.