]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add `max_recipients` config knob
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 May 2020 16:18:43 +0000 (17:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 19 May 2020 16:18:43 +0000 (17:18 +0100)
conf/options.inc
src/libmime/email_addr.c
src/libmime/email_addr.h
src/libmime/mime_headers.c
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libserver/milter.c
src/libserver/protocol.c

index 8338a89cc7c23da4d33a71b04be4de67a65c6c8a..f305bcfcbf40e2939c5a60dd74b77bb84035ac53 100644 (file)
@@ -29,6 +29,7 @@ check_all_filters = false;
 dns_max_requests = 64;
 max_lua_urls = 1024;
 max_urls = 10240;
+max_recipients = 1024;
 
 dns {
     timeout = 1s;
index 1987c58c3da86e905c5acdf7f1c57964712fb75a..eaf44fc918273c22472852f24c432ed404a5fad3 100644 (file)
@@ -48,7 +48,7 @@ rspamd_email_address_unescape (struct rspamd_email_address *addr)
 }
 
 struct rspamd_email_address *
-rspamd_email_address_from_smtp (const gchar *str, guint len, gint max_elements)
+rspamd_email_address_from_smtp (const gchar *str, guint len)
 {
        struct rspamd_email_address addr, *ret;
        gsize nlen;
index 2452fc7aa564121bf45521090852cfa9653752a0..fe9fd9e9dadec1f566e5af19c7afedad401f9aac 100644 (file)
@@ -67,9 +67,7 @@ struct rspamd_task;
  * @param len length of string
  * @return
  */
-struct rspamd_email_address *rspamd_email_address_from_smtp (const gchar *str,
-               guint len,
-               gint max_elements);
+struct rspamd_email_address *rspamd_email_address_from_smtp (const gchar *str, guint len);
 
 /**
  * Parses email address from the mime header, decodes names and return the array
index 55d04d69a314d73b1fcf8758f300a7d9b6f29020..786d43a6ab72aec1b736b867109cf7f15e2865d6 100644 (file)
@@ -20,6 +20,7 @@
 #include "contrib/uthash/utlist.h"
 #include "libserver/mempool_vars_internal.h"
 #include "libserver/url.h"
+#include "libserver/cfg_file.h"
 #include "libutil/util.h"
 #include <unicode/utf8.h>
 
@@ -62,25 +63,25 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
        case 0x76F31A09F4352521ULL:     /* to */
                MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
                                rh->decoded, strlen (rh->decoded),
-                               MESSAGE_FIELD (task, rcpt_mime), -1);
+                               MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
                rh->flags |= RSPAMD_HEADER_TO|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
                break;
        case 0x7EB117C1480B76ULL:       /* cc */
                MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
                                rh->decoded, strlen (rh->decoded),
-                               MESSAGE_FIELD (task, rcpt_mime), -1);
+                               MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
                rh->flags |= RSPAMD_HEADER_CC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
                break;
        case 0xE4923E11C4989C8DULL:     /* bcc */
                MESSAGE_FIELD (task, rcpt_mime) = rspamd_email_address_from_mime (task->task_pool,
                                rh->decoded, strlen (rh->decoded),
-                               MESSAGE_FIELD (task, rcpt_mime), -1);
+                               MESSAGE_FIELD (task, rcpt_mime), task->cfg->max_recipients);
                rh->flags |= RSPAMD_HEADER_BCC|RSPAMD_HEADER_RCPT|RSPAMD_HEADER_UNIQUE;
                break;
        case 0x41E1985EDC1CBDE4ULL:     /* from */
                MESSAGE_FIELD (task, from_mime) = rspamd_email_address_from_mime (task->task_pool,
                                rh->decoded, strlen (rh->decoded),
-                               MESSAGE_FIELD (task, from_mime), -1);
+                               MESSAGE_FIELD (task, from_mime), task->cfg->max_recipients);
                rh->flags |= RSPAMD_HEADER_FROM|RSPAMD_HEADER_SENDER|RSPAMD_HEADER_UNIQUE;
                break;
        case 0x43A558FC7C240226ULL:     /* message-id */ {
@@ -129,7 +130,7 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
        case 0xEE4AA2EAAC61D6F4ULL:     /* return-path */
                if (task->from_envelope == NULL) {
                        task->from_envelope = rspamd_email_address_from_smtp (rh->decoded,
-                                       strlen (rh->decoded), -1);
+                                       strlen (rh->decoded));
                }
                rh->flags = RSPAMD_HEADER_RETURN_PATH|RSPAMD_HEADER_UNIQUE;
                break;
index 702325f627411f181f463173fdaac6fd8dad5348..5c6c682a1695caf43495d36d98be480d7a4ba229 100644 (file)
@@ -471,6 +471,7 @@ struct rspamd_config {
        guint full_gc_iters;                            /**< iterations between full gc cycle                                   */
        guint max_lua_urls;                             /**< maximum number of urls to be passed to Lua                 */
        guint max_urls;                                 /**< maximum number of urls to be processed in general  */
+       gint max_recipients;                           /**< maximum number of recipients to be processed        */
        guint max_blas_threads;                         /**< maximum threads for openblas when learning ANN             */
        guint max_opts_len;                             /**< maximum length for all options for a symbol                */
 
index dc568297bfb9030434a0e17e15c91ec208ad2367..885ebad4d600b9bdb5be32e4f8cc3cf4e6654060 100644 (file)
@@ -2240,6 +2240,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections)
                                G_STRUCT_OFFSET (struct rspamd_config, max_urls),
                                RSPAMD_CL_FLAG_INT_32,
                                "Maximum count of URLs to process to avoid DoS (default: 10240)");
+               rspamd_rcl_add_default_handler (sub,
+                               "max_recipients",
+                               rspamd_rcl_parse_struct_integer,
+                               G_STRUCT_OFFSET (struct rspamd_config, max_recipients),
+                               RSPAMD_CL_FLAG_INT_32,
+                               "Maximum count of recipients to process to avoid DoS (default: 1024)");
                rspamd_rcl_add_default_handler (sub,
                                "max_blas_threads",
                                rspamd_rcl_parse_struct_integer,
index d3ad9e21016fb02206c5b4ce7578c80d3f8ed028..6b3f3e15bfb36bec95a49d7f8833e2f3b203c4d6 100644 (file)
@@ -221,6 +221,7 @@ rspamd_config_new (enum rspamd_config_init_flags flags)
        cfg->cache_reload_time = 30.0;
        cfg->max_lua_urls = 1024;
        cfg->max_urls = cfg->max_lua_urls * 10;
+       cfg->max_recipients = 1024;
        cfg->max_blas_threads = 1;
        cfg->max_opts_len = 4096;
 
index 4713b737142e999fbf39ab93589cbec72c99fb8c..dc398912d0d3610f373cffbe70b845130ca82bcd 100644 (file)
@@ -603,7 +603,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
                                cpy = rspamd_mempool_alloc (priv->pool, zero - pos);
                                memcpy (cpy, pos, zero - pos);
                                msg_debug_milter ("got mail: %*s", (int)(zero - pos), cpy);
-                               addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
+                               addr = rspamd_email_address_from_smtp (cpy, zero - pos);
 
                                if (addr) {
                                        session->from = addr;
@@ -618,7 +618,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
                                /* That actually should not happen */
                                cpy = rspamd_mempool_alloc (priv->pool, end - pos);
                                memcpy (cpy, pos, end - pos);
-                               addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
+                               addr = rspamd_email_address_from_smtp (cpy, end - pos);
 
                                if (addr) {
                                        session->from = addr;
@@ -707,7 +707,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
                                memcpy (cpy, pos, end - pos);
 
                                msg_debug_milter ("got rcpt: %*s", (int)(zero - pos), cpy);
-                               addr = rspamd_email_address_from_smtp (cpy, zero - pos, -1);
+                               addr = rspamd_email_address_from_smtp (cpy, zero - pos);
 
                                if (addr) {
                                        if (!session->rcpts) {
@@ -726,7 +726,7 @@ rspamd_milter_process_command (struct rspamd_milter_session *session,
                                msg_debug_milter ("got weird rcpt: %*s", (int)(end - pos),
                                                pos);
                                /* That actually should not happen */
-                               addr = rspamd_email_address_from_smtp (cpy, end - pos, -1);
+                               addr = rspamd_email_address_from_smtp (cpy, end - pos);
 
                                if (addr) {
                                        if (!session->rcpts) {
index 1d51ff28fe5aab6a4f3b2deb2528d61783168d2f..9d127606409fb20d76c4ec480eb4acd53f372faa 100644 (file)
@@ -292,7 +292,7 @@ rspamd_protocol_process_recipients (struct rspamd_task *task,
                        else if (*p == ',' && start_addr != NULL && p > start_addr) {
                                /* We have finished address, check what we have */
                                addr = rspamd_email_address_from_smtp (start_addr,
-                                               p - start_addr, -1);
+                                               p - start_addr);
 
                                if (addr) {
                                        if (task->rcpt_envelope == NULL) {
@@ -322,7 +322,7 @@ rspamd_protocol_process_recipients (struct rspamd_task *task,
        if (start_addr && p > start_addr) {
                switch (state) {
                case normal_string:
-                       addr = rspamd_email_address_from_smtp (start_addr, end - start_addr, -1);
+                       addr = rspamd_email_address_from_smtp (start_addr, end - start_addr);
 
                        if (addr) {
                                if (task->rcpt_envelope == NULL) {
@@ -495,7 +495,7 @@ rspamd_protocol_handle_headers (struct rspamd_task *task,
                                IF_HEADER (FROM_HEADER) {
                                        task->from_envelope = rspamd_email_address_from_smtp (
                                                        hv_tok->begin,
-                                                       hv_tok->len, -1);
+                                                       hv_tok->len);
                                        msg_debug_protocol ("read from header, value: %T", hv_tok);
 
                                        if (!task->from_envelope) {