Browse Source

[Rules] Improve MULTIPLE_UNIQUE_HEADERS rule

tags/1.7.9
Vsevolod Stakhov 5 years ago
parent
commit
18af41ce00
1 changed files with 24 additions and 20 deletions
  1. 24
    20
      rules/headers_checks.lua

+ 24
- 20
rules/headers_checks.lua View File

@@ -217,7 +217,7 @@ local check_replyto_id = rspamd_config:register_callback_symbol('CHECK_REPLYTO',
elseif from[1].domain and rt[1].domain then
if (util.strequal_caseless(from[1].domain, rt[1].domain)) then
task:insert_result('REPLYTO_DOM_EQ_FROM_DOM', 1.0)
else
else
-- See if Reply-To matches the To address
local to = task:get_recipients(2)
if (to and to[1] and to[1].addr:lower() == rt[1].addr:lower()) then
@@ -225,7 +225,7 @@ local check_replyto_id = rspamd_config:register_callback_symbol('CHECK_REPLYTO',
if (not (task:get_header('List-Unsubscribe') or
task:get_header('X-To-Get-Off-This-List') or
task:get_header('X-List') or
task:get_header('Auto-Submitted')))
task:get_header('Auto-Submitted')))
then
task:insert_result('REPLYTO_EQ_TO_ADDR', 1.0)
end
@@ -504,44 +504,48 @@ rspamd_config.HEADER_FORGED_MDN = {
}

local headers_unique = {
'Content-Type',
'Content-Transfer-Encoding',
['Content-Type'] = 1.0,
['Content-Transfer-Encoding'] = 1.0,
-- https://tools.ietf.org/html/rfc5322#section-3.6
'Date',
'From',
'Sender',
'Reply-To',
'To',
'Cc',
'Bcc',
'Message-ID',
'In-Reply-To',
'References',
'Subject'
['Date'] = 1.0,
['From'] = 1.0,
['Sender'] = 1.0,
['Reply-To'] = 1.0,
['To'] = 0.2,
['Cc'] = 0.1,
['Bcc'] = 0.1,
['Message-ID'] = 0.7,
['In-Reply-To'] = 0.7,
['References'] = 0.3,
['Subject'] = 0.7
}

rspamd_config.MULTIPLE_UNIQUE_HEADERS = {
callback = function(task)
local res = 0
local max_mult = 0.0
local res_tbl = {}

for _,hdr in ipairs(headers_unique) do
local h = task:get_header_full(hdr)
for hdr,mult in pairs(headers_unique) do
local hc = task:get_header_count(hdr)

if h and #h > 1 then
if hc > 1 then
res = res + 1
table.insert(res_tbl, hdr)
if max_mult < mult then
max_mult = mult
end
end
end

if res > 0 then
return true,res,table.concat(res_tbl, ',')
return true,max_mult,table.concat(res_tbl, ',')
end

return false
end,

score = 5.0,
score = 7.0,
group = 'headers',
one_shot = true,
description = 'Repeated unique headers'

Loading…
Cancel
Save