From: Vsevolod Stakhov Date: Fri, 14 Nov 2025 13:34:38 +0000 (+0000) Subject: [Fix] Avoid duplicate R_SUSPICIOUS_URL symbol registration X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=14827fd8e828963b26fb00bbe1b8b99033df33da;p=thirdparty%2Frspamd.git [Fix] Avoid duplicate R_SUSPICIOUS_URL symbol registration When url_suspect plugin is enabled, skip the old R_SUSPICIOUS_URL registration in rules/misc.lua to avoid symbol duplication. The old implementation is kept for backward compatibility when the new plugin is disabled. --- diff --git a/rules/misc.lua b/rules/misc.lua index 6a740f4172..0eff594ded 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -124,43 +124,50 @@ rspamd_config:register_symbol({ parent = date_id, }) -local obscured_id = rspamd_config:register_symbol { - callback = function(task) - local susp_urls = task:get_urls_filtered({ 'obscured', 'zw_spaces' }) - - if susp_urls and susp_urls[1] then - local obs_flag = url_flags_tab.obscured - local zw_flag = url_flags_tab.zw_spaces - - for _, u in ipairs(susp_urls) do - local fl = u:get_flags_num() - if bit.band(fl, obs_flag) ~= 0 then - task:insert_result('R_SUSPICIOUS_URL', 1.0, u:get_host()) - end - if bit.band(fl, zw_flag) ~= 0 then - task:insert_result('ZERO_WIDTH_SPACE_URL', 1.0, u:get_host()) +-- Check if url_suspect plugin is enabled (it provides better R_SUSPICIOUS_URL) +local url_suspect_enabled = rspamd_config:get_all_opt('url_suspect') +if url_suspect_enabled and url_suspect_enabled.enabled ~= false then + rspamd_logger.infox(rspamd_config, 'url_suspect plugin is enabled, skipping old R_SUSPICIOUS_URL registration') +else + -- Legacy R_SUSPICIOUS_URL implementation (kept for backward compatibility) + local obscured_id = rspamd_config:register_symbol { + callback = function(task) + local susp_urls = task:get_urls_filtered({ 'obscured', 'zw_spaces' }) + + if susp_urls and susp_urls[1] then + local obs_flag = url_flags_tab.obscured + local zw_flag = url_flags_tab.zw_spaces + + for _, u in ipairs(susp_urls) do + local fl = u:get_flags_num() + if bit.band(fl, obs_flag) ~= 0 then + task:insert_result('R_SUSPICIOUS_URL', 1.0, u:get_host()) + end + if bit.band(fl, zw_flag) ~= 0 then + task:insert_result('ZERO_WIDTH_SPACE_URL', 1.0, u:get_host()) + end end end - end - - return false - end, - name = 'R_SUSPICIOUS_URL', - score = 5.0, - one_shot = true, - description = 'A message has been identified to contain an obfuscated or suspicious URL', - group = 'url' -} -rspamd_config:register_symbol { - type = 'virtual', - name = 'ZERO_WIDTH_SPACE_URL', - score = 7.0, - one_shot = true, - description = 'Zero width space in URL', - group = 'url', - parent = obscured_id, -} + return false + end, + name = 'R_SUSPICIOUS_URL', + score = 5.0, + one_shot = true, + description = 'A message has been identified to contain an obfuscated or suspicious URL', + group = 'url' + } + + rspamd_config:register_symbol { + type = 'virtual', + name = 'ZERO_WIDTH_SPACE_URL', + score = 7.0, + one_shot = true, + description = 'Zero width space in URL', + group = 'url', + parent = obscured_id, + } +end rspamd_config.ENVFROM_PRVS = { callback = function(task)