Browse Source

[Rework] Reiterate on priorities

tags/3.3
Vsevolod Stakhov 1 year ago
parent
commit
05fd471df5
No account linked to committer's email address

+ 8
- 0
lualib/lua_util.lua View File



exports.dns_timeout_augmentation = dns_timeout_augmentation exports.dns_timeout_augmentation = dns_timeout_augmentation


-- Defines symbols priorities for common usage in prefilters/postfilters
exports.symbols_priorities = {
top = 10, -- Symbols must be executed first (or last), such as settings
high = 9, -- Example: asn
medium = 5, -- Everything should use this as default
low = 0,
}

return exports return exports

+ 16
- 16
rules/misc.lua View File



local E = {} local E = {}
local fun = require "fun" local fun = require "fun"
local util = require "rspamd_util"
local rspamd_util = require "rspamd_util"
local rspamd_parsers = require "rspamd_parsers" local rspamd_parsers = require "rspamd_parsers"
local rspamd_regexp = require "rspamd_regexp" local rspamd_regexp = require "rspamd_regexp"
local rspamd_lua_utils = require "lua_util"
local lua_util = require "lua_util"
local bit = require "bit" local bit = require "bit"
local rspamd_url = require "rspamd_url" local rspamd_url = require "rspamd_url"
local url_flags_tab = rspamd_url.flags local url_flags_tab = rspamd_url.flags
end end
if h1 and h2 then if h1 and h2 then
local selt = string.format('%s->%s', h1, h2) local selt = string.format('%s->%s', h1, h2)
if not seen[selt] and util.is_utf_spoofed(h1, h2) then
if not seen[selt] and rspamd_util.is_utf_spoofed(h1, h2) then
bad_urls[#bad_urls + 1] = selt bad_urls[#bad_urls + 1] = selt
bad_omographs = bad_omographs + 1 bad_omographs = bad_omographs + 1
end end
local h = u:get_tld() local h = u:get_tld()


if h then if h then
if not seen[h] and util.is_utf_spoofed(h) then
if not seen[h] and rspamd_util.is_utf_spoofed(h) then
bad_urls[#bad_urls + 1] = h bad_urls[#bad_urls + 1] = h
single_bad_omograps = single_bad_omograps + 1 single_bad_omograps = single_bad_omograps + 1
end end
local function check_from(type) local function check_from(type)
if task:has_from(type) then if task:has_from(type) then
local addr = task:get_from(type)[1] local addr = task:get_from(type)[1]
local na,tags = rspamd_lua_utils.remove_email_aliases(addr)
local na,tags = lua_util.remove_email_aliases(addr)
if na then if na then
task:set_from(type, addr, 'alias') task:set_from(type, addr, 'alias')
task:insert_result('TAGGED_FROM', 1.0, fun.totable( task:insert_result('TAGGED_FROM', 1.0, fun.totable(
local addrs = task:get_recipients(type) local addrs = task:get_recipients(type)


for _, addr in ipairs(addrs) do for _, addr in ipairs(addrs) do
local na,tags = rspamd_lua_utils.remove_email_aliases(addr)
local na,tags = lua_util.remove_email_aliases(addr)
if na then if na then
modified = true modified = true
fun.each(function(t) table.insert(all_tags, t) end, fun.each(function(t) table.insert(all_tags, t) end,
check_rcpt('smtp') check_rcpt('smtp')
check_rcpt('mime') check_rcpt('mime')
end, end,
priority = 150,
priority = lua_util.symbols_priorities.top + 1,
description = 'Removes plus aliases from the email', description = 'Removes plus aliases from the email',
group = 'headers', group = 'headers',
} }
-- Make sure we did not mistake e.g. <something>@<name> for an email address -- Make sure we did not mistake e.g. <something>@<name> for an email address
if not parsed[1]['domain'] or not parsed[1]['domain']:find('%.') then return false end if not parsed[1]['domain'] or not parsed[1]['domain']:find('%.') then return false end
-- See if the parsed domains differ -- See if the parsed domains differ
if not util.strequal_caseless(from[1]['domain'], parsed[1]['domain']) then
if not rspamd_util.strequal_caseless(from[1]['domain'], parsed[1]['domain']) then
-- See if the destination domain is the same as the spoof -- See if the destination domain is the same as the spoof
local mto = task:get_recipients(2) local mto = task:get_recipients(2)
local sto = task:get_recipients(1) local sto = task:get_recipients(1)
if mto then if mto then
for _, to in ipairs(mto) do for _, to in ipairs(mto) do
if to['domain'] ~= '' and util.strequal_caseless(to['domain'], parsed[1]['domain']) then
if to['domain'] ~= '' and rspamd_util.strequal_caseless(to['domain'], parsed[1]['domain']) then
task:insert_result('SPOOF_DISPLAY_NAME', 1.0, from[1]['domain'], parsed[1]['domain']) task:insert_result('SPOOF_DISPLAY_NAME', 1.0, from[1]['domain'], parsed[1]['domain'])
return false return false
end end
end end
if sto then if sto then
for _, to in ipairs(sto) do for _, to in ipairs(sto) do
if to['domain'] ~= '' and util.strequal_caseless(to['domain'], parsed[1]['domain']) then
if to['domain'] ~= '' and rspamd_util.strequal_caseless(to['domain'], parsed[1]['domain']) then
task:insert_result('SPOOF_DISPLAY_NAME', 1.0, from[1]['domain'], parsed[1]['domain']) task:insert_result('SPOOF_DISPLAY_NAME', 1.0, from[1]['domain'], parsed[1]['domain'])
return false return false
end end
if not (from and from[1] and from[1].addr) then return false end if not (from and from[1] and from[1].addr) then return false end
if (to and to[1] and to[1].addr) then if (to and to[1] and to[1].addr) then
-- Handle common case for Web Contact forms of From = To -- Handle common case for Web Contact forms of From = To
if util.strequal_caseless(from[1].addr, to[1].addr) then
if rspamd_util.strequal_caseless(from[1].addr, to[1].addr) then
return false return false
end end
end end
to = task:get_recipients(1) to = task:get_recipients(1)
if not to then return false end if not to then return false end
-- Try mitigate some possible FPs on mailing list posts -- Try mitigate some possible FPs on mailing list posts
if #to == 1 and util.strequal_caseless(to[1].addr, from[1].addr) then return false end
if #to == 1 and rspamd_util.strequal_caseless(to[1].addr, from[1].addr) then return false end
local found_fromdom = false local found_fromdom = false
for _, t in ipairs(to) do for _, t in ipairs(to) do
if util.strequal_caseless(t.domain, from[1].domain) then
if rspamd_util.strequal_caseless(t.domain, from[1].domain) then
found_fromdom = true found_fromdom = true
break break
end end
local parsed = ((rspamd_parsers.parse_mail_address(rt, task:get_mempool()) or E)[1] or E).domain local parsed = ((rspamd_parsers.parse_mail_address(rt, task:get_mempool()) or E)[1] or E).domain
if not parsed then return false end if not parsed then return false end
-- Reply-To domain must be different to From domain -- Reply-To domain must be different to From domain
if not util.strequal_caseless(parsed, from[1].domain) then
if not rspamd_util.strequal_caseless(parsed, from[1].domain) then
return true, from[1].domain, parsed return true, from[1].domain, parsed
end end
return false return false
return false return false
end end
local from = task:get_from('mime') local from = task:get_from('mime')
if not (from and from[1] and util.strequal_caseless(from[1].user, 'info')) then
if not (from and from[1] and rspamd_util.strequal_caseless(from[1].user, 'info')) then
return false return false
end end
local to = task:get_recipients('smtp') local to = task:get_recipients('smtp')
if not to then return false end if not to then return false end
local found = false local found = false
for _,r in ipairs(to) do for _,r in ipairs(to) do
if util.strequal_caseless(r['user'], 'info') then
if rspamd_util.strequal_caseless(r['user'], 'info') then
found = true found = true
end end
end end

+ 1
- 1
src/plugins/lua/antivirus.lua View File



if m.symbol_type == 'postfilter' then if m.symbol_type == 'postfilter' then
t.type = 'postfilter' t.type = 'postfilter'
t.priority = 3
t.priority = lua_util.symbols_priorities.medium
else else
t.type = 'normal' t.type = 'normal'
end end

+ 1
- 1
src/plugins/lua/asn.lua View File

name = 'ASN_CHECK', name = 'ASN_CHECK',
type = 'prefilter', type = 'prefilter',
callback = asn_check, callback = asn_check,
priority = 8,
priority = lua_util.symbols_priorities.high,
flags = 'empty,nostat', flags = 'empty,nostat',
augmentations = {lua_util.dns_timeout_augmentation(rspamd_config)}, augmentations = {lua_util.dns_timeout_augmentation(rspamd_config)},
}) })

+ 1
- 1
src/plugins/lua/aws_s3.lua View File

name = 'EXPORT_AWS_S3', name = 'EXPORT_AWS_S3',
type = settings.fail_action and 'postfilter' or 'idempotent', type = settings.fail_action and 'postfilter' or 'idempotent',
callback = s3_aws_callback, callback = s3_aws_callback,
priority = settings.fail_action and 10 or nil,
priority = settings.fail_action and lua_util.symbols_priorities.high or nil,
flags = 'empty,explicit_disable,ignore_passthrough,nostat', flags = 'empty,explicit_disable,ignore_passthrough,nostat',
}) })

+ 1
- 1
src/plugins/lua/external_relay.lua View File

rspamd_config:register_symbol({ rspamd_config:register_symbol({
name = rule.symbol, name = rule.symbol,
type = 'prefilter', type = 'prefilter',
priority = rule.priority or 20,
priority = rule.priority or lua_util.symbols_priorities.top + 1,
group = N, group = N,
callback = cb, callback = cb,
}) })

+ 1
- 1
src/plugins/lua/external_services.lua View File



if m.symbol_type == 'postfilter' then if m.symbol_type == 'postfilter' then
t.type = 'postfilter' t.type = 'postfilter'
t.priority = 3
t.priority = lua_util.symbols_priorities.medium
else else
t.type = 'normal' t.type = 'normal'
end end

+ 1
- 1
src/plugins/lua/force_actions.lua View File

local t = {} local t = {}
if (raction or honor) then if (raction or honor) then
t.type = 'postfilter' t.type = 'postfilter'
t.priority = 10
t.priority = lua_util.symbols_priorities.high
else else
t.type = 'normal' t.type = 'normal'
if not sett.least then if not sett.least then

+ 2
- 2
src/plugins/lua/greylist.lua View File

name = 'GREYLIST_SAVE', name = 'GREYLIST_SAVE',
type = 'postfilter', type = 'postfilter',
callback = greylist_set, callback = greylist_set,
priority = 6,
priority = lua_util.symbols_priorities.medium,
augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}, augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
}) })
local id = rspamd_config:register_symbol({ local id = rspamd_config:register_symbol({
name = 'GREYLIST_CHECK', name = 'GREYLIST_CHECK',
type = 'prefilter', type = 'prefilter',
callback = greylist_check, callback = greylist_check,
priority = 6,
priority = lua_util.symbols_priorities.medium,
augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)} augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}
}) })
rspamd_config:register_symbol({ rspamd_config:register_symbol({

+ 1
- 1
src/plugins/lua/neural.lua View File

name = 'NEURAL_CHECK', name = 'NEURAL_CHECK',
type = 'postfilter,callback', type = 'postfilter,callback',
flags = 'nostat', flags = 'nostat',
priority = 6,
priority = lua_util.symbols_priorities.medium,
callback = ann_scores_filter callback = ann_scores_filter
}) })



+ 1
- 1
src/plugins/lua/p0f.lua View File

name = 'P0F_CHECK', name = 'P0F_CHECK',
type = 'prefilter', type = 'prefilter',
callback = check_p0f, callback = check_p0f,
priority = 8,
priority = lua_util.symbols_priorities.medium,
flags = 'empty,nostat', flags = 'empty,nostat',
group = N, group = N,
augmentations = {string.format("timeout=%f", rule.timeout or 0.0)}, augmentations = {string.format("timeout=%f", rule.timeout or 0.0)},

+ 1
- 1
src/plugins/lua/ratelimit.lua View File

local s = { local s = {
type = settings.prefilter and 'prefilter' or 'callback', type = settings.prefilter and 'prefilter' or 'callback',
name = 'RATELIMIT_CHECK', name = 'RATELIMIT_CHECK',
priority = 7,
priority = lua_util.symbols_priorities.medium,
callback = ratelimit_cb, callback = ratelimit_cb,
flags = 'empty,nostat', flags = 'empty,nostat',
augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}, augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},

+ 2
- 2
src/plugins/lua/replies.lua View File

type = 'prefilter', type = 'prefilter',
callback = replies_check_cookie, callback = replies_check_cookie,
flags = 'nostat', flags = 'nostat',
priority = 10,
priority = lua_util.symbols_priorities.medium,
group = "replies" group = "replies"
}) })
rspamd_config:register_symbol({ rspamd_config:register_symbol({
type = 'prefilter', type = 'prefilter',
flags = 'nostat', flags = 'nostat',
callback = replies_check, callback = replies_check,
priority = 9,
priority = lua_util.symbols_priorities.medium,
group = "replies" group = "replies"
}) })
rspamd_config:register_symbol({ rspamd_config:register_symbol({

+ 2
- 2
src/plugins/lua/settings.lua View File

name = 'REDIS_SETTINGS' .. tostring(id), name = 'REDIS_SETTINGS' .. tostring(id),
type = 'prefilter', type = 'prefilter',
callback = gen_redis_callback(h, id), callback = gen_redis_callback(h, id),
priority = 10,
priority = lua_util.symbols_priorities.top,
flags = 'empty,nostat', flags = 'empty,nostat',
augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}, augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
}) })
name = 'SETTINGS_CHECK', name = 'SETTINGS_CHECK',
type = 'prefilter', type = 'prefilter',
callback = check_settings, callback = check_settings,
priority = 10,
priority = lua_util.symbols_priorities.top,
flags = 'empty,nostat,explicit_disable,ignore_passthrough', flags = 'empty,nostat,explicit_disable,ignore_passthrough',
}) })



Loading…
Cancel
Save