Skip to content

Instantly share code, notes, and snippets.

@c-rosenberg
Last active February 6, 2024 16:04
Show Gist options
  • Save c-rosenberg/bed36ceef9a6bfb913d36bad0f9165e5 to your computer and use it in GitHub Desktop.
Save c-rosenberg/bed36ceef9a6bfb913d36bad0f9165e5 to your computer and use it in GitHub Desktop.
Rspamd Lua - check if DKIM domain matches header from domain [Fosdem 2024 talk question]
-- Rspamd Lua - check if DKIM domain matches header from domain [Fosdem 2024 talk question]
-- https://fosdem.org/2024/schedule/event/fosdem-2024-2661--operations-enterprise-mail-security-with-open-source-/
-- set symbol DKIM_EQ_HFROM when at least one of the validated DKIM signature domains
-- match the header from domain
local lua_util = require "lua_util"
local E = {}
rspamd_config:register_symbol{
type = 'callback', -- or virtual, callback, prefilter or postfilter
name = 'DKIM_EQ_HFROM',
score = 0.0, -- Metric score
flags = 'empty,explicit_disable,ignore_passthrough,nostat',
callback = function(task)
local symbol = "DKIM_EQ_HFROM"
local from_domain = (((task:get_from('mime') or E)[1] or E).domain or nil)
if from_domain then
local dkim_options = (((task:get_symbol('R_DKIM_ALLOW') or E)[1] or E)['options'] or E)
local dkim_domain_match = false
for _,s in ipairs(dkim_options) do
local dkim_split = lua_util.str_split(s, ':')
if from_domain == dkim_split[1] then
dkim_domain_match = true
end
end
if dkim_domain_match then
task:insert_result(symbol, 1.0, from_domain)
return true
end
end
return false
end,
}
rspamd_config:register_dependency("DKIM_EQ_HFROM","R_DKIM_ALLOW")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment