Why do DKIM signers list From twice in h=, as in h=from:from:..., when the message carries only one From header field?
answer
- count names, not fields
- instances picked from the bottom up
- a missing instance hashes as nothing
- once more than the count present
basics
~20 sListing From one more time than it occurs makes the extra h= entry hash an absent field as nothing; if another From is added later, that entry now picks it up, the header hash changes and the DKIM signature fails.
solid answer
~50 sA verifier selects header instances for `h=` from the bottom of the header block upward, and an `h=` entry with no instance left contributes nothing. With plain `h=from`, a second `From` added above the signed one is never selected, so the signature still verifies while the message now carries two author fields, and RFC 6376 Section 8.15 notes that some software displays only the first. Listing `from` twice means the second entry hashes as empty at signing time; once a copy is added, that entry selects it and verification fails. RFC 6376 says one extra listing is enough to block any number of additions. The same treatment suits other fields the reader relies on, such as `Subject`, `Date`, `To` and `Reply-To`, with the cost that a legitimate intermediary adding one of them breaks the signature.
code
pseudocode · 12 lines# header selection for h=from:from (RFC 6376 5.4.2)
from_fields = all From fields, last in the header block first
for entry in ["from", "from"]:
field = next unused field in from_fields, or NONE
if field is NONE:
hash nothing for this entry
else:
hash canonicalize(field) + CRLF
# at signing: entry 1 = original, entry 2 = NONE
# copy added above it: entry 1 = original, entry 2 = added copy
# -> header hash differs -> b= no longer verifiesgo deeper
Recall that a name listed in h= for a field that is not there hashes as nothing, and that listing From once more than it occurs blocks added copies.
Explain bottom-up instance selection and the null rule, and show with a two-From example why h=from alone still verifies after an addition.
Pick which fields to over-sign for real mail flows and name the paths, such as lists and gateways that add fields, where over-signing will break legitimate mail.
Weigh strictness against reach: an over-signed field is a promise that nobody downstream adds it, and the lead decides which flows can keep that promise.
## The problem over-signing solves RFC 5322 allows exactly one `From` field, but many components accept malformed mail and quietly pick one instance to show. RFC 6376 (September 2011), Section 8.15, notes that some software shows only the first of multiple `From` fields. Section 8.15 also points out that an extra field can be added to a genuinely signed copy, in transit or when it is resent. The question for the signer is whether the signature still verifies after that addition. With a naive `h=` list, it can. ## How a verifier picks header instances Two rules in RFC 6376 decide what gets hashed: 1. **Bottom-up selection (Section 5.4.2).** When a name appears in `h=`, the physically last instance of that field is used first; a second occurrence of the name in `h=` takes the next instance up, and so on. 2. **Absent means null (Sections 3.5 and 5.4).** If `h=` names an instance that does not exist, it contributes nothing to the hash: no name, no colon, no value, no CRLF. Put together: | Signed with | Header block at verification | Entries hashed | Result | |---|---|---|---| | `h=from` | original `From` only | original | pass | | `h=from` | added `From` above the original | original | still passes | | `h=from:from` | original `From` only | original, then nothing | pass | | `h=from:from` | added `From` above the original | original, then the added copy | fails | In the second row the cryptography is correct and the message is malformed, and the signature vouches for it anyway. In the fourth row the signer has, in the RFC's words, given an explicit indication that it repudiates responsibility for such a malformed message. ## How many times to list a field Section 5.4 has an informative note: a header name only needs to be listed **once more than the number of instances present at signing** to prevent any further additions. One `Comments` field signed as `Comments` twice blocks any number of appended ones; listing it three or more times is legal but unnecessary. The same logic works for fields that are **absent** when signing. Listing `Reply-To` once, when the message has none, means a `Reply-To` added later is hashed where nothing was signed, and the signature fails. RFC 6376 describes this as a signer explicitly asserting the absence of a field. ## Which fields signers over-sign The candidates are fields that change what the reader sees or how a reply is routed: - `From`, the author, which RFC 6376 requires to be signed anyway. - `Subject` and `Date`, visible on every message. - `To`, `Cc` and `Reply-To`, which change who appears to be addressed and where replies go. - `Sender`, which names the agent sending on the author's behalf, and MIME fields such as `Content-Type`, which change how the body is rendered. The RFC 8463 example message (September 2018) over-signs `from`, `subject` and `date` in exactly this way. ## The cost Over-signing makes the signature intolerant of additions, and some additions are legitimate: - An intermediary that adds a field you over-signed, such as a list that inserts its own `Reply-To`, breaks your signature on that path. - Fields that relays add as a matter of course, `Received` above all, should not be over-signed or even signed; RFC 6376 lists `Received` among fields to exclude. - Fields that legitimately repeat are hard to over-sign safely, because any further legitimate instance breaks the signature. The decision is therefore per field: over-sign what a reader relies on and no intermediary on your normal mail paths should add. ## What over-signing does not do - It does not stop anyone from sending a message with two `From` fields; it makes sure your signature does not verify on one. - It does not detect changes to fields you never listed. - It is not a replay defence: a copy resent unchanged still verifies, which is covered with DKIM verification. - It cannot anticipate fields defined in the future, as RFC 6376's own note on `h=` admits.
- If a message has two Received fields and the signer wants both signed, how does h= express that?The name appears twice, `h=Received:Received`, and RFC 6376 Section 5.4.2 says the signer hashes the physically last instance first, then the one above it. In practice signers leave `Received` out, because relays add instances in transit.
- Does over-signing From prevent a receiver from accepting a message with two From fields?No. It only makes the signature fail on such a message, so the domain's signature no longer vouches for it. Whether the receiver then rejects, quarantines or delivers is the receiver's policy and the domain's DMARC policy, not the signer's.
- Why not over-sign every header field the message contains?Because some fields are legitimately added in transit. Over-signing `Received`, or a field a mailing list or gateway inserts, breaks the signature on ordinary paths. Over-sign the fields a reader relies on and that intermediaries on your normal paths should not add.
- Signing From once already stops any extra From field being added.
- Listing From twice is invalid because h= names must be unique.
- Over-signing needs the name listed three or more times to work.
- Over-signing Received is good practice because it detects tampering.
- Any change to the header block breaks b=, so over-signing is redundant.