aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2022-03-10 21:18:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2022-03-10 21:30:05 +0000
commitcab96bb04a97534833888de2b60eb1d06d70dfcd (patch)
tree13638e3df1c6234c67f9ff8cdda84eeb714c66f6
parent67470931229eda9003de0911ba875e47321c5466 (diff)
downloadrspamd-cab96bb04a97534833888de2b60eb1d06d70dfcd.tar.gz
rspamd-cab96bb04a97534833888de2b60eb1d06d70dfcd.zip
[Fix] Properly find the request and the number of requested entries
Issue: #4100
-rw-r--r--src/plugins/lua/reputation.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua
index 2cb8f99e8..52c6c8ee7 100644
--- a/src/plugins/lua/reputation.lua
+++ b/src/plugins/lua/reputation.lua
@@ -157,25 +157,41 @@ end
local function dkim_reputation_filter(task, rule)
local requests = gen_dkim_queries(task, rule)
local results = {}
- local nchecked = 0
+ local dkim_tlds = lua_util.keys(requests)
+ local requests_left = #dkim_tlds
local rep_accepted = 0.0
local rep_rejected = 0.0
lua_util.debugm(N, task, 'dkim reputation tokens: %s', requests)
local function tokens_cb(err, token, values)
- nchecked = nchecked + 1
+ requests_left = requests_left - 1
if values then
results[token] = values
end
- if nchecked == #requests then
+ if requests_left == 0 then
for k,v in pairs(results) do
- if requests[k] == 'a' then
- rep_accepted = rep_accepted + generic_reputation_calc(v, rule, 1.0, task)
- elseif requests[k] == 'r' then
- rep_rejected = rep_rejected + generic_reputation_calc(v, rule, 1.0, task)
+ -- `k` in results is a prefixed and suffixed tld, so we need to look through
+ -- all requests to find any request with the matching tld
+ local sel_tld
+ for _,tld in ipairs(dkim_tlds) do
+ if k:find(tld) then
+ sel_tld = tld
+ break
+ end
+ end
+
+ if sel_tld and requests[sel_tld] then
+ if requests[sel_tld] == 'a' then
+ rep_accepted = rep_accepted + generic_reputation_calc(v, rule, 1.0, task)
+ elseif requests[sel_tld] == 'r' then
+ rep_rejected = rep_rejected + generic_reputation_calc(v, rule, 1.0, task)
+ end
+ else
+ rspamd_logger.warnx(task, "cannot find the requested tld for a request: %s (%s tlds noticed)",
+ k, dkim_tlds)
end
end