commit 723e9e9: [Feature] Greylist: Allow to disable greylisting depending on symbols

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Mar 18 17:56:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-03-18 17:53:16 +0000
URL: https://github.com/rspamd/rspamd/commit/723e9e963380dfa12d5b9e0f7b999535e4917e48 (HEAD -> master)

[Feature] Greylist: Allow to disable greylisting depending on symbols

---
 src/plugins/lua/greylist.lua | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index 5a1f6c0f9..1ba80dd80 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -44,7 +44,7 @@ end
 local redis_params
 local whitelisted_ip
 local whitelist_domains_map
-local toint =math.ifloor or math.floor
+local toint = math.ifloor or math.floor
 local settings = {
   expire = 86400, -- 1 day by default
   timeout = 300, -- 5 minutes by default
@@ -53,6 +53,7 @@ local settings = {
   message = 'Try again later', -- default greylisted message
   symbol = 'GREYLIST',
   action = 'soft reject', -- default greylisted action
+  whitelist_symbols = {}, -- whitelist when specific symbols have been found
   ipv4_mask = 19, -- Mask bits for ipv4
   ipv6_mask = 64, -- Mask bits for ipv6
   report_time = false, -- Tell when greylisting is epired (appended to `message`)
@@ -65,6 +66,7 @@ local rspamd_util = require "rspamd_util"
 local fun = require "fun"
 local hash = require "rspamd_cryptobox_hash"
 local rspamd_lua_utils = require "lua_util"
+local lua_map = require "lua_map"
 local N = "greylist"
 
 local function data_key(task)
@@ -276,6 +278,19 @@ local function greylist_set(task)
   -- Don't do anything if pre-result has been already set
   if task:has_pre_result() then return end
 
+  -- Check whitelist_symbols
+  for _,sym in ipairs(settings.whitelist_symbols) do
+    if task:has_symbol(sym) then
+      rspamd_logger.infox(task, 'skip greylisting as we have found symbol %s', sym)
+      if action == 'greylist' then
+        -- We are going to accept message
+        rspamd_logger.infox(task, 'downgrading metric action from "greylist" to "no action"')
+        task:disable_action('greylist')
+      end
+      return
+    end
+  end
+
   if settings.greylist_min_score then
     local score = task:get_metric_score('default')[1]
     if score < settings.greylist_min_score then
@@ -438,12 +453,12 @@ if opts then
     end
   end
 
-  whitelisted_ip = rspamd_map_add('greylist', 'whitelisted_ip', 'radix',
+  whitelisted_ip = lua_map.rspamd_map_add(N, 'whitelisted_ip', 'radix',
     'Greylist whitelist ip map')
-  whitelist_domains_map = rspamd_map_add('greylist', 'whitelist_domains_url',
+  whitelist_domains_map = lua_map.rspamd_map_add(N, 'whitelist_domains_url',
     'map', 'Greylist whitelist domains map')
 
-  redis_params = rspamd_parse_redis_server('greylist')
+  redis_params = rspamd_parse_redis_server(N)
   if not redis_params then
     rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
     rspamd_lua_utils.disable_module(N, "redis")


More information about the Commits mailing list