commit 60d0759: [Fix] Ical: Do not extract urls from all flags using merely specific ones

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Apr 20 14:28:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-04-20 15:26:46 +0100
URL: https://github.com/rspamd/rspamd/commit/60d075965347f1be5ec35fc72f8d3187151d0e1b (HEAD -> master)

[Fix] Ical: Do not extract urls from all flags using merely specific ones

---
 lualib/lua_content/ical.lua | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/lualib/lua_content/ical.lua b/lualib/lua_content/ical.lua
index 5ee37a491..ef8da5068 100644
--- a/lualib/lua_content/ical.lua
+++ b/lualib/lua_content/ical.lua
@@ -42,19 +42,34 @@ local function extract_text_data(specific)
   return table.concat(tbl, '\n')
 end
 
+
+-- Keys that can have visible urls
+local url_keys = lua_util.list_to_hash{
+  'description',
+  'location',
+  'summary',
+  'organizer',
+  'organiser',
+  'attendee',
+  'url'
+}
+
 local function process_ical(input, mpart, task)
   local control={n='\n', r=''}
   local rspamd_url = require "rspamd_url"
   local escaper = l.Ct((gen_grammar() / function(key, value)
     value = value:gsub("\\(.)", control)
-    key = key:lower()
-    local local_urls = rspamd_url.all(task:get_mempool(), value)
-
-    if local_urls and #local_urls > 0 then
-      for _,u in ipairs(local_urls) do
-        lua_util.debugm(N, task, 'ical: found URL in ical %s',
-            tostring(u))
-        task:inject_url(u, mpart)
+    key = key:lower():match('^([^;]+)')
+
+    if key and url_keys[key] then
+      local local_urls = rspamd_url.all(task:get_mempool(), value)
+
+      if local_urls and #local_urls > 0 then
+        for _,u in ipairs(local_urls) do
+          lua_util.debugm(N, task, 'ical: found URL in ical key "%s": %s',
+                  key, tostring(u))
+          task:inject_url(u, mpart)
+        end
       end
     end
     lua_util.debugm(N, task, 'ical: ical key %s = "%s"',


More information about the Commits mailing list