From: Vsevolod Stakhov Date: Tue, 16 Mar 2021 11:39:10 +0000 (+0000) Subject: [Rules] Another fix to HTTP_TO_HTTPS rule X-Git-Tag: 3.0~578 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=028e4ecefef3491202d16725b0ce780f5d6ba48d;p=rspamd.git [Rules] Another fix to HTTP_TO_HTTPS rule --- diff --git a/rules/html.lua b/rules/html.lua index 5430f49b7..cffb2f94a 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -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)