]> source.dussan.org Git - rspamd.git/commitdiff
[Rules] Another fix to HTTP_TO_HTTPS rule
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 16 Mar 2021 11:39:10 +0000 (11:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 16 Mar 2021 11:39:10 +0000 (11:39 +0000)
rules/html.lua

index 5430f49b788a768beae5326bbe2e3f9e14abd619..cffb2f94a866e01649d51cc7920200a7e1347aea 100644 (file)
@@ -368,10 +368,10 @@ rspamd_config.EXT_CSS = {
   description = 'Message contains external CSS reference'
 }
 
+local https_re = rspamd_regexp.create_cached('/^https:/i')
+
 rspamd_config.HTTP_TO_HTTPS = {
   callback = function(task)
-    local http_re = rspamd_regexp.create_cached('/^http[^s]/i')
-    local https_re = rspamd_regexp.create_cached('/^https:/i')
     local found_opts
     local tp = task:get_text_parts() or {}
 
@@ -382,25 +382,25 @@ rspamd_config.HTTP_TO_HTTPS = {
 
         local found = false
 
-        hc:foreach_tag('a', function (tag, length)
+        hc:foreach_tag('a', function (tag, _)
           -- Skip this loop if we already have a match
           if (found) then return true end
 
           local c = tag:get_content()
           if (c) then
-            if (not http_re:match(c)) then return false end
+            if (not https_re:match(c)) then return false end
 
             local u = tag:get_extra()
             if (not u) then return false end
             local url_proto = u:get_protocol()
-            if (not url_proto:match('^http')) then return false end
+
+            if (not url_proto == 'http') then return false end
             -- Capture matches for http in href to https in visible part only
-            if ((https_re:match(c) and url_proto == 'http')) then
-              found = true
-              found_opts = u:get_host()
-              return true
-            end
+            found = true
+            found_opts = u:get_host()
+            return true
           end
+
           return false
         end)