]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix DKIM forgeries via multiple headers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 2 Oct 2017 19:49:25 +0000 (20:49 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 17 Oct 2017 22:26:15 +0000 (00:26 +0200)
MFH: rspamd-1.6
URL: http://noxxi.de/research/breaking-dkim-on-purpose-and-by-chance.html

src/libserver/dkim.c

index 72cc7232f74324dc2bec2b84ad656a5fcffe0537..2b53571451ef9c6e2e08d26f260b9d58d7bfce88 100644 (file)
@@ -1938,6 +1938,22 @@ rspamd_dkim_canonize_header (struct rspamd_dkim_common_ctx *ctx,
                ar = g_hash_table_lookup (task->raw_headers, header_name);
 
                if (ar) {
+                       /* Check uniqueness of the header */
+                       rh = g_ptr_array_index (ar, 0);
+                       if ((rh->type & RSPAMD_HEADER_UNIQUE) && ar->len > 1) {
+                               guint64 random_cookie = ottery_rand_uint64 ();
+
+                               msg_warn_dkim ("header %s is intended to be unique by"
+                                               " email standards, but we have %d headers of this"
+                                               " type, artificially break DKIM check", header_name,
+                                               ar->len);
+                               rspamd_dkim_hash_update (ctx->headers_hash,
+                                               (const gchar *)&random_cookie,
+                                               sizeof (random_cookie));
+
+                               return FALSE;
+                       }
+
                        if (ar->len > count) {
                                /* Set skip count */
                                rh_num = ar->len - count - 1;