]> source.dussan.org Git - rspamd.git/commitdiff
rbl.lua: Try harder to avoid invalid DNS lookups
authorAndrew Lewis <nerf@judo.za.org>
Fri, 13 Feb 2015 09:23:06 +0000 (11:23 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Fri, 13 Feb 2015 09:23:06 +0000 (11:23 +0200)
src/plugins/lua/rbl.lua

index 9abac00677ea1f988effc498c0f9882e2736102d..bb0732820855fecc276acd791cfa1d2692a3f130 100644 (file)
@@ -1,7 +1,19 @@
 local rbls = {}
 
 local rspamd_logger = require "rspamd_logger"
-local rspamd_ip = require "rspamd_ip"
+
+local function validate_dns(lstr, rstr)
+  if (lstr:len() + rstr:len()) > 252 then
+    return false
+  end
+  for v in lstr:gmatch("[^%.]+") do
+    if not v:match("^[%w%.-]+$") or v:len() > 63
+      or v:match("^-") or v:match("-$") then
+      return false
+    end
+  end
+  return true
+end
 
 local function ip_to_rbl(ip, rbl)
   return table.concat(ip:inversed_str_octets(), ".") .. '.' .. rbl
@@ -83,7 +95,8 @@ local function rbl_cb (task)
          end
          if not havegot['helo'] then
            havegot['helo'] = task:get_helo()
-           if not havegot['helo'] or string.sub(havegot['helo'],1,1) == '[' or rspamd_ip.from_string(havegot['helo']):is_valid() then
+           if havegot['helo'] == nil or
+              not validate_dns(havegot['helo'], rbl['rbl']) then
              notgot['helo'] = true
              return
            end