diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-01 16:11:45 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-01 16:11:45 +0100 |
commit | 8b14fbab1e094fe8db43ce83afeea52bf83b7dc5 (patch) | |
tree | 2444ce7fce664259a1f0d6bac0edd4a8a78a3312 /src | |
parent | 66394a369f95e83bec1646f73bebccd106858bb2 (diff) | |
download | rspamd-8b14fbab1e094fe8db43ce83afeea52bf83b7dc5.tar.gz rspamd-8b14fbab1e094fe8db43ce83afeea52bf83b7dc5.zip |
[Feature] Skip updates for messages scanned via controller
Rationale: controller worker is not designed to perform scan jobs,
hence, we check for `Password` header or check `User-Agent` for `rspamc`
and skip some of rules parts:
- DMARC reports
- Greylisting
- Ratelimits
- Ip score update
- Clickhouse export
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/clickhouse.lua | 2 | ||||
-rw-r--r-- | src/plugins/lua/dmarc.lua | 5 | ||||
-rw-r--r-- | src/plugins/lua/greylist.lua | 9 | ||||
-rw-r--r-- | src/plugins/lua/ip_score.lua | 2 | ||||
-rw-r--r-- | src/plugins/lua/ratelimit.lua | 3 |
5 files changed, 14 insertions, 7 deletions
diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index baee79ca7..eb4ad57b7 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -16,6 +16,7 @@ limitations under the License. local rspamd_logger = require 'rspamd_logger' local rspamd_http = require "rspamd_http" +local rspamd_lua_utils = require "lua_util" if confighelp then return @@ -345,6 +346,7 @@ local function clickhouse_quote(str) end local function clickhouse_collect(task) + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end local from_domain = '' local from_user = '' if task:has_from('smtp') then diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index 02dc0bb97..10aa95589 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -197,11 +197,14 @@ end local dmarc_grammar = gen_dmarc_grammar() -local function dmarc_report(task, spf_ok, dkim_ok, disposition, sampled_out, hfromdom, spfdom, dres, spf_result) +local function dmarc_report(task, spf_ok, dkim_ok, disposition, + sampled_out, hfromdom, spfdom, dres, spf_result) local ip = task:get_from_ip() if not ip:is_valid() then return nil end + local rspamd_lua_utils = require "lua_util" + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end local dkim_pass = table.concat(dres.pass or E, '|') local dkim_fail = table.concat(dres.fail or E, '|') local dkim_temperror = table.concat(dres.temperror or E, '|') diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index 424cf5509..586661d44 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -62,6 +62,7 @@ local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" local fun = require "fun" local hash = require "rspamd_cryptobox_hash" +local rspamd_lua_utils = require "lua_util" local function data_key(task) local cached = task:get_mempool():get_variable("grey_bodyhash") @@ -206,9 +207,7 @@ local function greylist_check(task) end_time, type) task:insert_result(settings['symbol'], 0.0, 'greylisted', end_time) - local ua = task:get_request_header('User-Agent') or '' - if tostring(ua) == 'rspamc' then return end -- Likely rspamc scan - + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end if settings.message_func then task:set_pre_result('soft reject', settings.message_func(task, end_time)) @@ -310,9 +309,7 @@ local function greylist_set(task) end end - local ua = task:get_request_header('User-Agent') or '' - local is_rspamc = false - if tostring(ua) == 'rspamc' then is_rspamc = true end + local is_rspamc = rspamd_lua_utils.is_rspamc_or_controller(task) if is_whitelisted then if action == 'greylist' then diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index a1a88d4b2..879aff74c 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -22,6 +22,7 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_regexp = require "rspamd_regexp" local rspamd_util = require "rspamd_util" +local rspamd_lua_utils = require "lua_util" -- Default settings local redis_params = nil @@ -96,6 +97,7 @@ end -- Set score based on metric's action local ip_score_set = function(task) + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end local function new_score_set(score, old_score, old_total) local new_total if old_total == -1 or old_total ~= old_total then diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 02e9d4d6f..beb9eb283 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -48,6 +48,7 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" +local rspamd_lua_utils = require "lua_util" local fun = require "fun" local user_keywords = {'user'} @@ -545,6 +546,7 @@ end --- Check limit local function rate_test(task) + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end rate_test_set(task, check_limits) end --- Update limit @@ -552,6 +554,7 @@ local function rate_set(task) local action = task:get_metric_action('default') if action ~= 'soft reject' then + if rspamd_lua_utils.is_rspamc_or_controller(task) then return end rate_test_set(task, set_limits) end end |