]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Spf: Fix external relay detection
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Dec 2019 13:45:06 +0000 (13:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Dec 2019 13:45:06 +0000 (13:45 +0000)
src/plugins/lua/spf.lua

index f664661f994736b88f6ee034b9d8904139c6de17..10daa0d2b3e53771e702cc794315796d291ebea3 100644 (file)
@@ -93,8 +93,8 @@ local function spf_check_callback(task)
         -- We can use the next header as a source of IP address
         if rh[i + 1] then
           local nhdr = rh[i + 1]
-          lua_util.debugm(N, task, 'found external relay %s at received header %s -> %s',
-              local_config.external_relay, hdr, nhdr.real_ip)
+          lua_util.debugm(N, task, 'found external relay %s at received header number %s -> %s',
+              local_config.external_relay, i, nhdr.real_ip)
 
           if nhdr.real_ip then
             ip = nhdr.real_ip
@@ -218,6 +218,19 @@ if local_config.whitelist then
       "radix", "SPF whitelist map")
 end
 
+if local_config.external_relay then
+  local rspamd_ip = require "rspamd_ip"
+  local ip = rspamd_ip.from_string(local_config.external_relay)
+
+  if not ip or not ip:is_valid() then
+    rspamd_logger.errx(rspamd_config, "invalid external relay IP: %s",
+        local_config.external_relay)
+    local_config.external_relay = nil
+  else
+    local_config.external_relay = ip
+  end
+end
+
 for _,sym in pairs(local_config.symbols) do
   rspamd_config:register_symbol{
     name = sym,