diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-07 12:09:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-07 12:09:04 +0100 |
commit | 6026ab965000eadb07de1d05ad334367f4f15e71 (patch) | |
tree | ed17eb97b131cb77743040e768aaef9ca28ded4c | |
parent | 6fafe4f28872679bcf55bb7b9455bc03c04a61e8 (diff) | |
parent | ce9394561d07edfb9ff14d5a7e3ece2722c24a24 (diff) | |
download | rspamd-6026ab965000eadb07de1d05ad334367f4f15e71.tar.gz rspamd-6026ab965000eadb07de1d05ad334367f4f15e71.zip |
Merge pull request #3510 from citrin/date-checks
Date checks
-rw-r--r-- | rules/misc.lua | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/rules/misc.lua b/rules/misc.lua index 88895c2b9..870952c94 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -55,51 +55,70 @@ rspamd_config.R_PARTS_DIFFER = { } -- Date issues -rspamd_config.MISSING_DATE = { +local date_id = rspamd_config:register_symbol({ + name = 'DATE_CB', + type = 'callback,mime', callback = function(task) - local date = task:get_header_raw('Date') - if date == nil or date == '' then - return true + local date_time = task:get_header('Date') + if date_time == nil or date_time == '' then + task:insert_result('MISSING_DATE', 1.0) + return end - return false - end, + + local dm, err = util.parse_smtp_date(date_time) + if err then + task:insert_result('INVALID_DATE', 1.0) + return + end + + local dt = task:get_date({format = 'connect', gmt = true}) + local date_diff = dt - dm + + if date_diff > 86400 then + -- Older than a day + task:insert_result('DATE_IN_PAST', 1.0, tostring(math.floor(date_diff/3600))) + elseif -date_diff > 7200 then + -- More than 2 hours in the future + task:insert_result('DATE_IN_FUTURE', 1.0, tostring(math.floor(-date_diff/3600))) + end + end +}) + +rspamd_config:register_symbol({ + name = 'MISSING_DATE', score = 1.0, description = 'Message date is missing', group = 'headers', - type = 'mime', -} + type = 'virtual', + parent = date_id, +}) -rspamd_config.DATE_IN_FUTURE = { - callback = function(task) - local dm = task:get_date{format = 'message', gmt = true} - local dt = task:get_date{format = 'connect', gmt = true} - -- 2 hours - if dm > 0 and dm - dt > 7200 then - return true - end - return false - end, +rspamd_config:register_symbol({ + name = 'INVALID_DATE', + score = 1.5, + description = 'Malformed date header', + group = 'headers', + type = 'virtual', + parent = date_id, +}) + +rspamd_config:register_symbol({ + name = 'DATE_IN_FUTURE', score = 4.0, description = 'Message date is in future', group = 'headers', - type = 'mime', -} + type = 'virtual', + parent = date_id, +}) -rspamd_config.DATE_IN_PAST = { - callback = function(task) - local dm = task:get_date{format = 'message', gmt = true} - local dt = task:get_date{format = 'connect', gmt = true} - -- A day - if dm > 0 and dt - dm > 86400 then - return true - end - return false - end, +rspamd_config:register_symbol({ + name = 'DATE_IN_PAST', score = 1.0, description = 'Message date is in past', group = 'headers', - type = 'mime', -} + type = 'virtual', + parent = date_id, +}) local obscured_id = rspamd_config:register_symbol{ callback = function(task) |