Behind a gateway, load balancer or reverse proxy: relays, PROXY, XCLIENT and HTTPS
-
Written for 6.3.4. hMailServer 6.3.7 (17 October 2026) adds the PROXY protocol to the IMAP and POP3 listeners: each takes the client's address from a PROXY header as the SMTP listener does, from the peers on a list of its own, and both are off by default; their switches and peer lists are on the IMAP and POP3 cards of the Control Panel's Protocols page. The SMTP listener's PROXY protocol and XCLIENT are a card on Incoming relays, not on Server limits & expert settings, and Ctrl+K takes every old title to its page. A state-changing REST request that carries a credential is now refused when the browser reports it as cross-site (
Sec-Fetch-Site, or anOriginthat is not this server's); scripts,hmctland the PowerShell module send no such header and are unaffected. The ACME HTTP-01 challenge responder, which served one connection at a time, serves up to 64 at once. See the 6.3.7 announcement. hMailServer 6.3.8 (2 November 2026) no longer charges a failed sign-in through a proxy to the proxy: at the web services listener one from loopback or an address inWebServicesTrustedProxies, and at the REST listener an account's from loopback, is counted against the name alone, never towards a ban of the address, where up to 6.3.7 a ban could be written that shut the proxy, or127.0.0.1, out of the SMTP, POP3, IMAP and ManageSieve listeners. The web services listener now also refuses, before the TLS handshake, an address whose IP range allows none of SMTP, POP3 and IMAP, an auto-ban's or one of your own, though never loopback or an address inWebServicesTrustedProxies: where mail reaches the server only through a relay or a VPN and the Internet range allows nothing, that range now closes ACME's http-01 validation when this listener answers it, MTA-STS, CalDAV, CardDAV, Autodiscover, autoconfiguration and the Web Key Directory to the addresses it holds, so check before upgrading that the certificate authority, the sending MTAs and these services' clients do not come from it. See the 6.3.8 announcement.This topic is for a server that does not face the internet alone: behind a hosted spam filter or a filtering appliance, behind a load balancer, or with a reverse proxy terminating HTTPS in front of the webmail, the Control Deck, CalDAV and CardDAV. The one thing to know first: hMailServer judges the address that connected to it, and behind a front end that address is the front end's until you tell the server otherwise. Auto-ban, the rate limits, the IP ranges and every spam test then reason about the wrong machine: SPF fails on every message, and a block list that lists your gateway blocks all your mail. Each kind of front end is handled in its own way, and behind an HTTP reverse proxy the address stays the proxy's.
Which mechanism fits which front end
Front end What reaches hMailServer What tells it the truth A filtering gateway, hosted or an appliance, that accepts the mail and sends it on A new SMTP session from the gateway, the sender's address in its ReceivedheaderIncoming relays, XCLIENTif the gateway can send it, and thegatewaysetting profileA load balancer or TLS terminator in front of the SMTP listener The client's session, from the balancer's address HAProxy PROXYv1 or v2A reverse proxy terminating HTTPS for /portal,/and/api/v1HTTP from the proxy X-Forwarded-Proto: httpsfrom the proxy on the same machine, for the cookies; the address stays the proxy'sA reverse proxy in front of CalDAV, CardDAV and the other web services HTTP from the proxy X-Forwarded-Proto: https, believed from loopback and fromWebServicesTrustedProxiesIncoming relays: what listing one changes
Mail flow & delivery → Incoming relays in the Control Panel (Windows) lists servers that legitimately forward mail to you, each a name and an IP range (a lower and an upper address); a save applies at once. The same list is in the Control Deck, at
/api/v1/incoming-relaysover REST since 6.3.3 (a key confined to named domains is refused), and in COMSettings.IncomingRelayson Windows, where since 6.3.4 a change takes effect only atSave().Listing a relay changes two things:
- When spam protection runs. A connection from a listed relay is switched from pre-transmission to post-transmission testing. DNSBL, PTR and HELO checks judge the connecting IP, so they wait until the body has arrived and the real origin can be read from it. Spam is then no longer refused before the body: with quarantine on, a message reaching the delete threshold is held for review; without it, it is refused with
554 5.7.1after the body. - Which IP counts as the origin. The
Receivedchain is walked from the top, and the first address that is not a listed relay becomes the originating IP. SPF, DMARC and ARC are evaluated against it.
Received: from gw2.example.net [198.51.100.8] listed relay: keep walking Received: from gw1.example.net [198.51.100.7] listed relay: keep walking Received: from mail.sender.example [203.0.113.44] not listed: the originating IPSince 6.2.24 the address taken is the one the relay observed, not the client's own HELO literal; thresholds tuned before then need checking again.
Since 6.3.4 a listed relay changes more:
- A remote domain policy's inbound rule, Require TLS on mail from this domain (
530 5.7.0atMAIL FROM), is not applied to it. The hop that rule is about happened before the gateway, so require TLS on the gateway. Requiring TLS and remote domain policies covers the policies. - Mail it hands over counts as coming from inside. One rule,
MessageOrigin::IsExternalSender, decides that for the external-sender tag, the first-contact note and impersonation protection, so none of the three applies behind a listed gateway. DomainTransforms.md: the choice is between the tag and the relay declaration, and there is no third answer today. Mail flow rules and what a domain does to a message covers the tag. - A spam trap never bans it; the sender is still judged.
- The domain white and black list sees the relay's own HELO name, so key rows for mail behind a relay on the envelope domain.
Keep the range to the exact gateway addresses. An attacker inside a range listed too wide can insert a forged
Receivedheader and choose which IP you evaluate. And leave spam protection on for the IP range the gateway connects from: clearing Enable anti-spam on a range turns off every spam test, greylisting and the recipient tarpit for it, relay or not.Symptom Cause Every message is scored as though it came from your own filter; SPF always fails The front end is not listed as an incoming relay A DNSBL hit on the gateway's address blocks all mail The same Adding a relay stopped spam being rejected before the body Expected: testing moved to after the body. Quarantine and scoring still apply PROXY protocol and XCLIENT
If the front end can pass the real client address itself, that is better than reconstructing it from headers. Two mechanisms have been accepted since 6.2.23-alpha1, both off by default and both honoured only from the addresses you list:
Setting Default What it does SMTPProxyProtocolEnabled0HAProxy PROXYv1 and v2 on the SMTP listener, read before TLS and before the bannerSMTPProxyProtocolTrustedIPsempty The real TCP peers allowed to send a PROXYheader, comma-separated addresses or CIDR ranges. Empty means nobodySMTPXClientEnabled0The Postfix XCLIENTverbSMTPXClientTrustedIPsempty The peers allowed to use it. Empty means nobody - Trust is decided against the real TCP peer, never an address a header supplied, so chained proxies cannot bootstrap trust. An entry that does not parse matches nothing and is logged once per run (
HM6281). - Once an address is listed for PROXY, the header is required from it. Configure the proxy to send it (in HAProxy,
send-proxyorsend-proxy-v2) or its connections are dropped; and aPROXYline from a peer that is not listed closes the connection without a reply. Change the proxy and the settings together. XCLIENTis advertised inEHLOonly to a trusted peer, asXCLIENT ADDR NAME PORT PROTO HELO LOGIN; an untrusted peer never learns the verb exists and gets550if it tries. WithLOGINthe upstream vouches for a signed-in account: RoomsAndEquipment.md counts such a submission as a signed-in session, like SMTPAUTH. Listing an address forXCLIENTtrusts it with that too.
What then sees the real client: auto-ban, the rate limits, the IP ranges, the spam tests, and since 6.3.4 the compromised-account detection's address signal (which never scores behind a proxy that speaks neither) and, with PROXY, the live view of one connection. What does not: country blocking (since 6.3.4). It judges the address the TCP connection came from, the proxy, and exempts loopback and private ranges; put the geographic policy on the proxy. Since 6.3.7 the IMAP and POP3 listeners take the client's address from a PROXY protocol header too, each from the peers on a list of its own (
IMAPProxyProtocolEnabledandIMAPProxyProtocolTrustedIPs,POP3ProxyProtocolEnabledandPOP3ProxyProtocolTrustedIPs), both off by default, the header read before an IMAPS or POP3S port's TLS handshake and before the greeting. No document describes either mechanism for ManageSieve.Where they are set. On Windows, the Control Panel's Maintenance → Server limits & expert settings (card Front-end proxies (PROXY protocol and XCLIENT); in 6.3.7's Control Panel the PROXY protocol and XCLIENT are a card on Incoming relays) or COM
Settings.SetIniSetting. On either system,PUT /api/v1/settings/ini/{name}(the administrator password only; an API key is refused) orhmctl ini set <name> <value>; on Linux alsohmailserver --set-setting. The Control Deck has no editor for these keys. All four apply when saved. Since 6.3.4 the database holds them, so a line edited inhMailServer.inichanges nothing the server uses; the store, the file's copy andHM5804are in Settings: what is not stock and when a save takes effect.# Over REST with the administrator password (an API key is refused), from any machine that reaches the listener; applies when saved hmctl ini set SMTPProxyProtocolTrustedIPs 10.0.0.5,10.0.0.6 hmctl ini set SMTPProxyProtocolEnabled 1 # On a Linux server; a running service takes it at its next save, reinitialise or restart sudo hmailserver --set-setting SMTPProxyProtocolTrustedIPs=10.0.0.5,10.0.0.6 sudo hmailserver --set-setting SMTPProxyProtocolEnabled=1The gateway profile (since 6.3.4)
A setting profile is a named, reviewed set of settings, shown as a diff first.
gatewayis for a server whose inbound mail a filtering gateway has already judged. Its 17 entries include:Entry Value Why (Profiles.md, shortened) usegreylisting0It judges the connecting address, which is the gateway's even through Incoming relays SMTPXClientEnabled1Honoured only from SMTPXClientTrustedIPs, and from nobody while that is emptyASArcFilteringEnabled1With DMARC on, the DMARC penalty is offset when a sealer named in arc_trusted_sealerssealed a passMaxSubmissionsPerIPPerMinute,SmtpTarpitCount0All inbound mail comes from the gateway's few addresses QuarantineEnabled,RejectFullMailboxAtRcpt1A message at the delete threshold is held, not refused back to the gateway; a full mailbox is refused at RCPT so the gateway returns the message usespf,ascheckhostinhelo,ascheckptr,ASDMARCEnabled1Through Incoming relays they judge the real sender AutoBanOnLogonFailureEnabled,SmtpAuthenticatedSenderCheck1For people who sign in here directly The rest switch on DKIM verification, the MX check and attachment blocking, all three off as shipped, and keep the reason headers on. The first four rows turn a check off or trust an address range, so applying asks for an explicit confirmation wherever one of them would change something.
A profile never writes an incoming relay, an IP range, a port's TLS or the ARC sealer. The steps are yours, in this order:
- Add the gateway's addresses to Incoming relays before applying the profile, and leave spam protection on for their IP range. Until they are there, the tests judge the gateway's own address.
- If the gateway sends
XCLIENT, put its addresses inSMTPXClientTrustedIPs. - Name the ARC sealer the gateway signs as in
arc_trusted_sealers(PUT /api/v1/settings/antispam, or COMAntiSpam.ArcTrustedSealers). Until then no seal is trusted. - Read the diff and apply it, on the Control Panel's Setting profiles page under Maintenance, in the Deck's checklist, over REST or with
hmctl, confirming the entries that ask. The apply is all or nothing and saves the values it replaces first; while an earlier profile is neither reverted nor discarded, another apply is refused with 409. The routes, the diff's token, the way back and the command-line verbs are in the profiles section of the unattended installs topic. - Check "Require SSL/TLS when authenticating" on the Internet IP range, or make the submission port STARTTLS-required, for people who sign in here directly. A new installation turns it on; an upgraded one keeps what it had.
- On the listener the gateway delivers to, leave TLS optional unless the gateway offers it: a port's security is the port's, not a setting.
A filter on the same machine
Since 6.3.4 SPF is RFC 7208, and
127.0.0.0/8and::1no longer pass unconditionally. A content filter that re-injects mail over loopback should authenticate, or connect from an IP range with anti-spam off.The HTTP listeners behind a TLS-terminating proxy
REST listener Web-services listener Serves The webmail at /portal, the Control Deck at/, the API under/api/v1ACME challenges, MTA-STS, security.txt, autoconfiguration, CalDAV, CardDAV, the OpenPGP key directoryPlain HTTP behind the proxy Only on loopback: TLS is required unless bound to 127.0.0.1, localhost or ::1 WebServicesHttpPortWhose X-Forwarded-Proto: httpscountsThe proxy on this machine Loopback, and WebServicesTrustedProxies(since 6.3.3)What it decides Secureon the session and sign-in cookiesWhether CalDAV and CardDAV treat the request as HTTPS; the Apple .mobileconfigprofile; the key directoryA changed port or bind address (
RestApiPort,RestApiBindAddress,WebServicesHttpPort,WebServicesHttpsPort) waits for a reinitialise (Apply now).WebServicesTrustedProxiesapplies when saved, and no document names a Control Panel field for it: set it withPUT /api/v1/settings/ini/{name},hmctl ini set, COMSettings.SetIniSettingon Windows orhmailserver --set-settingon Linux (which a running service takes at its next save, reinitialise or restart).The cookies, since 6.3.4.
hmailsessionand the sign-in cookieshmoidc,hmssoandhmpasskeyare markedSecureover TLS, or when the proxy on this machine saysX-Forwarded-Proto: https. Before 6.3.4 only a TLS listener counted, so behind the usual proxy a browser would also send the session cookie over plain HTTP. A proxy that does not set the header still leaves them withoutSecure; a proxy on another machine can only reach a REST listener that speaks TLS itself.CalDAV (since 6.3.4) and CardDAV take HTTP Basic over HTTPS only: over plain HTTP the answer is 403 with the reason, unless a trusted proxy says
X-Forwarded-Proto: https. From any other peer the header is ignored; an entry that does not parse matches nothing (HM6281). The Apple profile honours the header on the same terms, and the OpenPGP key directory (since 6.3.4) answers a plain request with the same 404 as an unknown address; pointopenpgpkey.<domain>at the proxy and forward/.well-known/openpgpkey/with the header. The CalDAV and CardDAV topic covers the rest.The client address stays the proxy's. Nothing reads
X-Forwarded-For, so:- The auto-ban leaves
127.0.0.1and::1alone, and behind a proxy on this machine every webmail and Deck request comes from there. What brakes guessing is the per-name lockout, whenAccountLockoutThresholdis set, and since 6.3.4 each owner's second-factor budget: five wrong codes in fifteen minutes refuse that owner's codes for the next fifteen (429,second_factor_locked). - The forgotten-password route (since 6.3.4) holds loopback to thirty requests in any sixty seconds, all together. A proxy on another host shares one per-client bucket of twenty an hour. Neither has a setting: put the proxy on the mail server or accept the cap.
- For CalDAV, CardDAV and Autodiscover, since 6.3.8 a failed sign-in from loopback or an address in
WebServicesTrustedProxiesis counted against the name alone, never towards a ban of the address, and the listener never refuses those addresses by an IP range, so only proxies belong in that list, and the per-name lockout (AccountLockoutThreshold, off by default) is the limit on the guesses through one. Up to 6.3.7 each such failure was charged to the proxy's address, and a ban written for it could shut the proxy, and every client behind it, out of the SMTP, POP3, IMAP and ManageSieve listeners (AutoBan.md).
Passkeys (since 6.3.4). By default the relying party id is the
Hostheader, which behind a TLS-terminating proxy is still what the browser sent, so the check holds.X-Forwarded-Protois not consulted, which is why the origin check acceptshttpsat the page's host and plainhttponly on a loopback name. A server reached at several names needspasskey_relying_partyandpasskey_allowed_originstogether, the origins written as the browser writes them, port included; the topic on signing in has the rest.The address people use. The server cannot learn it from the proxy. The links in a message that expires, a password-protected message and a password reset use
confidential_base_url(thenquarantine_digest_base_url, thenimport_oauth_redirect_base_url); the quarantine digest's links usequarantine_digest_base_urlalone, a mailing list's uselist_base_url, and single sign-on (since 6.3.4) usesoidc_redirect_base_url. Which paths to publish is in The webmail portal at /portal.Compression: let one side do it (since 6.3.4)
Both listeners compress when the client asks, and there is no setting.
- Negotiation.
Accept-Encodingis the whole of it:gzipordeflate,gzipwhere both are acceptable, neverbr.deflateis the zlib format of RFC 1950, which a raw inflater fails on; ask forgzip. - What. Text, JSON, XML, a manifest,
message/rfc822and an icon, between 1,024 bytes and 4 MB. An image, a PDF or a zip goes as it is, and a download (/api/v1/me/messages/{id}/attachments/{index},/files/{token}) is never compressed. - Headers.
Content-Lengthis the bytes sent; no chunked transfer encoding, no byte ranges.Vary: Accept-Encodingis on every answer of a type it would compress, which matters for the web-services listener, whose answers may be cached; the webmail and the API areCache-Control: no-store.
Behind a reverse proxy, either leave
Accept-Encodingalone and pass the answer through (the server will not encode twice, and the proxy must not either), or stripAccept-Encodingfrom the request and compress at the proxy. What does not is forwardingAccept-Encoding: gzip, receivingContent-Encoding: gzip, and handing the bytes to a client that did not ask.What it does not do
- It reads no forwarded-for header. XCLIENT is an SMTP setting only; since 6.3.7 the PROXY protocol is taken on the IMAP and POP3 listeners too, each from its own list of peers.
- A listed gateway turns off the external-sender tag, the first-contact note and impersonation protection for what it hands over.
- Compression has no switch. A client that wants none sends no
Accept-Encoding, orAccept-Encoding: identity. - A second machine behind a balancer is the warm standby and high availability topic.
Where to read more
- Wiki: Routes and Relays §14.3, Security Hardening §17.8, Stopping Spam §10.1, Settings Overview, and chapter 14.3 of the documentation page.
- Documents at the 6.3.4 tag: Profiles.md, ResponseCompression.md, DomainTransforms.md, PasskeysAndSingleSignOn.md, DevicesAndSessions.md, AccountRecovery.md, CountryBlocking.md, SettingsApply.md, RoomsAndEquipment.md, and README.md for the
[Settings]notes on PROXY, XCLIENT and the web services. - On this forum: The webmail portal at /portal, The Control Deck, the anti-spam stack end to end, IP ranges, auto-ban, lockout and tarpits and TLS on the listeners.
A way past one of these trust lists is a vulnerability: report it by a confidential GitLab issue or by email to the project's Service Desk address, contact-project+hmailserver-hmailserver-86730559-issue-@incoming.gitlab.com, which GitLab files as a confidential issue, and not in a forum post.
- When spam protection runs. A connection from a listed relay is switched from pre-transmission to post-transmission testing. DNSBL, PTR and HELO checks judge the connecting IP, so they wait until the body has arrived and the real origin can be read from it. Spam is then no longer refused before the body: with quarantine on, a message reaching the delete threshold is held for review; without it, it is refused with
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login