DKIM and injected headers

If you look at the DKIM-Signature header in any piece of email signed with DKIM you’ll see that one of the fields it contains, the h= field, lists some email header names, for example:

h=From:Subject:Date:To:MIME-Version:Content-Type

Those are the headers that were signed when the mail was sent, and they’re the only headers that will be checked by the DKIM validator. There are some header fields that can occur multiple times, but they’re seldom ones that you’d be interested in signing (if you ever are, check out the DKIM RFC for the details of how that works).
Yesterday I talked about DKIM replay attacks, how replayed messages looked a little odd and had bad To: headers, and mentioned that header duplication might be a problem. You can’t modify a signed header without breaking the DKIM signature – but what happens if someone takes your signed message, adds a new Subject: or To: header in addition to the existing one, and then sends it on to a new set of recipients?
RFC 5322 says that you can’t have multiple Subject or To headers, but violating specifications is where protocol attacks usually get interesting. If the attacker is careful, they can add a second Subject: header and some DKIM validation code will consider the resulting (invalid) message to still be validly signed – the signature says it’s signed one Subject header, and there’s one Subject header that hasn’t changed, so that one validates.
What will be displayed to the end user, if there are multiple Subjects? That’s undefined behaviour – the message is violating email standards, so the MUA could do anything and still be within spec. It could legitimately halt, play La Marseillaise, electrocute the user and then catch fire. More likely, it’ll display one of the two Subject fields – most likely it’ll predictably show either the first one or the last one.
If you’re an attacker trying to hijack someone else’s reputation by replaying signed mail this is a wonderful opportunity – it means that you’re potentially able to replay signed mail, displaying modified To: and Subject: fields to the final recipients, avoiding the red flag of having the recipient not be in the To: field. It might only work reliably for some MUAs, but even if it just worked at Yahoo or Gmail or Hotmail it’d be worth doing.
DKIM has two, slightly opposing, views on what to do about this. The first one is more theoretical: DKIM is only defined for use with email messages, if there are two Subject: headers then it’s not an email message so it’s out of scope for DKIM to even have an opinion on the situation. The operational implication of that is that ISPs receiving should reject any email they receive that violates the email specs before their DKIM validator even looks at it – and it’s likely that ISPs who aren’t already doing this will start being stricter about what violations of RFC 5322 they will accept.
The second is more practical. DKIM allows you to “sign” that a header doesn’t exist – if you tell a DKIM signer to sign, for example, Reply-To: and there’s no Reply-To: field in the message when it’s signed then adding a Reply-To: field will break the signature. And DKIM allows you to sign a repeated header field, just by including it multiple times in the list of fields to sign.
We can combine these two features to enforce that there is only a single, unchanged copy of any given header. To do that, we just need to include the Subject (and To, and From, and maybe others) twice in the list of headers to sign. The first entry is to sign the content of the Subject: header, the second entry is to assert that there isn’t a second Subject: header.
So we’d change from

h=From:Subject:Date:To:MIME-Version:Content-Type

to

h=From:From:Subject:Subject:Date:To:To:MIME-Version:Content-Type

and then any attempt to add additional From:, Subject: or To: fields will break the signature. If you configure your DKIM signer to do that, you’re protected from having those fields tampered with. This is discussed in a bit more rigorous detail in the DKIM RFC.
ESP reputations are being attacked by this approach today. You should consider updating your DKIM signing (and locking down your evaluation accounts) fairly urgently. Don’t forget that these changes only apply to new mail you send out – they won’t prevent an attacker from replaying mail you’ve sent previously unless you rotate your DKIM keys.

Related Posts

A brief DMARC primer

DMARC stands for Domain-based Message Authentication, Reporting and Conformance. What DMARC does is allow domain owners to publish policy statements in DNS telling receiver domains what to do with messages that do not authenticate. In addition, DMARC introduces the concept of “domain alignment.” What this means is that the authentication has to be from the same domain (or a sub-domain) as the address in the header-from: line. The idea behind DMARC is that organizational owners can use SPF and DKIM authentication to authenticate their actual domain in the header-from line. This moves authentication from a important but behind the scenes technology out to an end user visible technology.

Read More

DMARC: Please Be Careful!

(Cross posted from Spam Resource.)
Every couple of days, somebody new pops up on the DMARC-Discuss mailing list to ask some question or share an observation. It’s great to see people interested and joining the conversation. Clearly, DMARC interest and adoption are growing. What’s really frustrating, though, is that for about a quarter of the new subscribers, their first mailing list message goes to the spam folder in my Gmail account. It has become sort of an intelligence test I apply to new subscribers — I’ve stopped digging those messages out of the spam folder. I’m figuring that if they can’t figure out how to implement a DMARC record, or they don’t understand that it’s not really compatible with mailing lists nor is it meant for hobbyist domains, then I think perhaps they’ve got some things they’ve got to figure out before they’re ready to join the discussion.
To that end, let me take a moment to jot down some recommendations for folks who are considering implementing DMARC.

Read More

Gmail sending out warnings for 512 bit DKIM keys

As an update to yesterday’s post, Gmail is contacting postmasters at domains signing with 512 bit keys to warn them of the upcoming changes. This message also clarifies “DKIM keys failing.” Messages signed with 512 bit keys or less will be treated as unsigned by Gmail in the next week or so.

Read More