diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-10 21:29:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-10 21:30:05 +0000 |
commit | 6b6c4af8dc90b38592ab0268aa2a3e66e1d8aa1f (patch) | |
tree | 8e3214b53315d5fe3123ed0f3d8a52bb47374a1d /src | |
parent | cab96bb04a97534833888de2b60eb1d06d70dfcd (diff) | |
download | rspamd-6b6c4af8dc90b38592ab0268aa2a3e66e1d8aa1f.tar.gz rspamd-6b6c4af8dc90b38592ab0268aa2a3e66e1d8aa1f.zip |
[Fix] Apply the similar fix to the url_reputation
Issue: #4100
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/reputation.lua | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua index 52c6c8ee7..01c81d481 100644 --- a/src/plugins/lua/reputation.lua +++ b/src/plugins/lua/reputation.lua @@ -302,30 +302,53 @@ end local function url_reputation_filter(task, rule) local requests = gen_url_queries(task, rule) + local url_keys = lua_util.keys(requests) + local requests_left = #url_keys local results = {} - local nchecked = 0 local function indexed_tokens_cb(err, index, values) - nchecked = nchecked + 1 + requests_left = requests_left - 1 if values then results[index] = values end - if nchecked == #requests then + if requests_left == 0 then -- Check the url with maximum hits local mhits = 0 + + local result_request_match_tbl = {} + -- XXX: ugly O(N^2) loop to match requests and responses + for result_k,_ in pairs(results) do + for _, request_k in ipairs(url_keys) do + if result_k:find(request_k) then + result_request_match_tbl[result_k] = request_k + break + end + end + end + for k,_ in pairs(results) do - if requests[k][2] > mhits then - mhits = requests[k][2] + local req = result_request_match_tbl[k] + if req then + if requests[req] > mhits then + mhits = requests[req][2] + else + rspamd_logger.warnx(task, "cannot find the requested response for a request: %s (%s requests noticed)", + k, url_keys) + end end end if mhits > 0 then local score = 0 for k,v in pairs(results) do - score = score + generic_reputation_calc(v, rule, - requests[k][2] / mhits, task) + local req = result_request_match_tbl[k] + if req then + score = score + generic_reputation_calc(v, rule, + requests[req][2] / mhits, task) + + end end if math.abs(score) > 1e-3 then |