skip to content

Why does the DKIM l= body-length tag let anyone handling a message append content that still verifies, and what should signers and verifiers do?

level: seniorimportance: must knowfreq 30%

answer

  1. counts octets, not the whole body
  2. measured after canonicalization
  3. nothing past N is covered
  4. l=0 signs no body
  5. extremely wary; might ignore

basics

~20 s

DKIM's l= tag limits the body hash to the first N canonicalized body octets, so anything after them is unsigned and can be added without breaking the signature. Signers should omit it; verifiers may treat such signatures as invalid.

solid answer

~40 s

`l=` is an optional count of body octets, measured after canonicalization, that the body hash in `bh=` covers; without it the whole body is signed. It was added so a list's appended trailer would not break signatures. The consequence is that every octet past the count is outside DKIM's protection, so any intermediary can add content and the signature still verifies; `l=0` leaves the body completely unsigned. RFC 6376 section 8.2 warns that appended content can replace the original in the reader's eyes and defeat duplicate detection, says signers should be extremely wary of the tag, and that assessors might wish to ignore signatures that use it. Section 6.1.3 lets verifiers treat unsigned trailing content as making the signature invalid. Signers should not set `l=`; RFC 6377 discourages it for lists too.

code

pseudocode · 11 lines
pseudocode
canon = canonicalize_body(body, c_body)       # simple or relaxed, from c=
if sig.has("l"):
    signed   = canon[0 : sig.l]               # first l octets only
    unsigned = canon[sig.l : ]                # never covered by bh=
else:
    signed   = canon
    unsigned = ""
if base64(hash(signed)) != sig.bh:
    return PERMFAIL("body hash did not verify")
if unsigned != "" and local_policy.distrust_body_length:
    return PERMFAIL("unsigned content")       # optional per RFC 6376 6.1.3

go deeper

for a junior

Recall that l= limits how many body octets the signature covers, and that whatever comes after that count is not signed.

for a middle

Explain that the count is taken after canonicalization, that l=0 signs no body at all, and why the tag was introduced for list trailers.

for a senior

Show the defensive response: audit outbound signatures for l=, remove it from signers, and know verifiers may treat trailing unsigned content as invalid.

for a principal

Set a domain-wide rule that no signer or outside sending service uses l=, and accept list breakage rather than signing partial bodies.

## What l= is DKIM's body hash, carried in the `bh=` tag of the `DKIM-Signature` field, normally covers the whole canonicalized body. RFC 6376 (September 2011) section 3.5 defines an optional **`l=` body length count**: an unsigned decimal number of octets, counted from the first octet after the CRLF that ends the header block, that the hash covers instead. Three rules define it precisely: - The count is taken **after canonicalization**. Section 5.3.1 says whitespace ignored by the canonicalization algorithm is not counted, so the same message can give different counts under `simple` and `relaxed` bodies. - The value MUST NOT be larger than the actual number of octets in the canonicalized body. - **`l=0`** means the body is completely unsigned. The informative rationale in section 5.3.1 is mailing lists: they commonly append trailers such as unsubscribe instructions, and a body length count let a verifier accept, as a matter of policy, a validly signed message carrying extra data at the end. ## Why it lets anyone append content The verifier hashes the canonical body truncated to `l=` octets and compares that with `bh=`. Octets beyond the count are never hashed, so DKIM says nothing about them: whoever handles the message after signing can add content after the counted part and the signature still verifies. Section 6.1.3 states it directly: all data beyond that limit is not validated by DKIM. The danger is that the result looks fully authenticated. RFC 6376 section 8.2 warns that `l=` "might allow display of fraudulent content without appropriate warning to end users", that the appended content can completely replace the original content in the recipient's eyes, and that it can defeat duplicate-message detection; it names MIME structure and lax HTML rendering in mail clients as what makes that possible. RFC 4686 (September 2006), the DKIM threat analysis, adds that the size of the appended content makes little difference, since a short reference can point elsewhere. The protection the domain thinks its signature provides covers only the counted prefix. ## What signers should do 1. **Do not set `l=`.** Section 8.2 says signers should be extremely wary of the tag. Section 5.4.1 says that unless mail passes through intermediaries such as lists, `l=` is likely to convey no additional benefit while providing an avenue for unauthorised addition of text, and calls `l=0` the extreme case. 2. **Do not use it to survive lists.** RFC 6377 (September 2011), the best current practice on DKIM and mailing lists, says `l=` is not workable for MIME messages, has security considerations, and that its use is discouraged. 3. **Audit what is actually sent.** Read the `DKIM-Signature` field on sample outbound mail from every signing system and outside sending service; the presence of an `l=` tag is visible to anyone. 4. **For maximum integrity**, section 5.3.1 says signers wishing to ensure that no modification of any sort can occur should use `simple` for header and body and omit the body length count. ## What verifiers and receivers can do RFC 6376 leaves the response to local policy, at permissive strength: - Section 6.1.3: verifiers might treat a message with bytes beyond the indicated length **with suspicion** and can choose to treat the signature as if it were invalid, for example by returning PERMFAIL with "unsigned content". - Section 8.2: assessors might wish to **ignore** signatures that use the tag. - RFC 4686 section 4.1.9 lists the options as ignoring the limit (hashing the whole body, so any addition fails the check), verifying only the counted portion, or truncating the message to the signed portion; it adds that receiving clients can at a minimum identify the unsigned content. | Verifier policy for `l=` | Effect on appended content | |---|---| | Honour it and report a pass | unsigned content arrives looking authenticated | | Honour it but flag unsigned content | reader and filters know what is unsigned | | Treat trailing unsigned content as invalid | signature fails; content gets no DKIM credit | | Ignore `l=` and hash the full body | any addition fails the body hash | What a failed or discounted signature then means for the message's overall verdict belongs to the material on signature verification and on DMARC.

  • Is the l= count measured on the raw body or the canonicalized body?
    On the canonicalized body. RFC 6376 section 5.3.1 says the count MUST be calculated after canonicalization, so whitespace a relaxed body ignores is not counted, and section 3.5 says the value MUST NOT exceed the canonicalized body's length.
  • Why does RFC 6377 reject l= even for the mailing lists it was designed for?
    RFC 6377, the best current practice on DKIM and mailing lists, says l= is not workable for MIME messages and carries security considerations, and therefore discourages its use. Lists that change bodies are expected to break signatures; accommodating them is handled outside the signer's settings.
  • As a security engineer reviewing a domain, how do you find out whether its mail uses l=?
    Read the DKIM-Signature field on real outbound samples from every system and outside service that signs for the domain; the l= tag is in clear text. Compare its value with the canonical body length to see how much of the body is unsigned.

A notary stamps a certificate saying "pages 1 to 3 of this contract are authentic". Anyone can staple a page 4 on afterwards and the stamp still checks out, because it never covered page 4; only a reader who counts pages notices.

  • l= is a safe, recommended way to survive mailing-list footers.
  • l=0 means no limit, so the whole body is signed.
  • The l= count is taken on the raw body before canonicalization.
  • A verifier must report a full pass whenever the counted octets match bh=.
  • Content appended after the l= count breaks the body hash.