skip to content

How does the Sender Rewriting Scheme (SRS) let a mail forwarder pass SPF while bounces still reach the original sender, and why is the rewritten address signed?

level: seniorimportance: should knowfreq 24%

answer

  1. move the envelope into the forwarder's domain
  2. original sender encoded in the local-part
  3. SRS0, hash, timestamp, domain, user
  4. unsigned reversal is a relay

basics

~20 s

SRS rewrites MAIL FROM to an address in the forwarder's own domain that encodes the original sender, so receivers check the forwarder's SPF record. Bounces return there, are verified by hash and timestamp, and are relayed back.

solid answer

~50 s

A forwarder that keeps the original `MAIL FROM` is checked against a record that does not list it. SRS, described in a 2004 paper and never published as an RFC, has the forwarder replace the envelope sender with an address such as `[email protected]`. That address is in the forwarder's own domain, which its own SPF record authorizes, so the next hop can return `pass` for alumni.example.org. If the message bounces, the null-sender notification comes to that address; the forwarder checks `HHH`, a keyed hash only it can compute, and `TT`, a timestamp that limits validity to a few days or weeks, then decodes the original address and relays the bounce. The hash matters because a reversible but unsigned rewrite would let anyone use the forwarder to deliver mail to arbitrary addresses. SRS changes only the envelope: the `From` header is untouched, and the `pass` vouches for the forwarder, not for example.com.

code

ini · 5 lines
ini
# Postfix main.cf: hand envelope addresses to a local SRS service
sender_canonical_maps = socketmap:unix:srs:forward
sender_canonical_classes = envelope_sender
recipient_canonical_maps = socketmap:unix:srs:reverse
recipient_canonical_classes = envelope_recipient, header_recipient

go deeper

for a junior

Recall that SRS swaps the envelope sender for an address in the forwarder's domain that still encodes the original sender, so bounces can find their way back.

for a middle

Explain the SRS0 fields, which domain the next receiver now checks, and how a returning bounce is decoded and relayed to the original sender.

for a senior

Show deployment judgment: why the hash and timestamp exist, rewriting only the envelope sender in Postfix, publishing SPF for the SRS domain and handling the secret.

for a principal

Decide whether your forwarding service should rewrite at all, against rejecting or narrowing forwarding, weighing bounce handling, secret custody and what the pass no longer proves.

## The problem SRS solves An SPF check (RFC 7208) asks whether the connecting host may use the domain in `MAIL FROM`. A plain forwarder resends a message from its own IP address but keeps the original envelope sender, so the final receiver checks the original domain's record, which does not list the forwarder, and gets `fail` or `softfail`. RFC 7208 Appendix D suggests that a mediator can solve this by rewriting `MAIL FROM` into its own domain, provided mail rejected later is routed back to the original sender. The **Sender Rewriting Scheme** (SRS) is the published design for doing that safely. It comes from a design paper dated June 2004; it has **no RFC**. The paper scopes it to servers that forward mail from domains whose SPF record does not cover them, such as servers honouring per-user forwarding files and third-party forwarding services. ## The SRS0 address, field by field The paper defines the first-hop form as `SRS0=HHH=TT=orig-domain=orig-local-part@domain-part`. For [email protected] forwarded by the university's alumni service it looks like `[email protected]`. | Field | Meaning | |---|---| | `SRS0` | Tag marking the address as an SRS address; the `0` acts as a version number | | `HHH` | A cryptographic hash over the timestamp, original domain and original local-part, keyed with a secret only the forwarder holds | | `TT` | A timestamp limiting how long the address is valid; the paper expects bounces within a few days, at most a month | | `example.com` | The original sender's domain | | `alice` | The original sender's local-part | | `@alumni.example.org` | The forwarder's own domain, which is what SPF now checks | The `=` separator was chosen because it does not normally appear in host names or in base64. The paper recommends an HMAC based on SHA-1, base64-encoded and truncated; its reference implementation uses four characters, 24 bits, which it calls probably a good minimum. ## What happens on each path 1. **Forward path.** The forwarder accepts mail for `[email protected]` with `MAIL FROM:<[email protected]>`, rewrites the envelope sender to the SRS0 address, and delivers to `[email protected]`. example.net checks the record for alumni.example.org against the forwarder's IP and gets `pass`, provided that record authorizes the forwarder. 2. **Bounce path.** If a later hop cannot deliver, its notification goes, with a null sender, to the SRS0 address. The forwarder recomputes the hash, checks the timestamp, rewrites the recipient back to `[email protected]` and relays the bounce. 3. **Invalid address.** If the hash does not verify or the timestamp is too old, the address is forged or expired and the forwarder refuses it. ## Why the address is signed The simplest reversible scheme, `[email protected]`, works for honest bounces, but anyone could send mail to such an address and the forwarder would deliver it to whatever address it encodes. That turns the forwarder into a restricted **open relay**. The keyed hash stops anyone but the forwarder from constructing a valid address, and the timestamp limits how long a harvested one stays usable. Both are needed: the hash cannot be recomputed without the secret, and the timestamp cannot be altered without breaking the hash. ## A second forwarder: SRS1 If mail passes through a second SRS forwarder, wrapping the SRS0 address again would make it grow with every hop. Instead the second forwarder writes an **SRS1** address, such as `SRS1=HHH=alumni.example.org==HHH=TT=example.com=alice@relay.example.net`, which sends bounces straight back to the first forwarder. It carries its own hash so it cannot be used as a relay either. The paper keeps the SRS1 format rigid because other administrators' servers must interpret it. ## Deploying it, with Postfix as the reference MTA - **Postfix itself has no SRS setting.** An external SRS service is attached through the cleanup daemon's canonical maps: `sender_canonical_maps` for the forward rewrite and `recipient_canonical_maps` for the reverse path. - **Rewrite only the envelope sender.** Postfix's `sender_canonical_classes` defaults to `envelope_sender, header_sender`; setting it to `envelope_sender` alone keeps the `From` header the reader sees untouched. - **Publish SPF for the SRS domain.** The rewritten domain must authorize the forwarder's outbound hosts, or the rewrite gains nothing. A dedicated SRS subdomain is simpler to manage than rewriting into each hosted domain. - **Rewrite only mail that leaves.** Local delivery needs no rewriting; one implementation skips it when every recipient is local. - **Guard the secret.** Every outstanding address is keyed with it, so simply discarding it invalidates SRS addresses still in flight and their bounces will be refused; a replacement has to keep validating the old secret until those addresses expire. ## What SRS does not do - It does not touch the `From` header, the DKIM signature or the content. - The resulting `pass` is for the forwarder's domain; it says nothing about whether example.com sent the message. - Whether that pass counts toward DMARC is a question of identifier alignment, covered with DMARC alignment; recording what the forwarder saw is a separate mechanism, covered with DMARC rollout.

  • Why does an SRS address carry a timestamp as well as a hash?
    The hash stops anyone from constructing a valid address, but a valid one could still be harvested from a real message and reused. The timestamp limits that window: the paper expects bounces within a few days, at most a month, and the forwarder refuses older addresses. The timestamp is covered by the hash, so it cannot be extended without the forwarder's secret.
  • After SRS, what does the final receiver's SPF pass actually tell it?
    Only that the forwarder's host is authorized for the forwarder's domain, now in `MAIL FROM`. It says nothing about whether the original domain sent the message, because that domain's record is no longer consulted. Evidence about the original sender has to come from something that survived the hop, such as an intact DKIM signature.
  • What breaks if the forwarder replaces its SRS secret?
    Every SRS address already sent out was hashed with the old secret. If that secret is simply discarded, bounces arriving for recent mail fail verification and are refused as forged, and their original senders never learn of the failure. A replacement therefore keeps validating with the old secret until addresses issued under it have expired.

  • SRS is defined in an RFC alongside SPF.
  • SRS rewrites the From header so the visible sender changes.
  • A reversible rewrite without a hash is safe enough for bounces.
  • After SRS the receiver still checks the original sender's SPF record.
  • An SPF pass after SRS proves the original domain sent the message.