{"code":200,"data":{"id":"ggxelwrgkv","slug":"gmails-non-compliant-dkim-verifier","appearance":"norm","language":"en","rtl":false,"created":"2026-11-04T17:25:00Z","updated":"2026-11-04T17:27:19Z","title":"Gmail's non-compliant DKIM verifier","body":"## The short version\n\nGmail fails to verify valid DKIM signatures when both of the following conditions are true:\n\n1. the DKIM-Signature header is folded right after `b=`, so the signature value starts on the next line, and\n2. the value is followed by a `;`, i.e. the header ends with `...==;`.\n\nThis perfectly valid DKIM signature fails at Gmail:\n\n```\n    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.org;\n    \ts=sel; h=From:To:Subject:Date:Message-ID; bh=...=; b=\n    \tQQH0CQIUShsLqiZt5ogRFg...\n    \t...BkOrlFyCm90Kxrk3tQcHPA==;\n```\n\nThese pass, even though they differ only in where the line break happens or if the last `;` is omitted:\n\n```\n    \ts=sel; h=From:To:Subject:Date:Message-ID; bh=...=; b=yWQqOWPUIZHdO    \t...Xt0M+hbzzbWUm1F/SOr9ztNinrNRaOtKvPvS6jqvwxBv1OLBsEnFceGvZ5hg==;\n```\n```\n    \ts=sel; h=From:To:Subject:Date:Message-ID; bh=...=; b=\n    \tQQH0CQIUShsLqiZt5ogRFg...\n    \t...BkOrlFyCm90Kxrk3tQcHPA==\n```\n\n[RFC 6376](https://www.rfc-editor.org/rfc/rfc6376) allows folding whitespace around the `=` of a tag ([section 3.2](https://www.rfc-editor.org/rfc/rfc6376#section-3.2)) and allows a `;` after the last tag. When a verifier computes the header hash, it must remove the `b=` value \"including all surrounding whitespace\" ([section 3.7](https://www.rfc-editor.org/rfc/rfc6376#section-3.7)). Compliant verifiers accept all three. Gmail doesn't.\n\n## How this came up\n\nHéctor at [Igalia](https://www.igalia.com/) contacted us a few weeks ago when he saw `dkim=fail` in DMARC reports from Google. It was for a subset of mail that reached Gmail through kernel.org list relays, but the failures were sporadic and without an easily discernible pattern. On our side, we use a set of distributed relays to deliver list messages, and the problem appeared to manifest itself at each one of them, seemingly at random.\n\nAfter a lot of back-and-forth, we eventually ruled out our relays and narrowed things down to how Igalia's MTA DKIM-signs their messages -- Exim folds the header at 78 columns, ending the signature with `;`. Under certain conditions this triggers the bug.\n\nWhether `b=` lands at the end of a line depends on the length of everything before it -- mostly the `h=` enumeration of headers that are being signed. It just so happens that the set of headers produced by git-send-email hits the exact length to cause the `b=` header wrapping, which is why the problem manifests itself when Igalia's developers send patches to the kernel.org mailing lists.\n\n## What Gmail probably does\n\nIt looks like Gmail removes the `b=` value that follows the `=`, but keeps the folding whitespace in front of it. After relaxed canonicalization, that becomes:\n\n```\n    ...; b= ;\n```\n\nwhile what the signer hashed was:\n\n```\n    ...; b=;\n```\nAs a result, the signature doesn't match. That trailing `;` in the original DKIM header is important, because without it, the leftover space ends up at the end of the header and gets trimmed, so the bug doesn't get triggered.\n\n## Corner case known since 2008\n\nIn his research, Héctor came across a similar bug filed with Exim -- the same `b= ;` vs. `b=;` already caused problems as far back as 2018 ([Exim bug 2278](https://bugs.exim.org/show_bug.cgi?id=2278)), and when I was running my own tests with dkimpy, I came across an interesting comment in its source code, committed in April 2012: apparently, some large receivers mishandle a folded `b=` value.\n\nFollowing the breadcrumbs of that commit, we find a mention of the [RFC 4871 erratum 1596](https://www.rfc-editor.org/errata/eid1596), describing **this exact situation** as far back as 2008. The updated DKIM spec, [RFC 6376](https://www.rfc-editor.org/rfc/rfc6376), includes specific wording to clarify and address it.\n\nI'm not sure if Gmail's DKIM implementation follows the pre-2011 spec or if this is merely a regression, but as things stand right now, Gmail can incorrectly reject or quarantine perfectly valid forwarded mail.\n\n## What you can do\n\nIf you work at Google, maybe poke someone on the Gmail team and show them this post?\n\nIf you're running Exim, you may want to consider doing what the Igalia folks did: they started adding a `t=` timestamp tag to their DKIM signatures, which moves `b=` away from the end of the line. It's not a guaranteed solution, but it appears to work in their case.\n\n## Acknowledgements\n\nMany thanks to Héctor, who did the hard work of finding the trigger and reproducing it.","tags":[],"paid":false,"views":1753,"likes":0}}