]> source.dussan.org Git - rspamd.git/commitdiff
Add `strict_protocol_headers` option for rspamc protocol.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Jan 2014 16:02:27 +0000 (16:02 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Jan 2014 16:02:27 +0000 (16:02 +0000)
If this option is specified then unknown headers are treated as errors
otherwise they are just ignored. This option is `false` by default meaning
that unknown headers are ignored.

src/cfg_file.h
src/cfg_rcl.c
src/protocol.c

index 41c37bd34439d4b9d5d8ae94607b97d5378cede4..55ced8456108f2cc34bea544998c141db7f8d29d 100644 (file)
@@ -292,6 +292,7 @@ struct config_file {
        gboolean one_shot_mode;                                                 /**< rules add only one symbol                                                  */
        gboolean check_text_attachements;                               /**< check text attachements as text                                    */
        gboolean convert_config;                                                /**< convert config to XML format                                               */
+       gboolean strict_protocol_headers;                               /**< strictly check protocol headers                                    */
 
        gsize max_diff;                                                                 /**< maximum diff size for text parts                                   */
 
index e8cb668009851bd95588482a4bddb0f4b5a9b05a..188bd331531ef3f644bab5b5d3f4b0464c81c22a 100644 (file)
@@ -1063,6 +1063,8 @@ rspamd_rcl_config_init (void)
                        G_STRUCT_OFFSET (struct config_file, history_file), RSPAMD_CL_FLAG_STRING_PATH);
        rspamd_rcl_add_default_handler (sub, "use_mlock", rspamd_rcl_parse_struct_boolean,
                        G_STRUCT_OFFSET (struct config_file, mlock_statfile_pool), 0);
+       rspamd_rcl_add_default_handler (sub, "strict_protocol_headers", rspamd_rcl_parse_struct_boolean,
+                       G_STRUCT_OFFSET (struct config_file, strict_protocol_headers), 0);
 
        /**
         * Metric section
index 6cb0ce677202dca57823e2688f5e0a2853e6cbfd..07d7072ab653c9f4bed746c64d278c28cf4a251e 100644 (file)
@@ -488,7 +488,7 @@ parse_header (struct worker_task *task, f_str_t * line)
                }
                else {
                        msg_info ("wrong header: %s", headern);
-                       return FALSE;
+                       res = FALSE;
                }
                break;
        case 'd':
@@ -583,7 +583,7 @@ parse_header (struct worker_task *task, f_str_t * line)
                                        task->from_addr.ipv6 = TRUE;
                                }
                                else {
-                                       msg_info ("bad ip header: '%s'", tmp);
+                                       msg_err ("bad ip header: '%s'", tmp);
                                        return FALSE;
                                }
                                task->from_addr.has_addr = TRUE;
@@ -595,7 +595,7 @@ parse_header (struct worker_task *task, f_str_t * line)
                                                task->from_addr.ipv6 = TRUE;
                                        }
                                        else {
-                                               msg_info ("bad ip header: '%s'", tmp);
+                                               msg_err ("bad ip header: '%s'", tmp);
                                                return FALSE;
                                        }
                                }
@@ -606,7 +606,7 @@ parse_header (struct worker_task *task, f_str_t * line)
                        }
 #else
                        if (!inet_aton (tmp, &task->from_addr)) {
-                               msg_info ("bad ip header: '%s'", tmp);
+                               msg_err ("bad ip header: '%s'", tmp);
                                return FALSE;
                        }
 #endif
@@ -652,13 +652,17 @@ parse_header (struct worker_task *task, f_str_t * line)
                }
                break;
        default:
-               if (!task->is_http) {
-                       msg_info ("wrong header: %s", headern);
-                       res = FALSE;
-               }
+               msg_info ("wrong header: %s", headern);
+               res = FALSE;
+               break;
        }
 
-       return res || task->is_http;
+       if (!res && task->cfg->strict_protocol_headers) {
+               msg_err ("deny processing of a request with incorrect or unknown headers");
+               return FALSE;
+       }
+
+       return TRUE;
 }
 
 gboolean