diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-26 21:17:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-26 21:17:51 +0100 |
commit | 544e12fbe78f85bf706d90da30180d353fbe203c (patch) | |
tree | b27d7528d1c6ad7aad2ef28eff4303f9def3e65d | |
parent | c2a26412ba839e4859ac5077907b2c69825b3287 (diff) | |
parent | 17955398297ab00f27aaa4f9f5efba7be096dbb5 (diff) | |
download | rspamd-544e12fbe78f85bf706d90da30180d353fbe203c.tar.gz rspamd-544e12fbe78f85bf706d90da30180d353fbe203c.zip |
Merge pull request #3346 from jendis/from_rules
[Rules] Add FROM_INVALID and ENVFROM_INVALID rules
-rw-r--r-- | rules/headers_checks.lua | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index ae5c61836..6c5489822 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -626,33 +626,41 @@ local check_from_id = rspamd_config:register_symbol{ callback = function(task) local envfrom = task:get_from(1) local from = task:get_from(2) - if (from and from[1] and (from[1].name == nil or from[1].name == '' )) then - task:insert_result('FROM_NO_DN', 1.0) - elseif (from and from[1] and from[1].name and - util.strequal_caseless(from[1].name, from[1].addr)) then - task:insert_result('FROM_DN_EQ_ADDR', 1.0) - elseif (from and from[1] and from[1].name and from[1].name ~= '') then - task:insert_result('FROM_HAS_DN', 1.0) - -- Look for Mr/Mrs/Dr titles - local n = from[1].name:lower() - local match, match_end - match, match_end = n:find('^mrs?[%.%s]') - if match then - task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1)) - end - match, match_end = n:find('^dr[%.%s]') - if match then - task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1)) + if (envfrom and envfrom[1] and not envfrom[1]["flags"]["valid"]) then + task:insert_result('ENVFROM_INVALID', 1.0) + end + if (from and from[1]) then + if not (from[1]["flags"]["valid"]) then + task:insert_result('FROM_INVALID', 1.0) end - -- Check for excess spaces - if n:find('%s%s') then - task:insert_result('FROM_NAME_EXCESS_SPACE', 1.0) + if (from[1].name == nil or from[1].name == '' ) then + task:insert_result('FROM_NO_DN', 1.0) + elseif (from[1].name and + util.strequal_caseless(from[1].name, from[1].addr)) then + task:insert_result('FROM_DN_EQ_ADDR', 1.0) + elseif (from[1].name and from[1].name ~= '') then + task:insert_result('FROM_HAS_DN', 1.0) + -- Look for Mr/Mrs/Dr titles + local n = from[1].name:lower() + local match, match_end + match, match_end = n:find('^mrs?[%.%s]') + if match then + task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1)) + end + match, match_end = n:find('^dr[%.%s]') + if match then + task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1)) + end + -- Check for excess spaces + if n:find('%s%s') then + task:insert_result('FROM_NAME_EXCESS_SPACE', 1.0) + end end - end - if (envfrom and from and envfrom[1] and from[1] and + if (envfrom and envfrom[1] and util.strequal_caseless(envfrom[1].addr, from[1].addr)) - then - task:insert_result('FROM_EQ_ENVFROM', 1.0) + then + task:insert_result('FROM_EQ_ENVFROM', 1.0) + end elseif (envfrom and envfrom[1] and envfrom[1].addr) then task:insert_result('FROM_NEQ_ENVFROM', 1.0, ((from or E)[1] or E).addr or '', envfrom[1].addr) end @@ -671,6 +679,22 @@ local check_from_id = rspamd_config:register_symbol{ } rspamd_config:register_symbol{ + name = 'ENVFROM_INVALID', + score = 2.0, + group = 'headers', + parent = check_from_id, + type = 'virtual', + description = 'Envelope from does not have a valid format', +} +rspamd_config:register_symbol{ + name = 'FROM_INVALID', + score = 2.0, + group = 'headers', + parent = check_from_id, + type = 'virtual', + description = 'From header does not have a valid format', +} +rspamd_config:register_symbol{ name = 'FROM_NO_DN', score = 0.0, group = 'headers', |