]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] mime_types - add filename whitelist 2735/head
authorCarsten Rosenberg <c.rosenberg@heinlein-support.de>
Tue, 29 Jan 2019 19:22:41 +0000 (20:22 +0100)
committerCarsten Rosenberg <c.rosenberg@heinlein-support.de>
Tue, 29 Jan 2019 19:22:41 +0000 (20:22 +0100)
src/plugins/lua/mime_types.lua
test/functional/cases/105_mimetypes.robot
test/functional/configs/maps/mime_types.wl [new file with mode: 0644]
test/functional/configs/mime_types.conf
test/functional/messages/exe_attm.eml [new file with mode: 0644]

index d53250510bdc0d246afc850544c550401f82a0b6..f0cc0f2dcde74194703cc8aafed8beb1f38d0943 100644 (file)
@@ -22,6 +22,7 @@ end
 local logger = require "rspamd_logger"
 local lua_util = require "lua_util"
 local rspamd_util = require "rspamd_util"
+local lua_maps = require "lua_maps"
 local N = "mime_types"
 local settings = {
   file = '',
@@ -845,6 +846,13 @@ local function check_mime_type(task)
     -- Replace potentially bad characters with '?'
     fname = fname:gsub('[^%s%g]', '?')
 
+    -- Check file is in filename whitelist
+    if settings.filename_whitelist:get_key(fname) then
+      logger.debugm("mime_types", task, "skip checking of %s - file is in filename whitelist",
+        fname)
+      return
+    end
+
     local ext,ext2,parts = gen_extension(fname)
     -- ext is the last extension, LOWERCASED
     -- ext2 is the one before last extension LOWERCASED
@@ -1073,6 +1081,9 @@ if opts then
     settings[k] = v
   end
 
+  settings.filename_whitelist = lua_maps.rspamd_map_add('mime_types', 'filename_whitelist', 'regexp',
+    'filename whitelist')
+
   local function change_extension_map_entry(ext, ct, mult)
     if type(ct) == 'table' then
       local tbl = {}
index 54a9cb4bbb96acd72a247a24bd40849f7e91c3e4..b9efd3e3cdf3d01cff41e7f5e37be45ae971df08 100644 (file)
@@ -55,6 +55,12 @@ Multipart Archive Extension
   ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/f.zip.001.eml
   Should Not Contain  ${result.stdout}  MIME_ARCHIVE_IN_ARCHIVE
 
+Exe file, but name in filename_whitelist
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/exe_attm.eml
+  Should Not Contain  ${result.stdout}  MIME_BAD_EXTENSION
+  Should Not Contain  ${result.stdout}  MIME_BAD_ATTACHMENT
+  Should Not Contain  ${result.stdout}  MIME_DOUBLE_BAD_EXTENSION
+
 Empty text part should not be treat as html
   ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/empty-plain-text.eml
   Should Not Contain  ${result.stdout}  FORGED_OUTLOOK_HTML
diff --git a/test/functional/configs/maps/mime_types.wl b/test/functional/configs/maps/mime_types.wl
new file mode 100644 (file)
index 0000000..eca07bd
--- /dev/null
@@ -0,0 +1 @@
+/^hello_world\.exe$/
index a16434b6a67733b958bfbb55db6b9912f18c4233..e28feba985ed3bd9ef59444db92ef2d48ee0a481 100644 (file)
@@ -15,4 +15,5 @@ mime_types {
             "application/pdf",
         ]
     }
+    filename_whitelist = "${TESTDIR}/configs/maps/mime_types.wl";
 }
diff --git a/test/functional/messages/exe_attm.eml b/test/functional/messages/exe_attm.eml
new file mode 100644 (file)
index 0000000..2ab0e94
--- /dev/null
@@ -0,0 +1,22 @@
+Return-Path: <root@srv.example.com>
+To: test@example.com
+From: root@srv.example.com
+Subject: test Sat, 26 Jan 2019 12:04:58 +0100
+Message-Id: <20190126120458.015328@srv.example.com>
+Date: Sat, 26 Jan 2019 12:04:58 +0100
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="----=_MIME_BOUNDARY_000_15328"
+
+------=_MIME_BOUNDARY_000_15328
+Content-Type: text/plain
+
+This is a test mailing
+------=_MIME_BOUNDARY_000_15328
+Content-Type: application/octet-stream; name="hello_world.exe"
+Content-Description: hello_world.exe
+Content-Disposition: attachment; filename="hello_world.exe"
+Content-Transfer-Encoding: BASE64
+
+f0VMRgIBAQAAAAAAAAAAAAMAPgABAAAAUBAAAAAAAABAAAAAAAAAAGA5AAAAAAAAAAAAAEAAOAAL
+
+------=_MIME_BOUNDARY_000_15328--