aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_cfg_transform.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-07 12:07:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-07 12:07:00 +0100
commit6fafe4f28872679bcf55bb7b9455bc03c04a61e8 (patch)
tree2b69ad3470626a086276c7e5fe0619a5635179f0 /lualib/lua_cfg_transform.lua
parent0c312c81f3009ae9b679c7739531181f7f8b4222 (diff)
downloadrspamd-6fafe4f28872679bcf55bb7b9455bc03c04a61e8.tar.gz
rspamd-6fafe4f28872679bcf55bb7b9455bc03c04a61e8.zip
[Feature] Add sanity checks for actions thresholds
Issue: #3506 Closes: #3506
Diffstat (limited to 'lualib/lua_cfg_transform.lua')
-rw-r--r--lualib/lua_cfg_transform.lua43
1 files changed, 35 insertions, 8 deletions
diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua
index 53c74da9e..9d85e4164 100644
--- a/lualib/lua_cfg_transform.lua
+++ b/lualib/lua_cfg_transform.lua
@@ -374,19 +374,16 @@ return function(cfg)
for _,d in ipairs(actions_defs) do
if cfg.actions[d] and type(cfg.actions[d]) == 'number' then
if cfg.actions[d] < 0 then
- cfg.actions['no action'] = cfg.actions[d] - 0.001
- logger.infox('set no action score to: %s, as action %s has negative score',
- cfg.actions['no action'], d)
+ cfg.actions['no_action'] = cfg.actions[d] - 0.001
+ logger.infox(rspamd_config, 'set no_action score to: %s, as action %s has negative score',
+ cfg.actions['no_action'], d)
break
end
end
end
end
- local actions_set = {}
- for _,d in ipairs(actions_defs) do
- actions_set[d] = true
- end
+ local actions_set = lua_util.list_to_hash(actions_defs)
-- Now check actions section for garbadge
actions_set['unknown_weight'] = true
@@ -395,7 +392,37 @@ return function(cfg)
for k,_ in pairs(cfg.actions) do
if not actions_set[k] then
- logger.warnx('unknown element in actions section: %s', k)
+ logger.warnx(rspamd_config, 'unknown element in actions section: %s', k)
+ end
+ end
+
+ -- Performs thresholds sanity
+ -- We exclude greylist here as it can be set to whatever threshold in practice
+ local actions_order = {
+ 'no_action',
+ 'add_header',
+ 'rewrite_subject',
+ 'quarantine',
+ 'reject',
+ 'discard'
+ }
+ for i=1,(#actions_order - 1) do
+ local act = actions_order[i]
+
+ if cfg.actions[act] and type(cfg.actions[act]) == 'number' then
+ local score = cfg.actions[act]
+
+ for j=i+1,#actions_order do
+ local next_act = actions_order[j]
+ if cfg.actions[next_act] and type(cfg.actions[next_act]) == 'number' then
+ local next_score = cfg.actions[next_act]
+ if next_score <= score then
+ logger.errx(rspamd_config, 'invalid actions thresholds order: action %s (%s) must have lower '..
+ 'score than action %s (%s)', act, score, next_act, next_score)
+ ret = false
+ end
+ end
+ end
end
end
end