diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-10-02 18:00:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-02 18:00:43 +0100 |
commit | 08667a7acad7021eefda5a84b9c7c7c6eeb796df (patch) | |
tree | 808dba886904f303a9285ee02d940b090d013fea | |
parent | a2342f217d549f06ceeabcf260ead8e9f88d6f7e (diff) | |
parent | d3379678a72189dce8a8de5e62d7ebbfb9fc824b (diff) | |
download | rspamd-08667a7acad7021eefda5a84b9c7c7c6eeb796df.tar.gz rspamd-08667a7acad7021eefda5a84b9c7c7c6eeb796df.zip |
Merge pull request #1852 from moisseev/mime-types
[Feature] Catch next-to-last bad extension
-rw-r--r-- | src/plugins/lua/mime_types.lua | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index b90bcad01..ad5f569f6 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -92,39 +92,50 @@ local function check_mime_type(task) local function gen_extension(fname) local parts = rspamd_str_split(fname, '.') - local ext - if #parts > 1 then - ext = string.lower(parts[#parts]) - else - ext = nil + local ext = {} + for n = 1, 2 do + ext[n] = #parts > n and string.lower(parts[#parts + 1 - n]) or nil end - return ext,parts + return ext[1],ext[2],parts end + local function check_filename(fname, ct, is_archive) - local ext,parts = gen_extension(fname) + local ext,ext2,parts = gen_extension(fname) - local function check_extension(badness_mult) - if badness_mult then - if #parts > 2 + local function check_extension(badness_mult, badness_mult2) + if #parts > 2 then + if ( badness_mult -- We need to ensure that it is an extension, so we check for its length and #parts[#parts - 1] <= 4 -- Check if next-to-last extension is not a number - and not string.match(parts[#parts - 1], '^%d+$') then + and not string.match(ext2, '^%d+$') ) + -- Check length of the last extension if next-to-last extension is bad + or ( badness_mult2 and #parts[#parts] <= 4 ) then + + -- Use the greatest badness multiplier + if not badness_mult or badness_mult2 and badness_mult < badness_mult2 then + badness_mult = badness_mult2 + end + -- Double extension + bad extension == VERY bad task:insert_result(settings['symbol_double_extension'], badness_mult, { - '.' .. parts[#parts - 1] .. '.' .. ext + '.' .. ext2 .. '.' .. ext }) - else + end + else + if badness_mult then -- Just bad extension task:insert_result(settings['symbol_bad_extension'], badness_mult, ext) end end - end if ext then - check_extension(settings['bad_extensions'][ext:lower()]) + check_extension( + settings['bad_extensions'][ext:lower()], + ext2 and settings['bad_extensions'][ext2:lower()] or nil + ) -- Also check for archive bad extension if is_archive then |