How does an MTA-STS policy (RFC 8461) tell sending MTAs to require authenticated TLS, and what do its enforce, testing and none modes change?
answer
- DNS signals, HTTPS carries the policy
- a TXT record with a version id
- a well-known path on a fixed host
- mx patterns, mode and max_age
- cached, so the first contact is exposed
basics
~20 sA domain publishes a _mta-sts TXT record (v=STSv1 and an id) and serves a policy over HTTPS from mta-sts.<domain>/.well-known/mta-sts.txt. Under enforce, senders deliver only to listed MX hosts presenting valid certificates; testing only reports; none withdraws the policy.
solid answer
~50 sMTA-STS splits the policy between DNS and HTTPS. The TXT record at `_mta-sts.example.com` holds `v=STSv1; id=...;` and tells senders a policy exists; the `id` changes whenever the policy does. The policy file is fetched from `https://mta-sts.example.com/.well-known/mta-sts.txt` over a certificate valid for that host, with no redirects, and carries `version: STSv1`, `mode`, one or more `mx` patterns and `max_age` (seconds, at most 31557600). A sender with a cached policy checks each MX: its name must match an `mx` pattern, it must offer STARTTLS, and its certificate must chain to a CA the sender trusts and carry the MX host name. In `enforce` the sender MUST NOT deliver to an MX that fails; it tries the next MX, treats the failure as temporary and checks for a new policy before giving up. In `testing` it delivers anyway and reports failures through TLSRPT. `none` tells senders to act as if no policy exists, which is how a domain withdraws.
code
ini · 5 linesversion: STSv1
mode: enforce
mx: mx1.example.com
mx: mx2.example.com
max_age: 1209600go deeper
Remember the two pieces: a _mta-sts TXT record that announces the policy and an HTTPS policy file on the mta-sts host.
Explain the fields of the policy file, the three checks a sender makes at each MX, and exactly what enforce, testing and none change.
Walk through a safe MX migration and a clean withdrawal, and explain why first contact is exposed and what a long max_age buys.
Decide when a domain is ready to move from testing to enforce, what evidence you require first, and how MTA-STS's reliance on public CAs compares with DANE.
## What MTA-STS adds to STARTTLS **SMTP MTA Strict Transport Security (MTA-STS)**, RFC 8461 (September 2018), lets a receiving domain declare that it accepts mail only over TLS with a certificate a sender can verify. It answers the two weaknesses of opportunistic STARTTLS: an on-path party removing the STARTTLS offer, and a forged MX answer sending mail to an impostor. It relies on ordinary certificate authorities, the same Web PKI browsers use, and does **not** require DNSSEC; that is the main contrast with DANE. ## The TXT record and the policy file A domain publishes two things. ```dns _mta-sts.example.com. 3600 IN TXT "v=STSv1; id=20261009T0800;" ``` - The **TXT record** at `_mta-sts.<domain>` must begin with `v=STSv1` and carry an `id` of up to 32 letters and digits. The `id` exists so a sender can tell whether its cached policy is current without an HTTPS request. It must change with every policy, but there is no implied ordering: it need not increase. - The **policy file** lives at `https://mta-sts.<domain>/.well-known/mta-sts.txt`. The host's certificate must be valid for the `mta-sts` name, only an HTTP 200 counts, redirects MUST NOT be followed and HTTP caching MUST NOT be used. The policy holds four fields: | Field | Meaning | |---|---| | `version` | Always `STSv1` | | `mode` | `enforce`, `testing` or `none` | | `mx` | One line per allowed MX pattern, required unless the mode is `none` | | `max_age` | How long senders may cache the policy, in seconds, at most 31557600 (about a year) | An `mx` pattern is either an exact name or `*.` followed by a suffix, and the wildcard covers exactly one label: `*.example.com` matches `mail.example.com` but neither `example.com` nor `a.b.example.com`. ## What a sender checks at each MX With a valid cached policy, a sending MTA that honours MTA-STS checks every candidate MX in normal preference order: 1. The MX host name matches at least one `mx` pattern. 2. The server offers STARTTLS. 3. Its certificate is unexpired, chains to a root the sender trusts, and has a subject alternative name matching **the MX host name**. Failing any of these is a policy validation failure. RFC 8461 asks senders to treat a failing candidate as unreachable and move to the next one, rather than pre-filtering the list, so a misconfigured backup MX may stay invisible until the primary goes down. How the certificate path itself is validated belongs to the material on certificate trust chains. ## The three modes - **`enforce`**: senders MUST NOT deliver to an MX that fails matching, certificate validation or STARTTLS. The failure should be treated as temporary, and before any message is permanently failed the sender must check the TXT record for a new policy; otherwise normal retry rules apply. - **`testing`**: senders that also implement TLS reporting send a report of the failure to the domain, and deliver as though no validation failure occurred. - **`none`**: senders treat the domain as having no active policy. It exists so that a domain can leave MTA-STS cleanly, distinguishable from an attack that hides the policy. ## Caching, max_age and the first contact Senders cache a policy for up to `max_age` from the last fetch, refresh it proactively (the RFC suggests daily), and keep applying a cached, unexpired policy even when DNS or HTTPS fails. If the TXT record exists but no policy can be fetched and nothing is cached, the sender MUST deliver as though the domain had no MTA-STS. That leaves the known gap: **the first contact is unprotected**, because an attacker who suppresses the TXT record or the HTTPS fetch on that first lookup makes the domain look policy-free. RFC 8461 section 10.2 therefore asks for `max_age` values as long as practical, typically weeks or more, and notes that DANE resists this downgrade because DNSSEC can prove that a record is absent. ## Changing or removing a policy 1. Update the HTTPS policy file first, then publish a TXT record with a new `id`, so no sender caches the old file under the new `id`. 2. Keep the old MX hosts working until previously served policies can have expired; a sender may still be holding them. 3. To withdraw, publish `mode: none` with a short `max_age`, change the `id`, wait for every earlier policy to expire, then remove the record and the host. Postfix takes MTA-STS policy from an external STS policy plugin queried through `smtp_tls_policy_maps`; from Postfix 3.10.5, `smtp_tls_enforce_sts_mx_patterns = yes` (the default) makes it connect only to MX hosts matching the policy's patterns, provided the plugin forwards those attributes.
- Why does RFC 8461 want a long max_age?Because the policy only protects senders that already have it cached. An attacker who can block the TXT lookup or the HTTPS fetch can make a domain look policy-free on first contact or at refresh. A long `max_age`, weeks or more, plus daily proactive refreshes means an attacker would have to block every refresh for the whole cache lifetime, and senders are asked to alert on repeated refresh failures.
- A domain moves its inbound mail to new MX hosts. In what order should it change the MTA-STS policy?Add the new hosts as extra `mx` lines in the policy file, alongside the old ones, then publish a new `id`. Move the MX records only once that policy is live, and keep the old hosts accepting mail until senders' cached copies of earlier policies can have expired. Remove the old `mx` lines last, with another `id` change.
- The whole MTA-STS policy is published in the _mta-sts TXT record
- Testing mode blocks delivery but sends reports
- MTA-STS needs a DNSSEC-signed zone to work
- The MX certificate must name the recipient domain rather than the MX host
- The id must increase numerically with each new policy
- Under enforce a failing MX causes an immediate permanent bounce