diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-06 20:37:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 20:37:41 +0000 |
commit | 902c55e5bec49c134e28ed468ac0fe46ab5dfc35 (patch) | |
tree | 4685f36c7462ecccbc7a535b3baef919e63a07fb | |
parent | 352a465639b64e024e54e25b76d59e4e68b798b5 (diff) | |
parent | e5bb0183d3480d9ce6840ad203da5c25fc0525b7 (diff) | |
download | rspamd-902c55e5bec49c134e28ed468ac0fe46ab5dfc35.tar.gz rspamd-902c55e5bec49c134e28ed468ac0fe46ab5dfc35.zip |
Merge pull request #1948 from moisseev/mime_types
[Fix] Once more (#1879) fix bad extension check
-rw-r--r-- | src/plugins/lua/mime_types.lua | 27 | ||||
-rw-r--r-- | test/functional/cases/105_mimetypes.robot | 4 | ||||
-rw-r--r-- | test/functional/messages/rar-date-bad-ext.eml | 10 |
3 files changed, 28 insertions, 13 deletions
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index a93b5889c..9dee24c6b 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -112,23 +112,24 @@ local function check_mime_type(task) if #parts > 2 then -- We need to ensure that it is an extension, so we check for its length -- Check if next-to-last extension is not a number or date - if #ext > 4 or (ext2 and string.match(ext2, '^%d+$')) then return end + if #ext <= 4 and ext2 and not string.match(ext2, '^%d+$') then - -- Use the greatest badness multiplier - if not badness_mult or - (badness_mult2 and badness_mult < badness_mult2) then - badness_mult = badness_mult2 - end + -- 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, - string.format(".%s.%s", ext2, ext)) - else - if badness_mult then - -- Just bad extension - task:insert_result(settings['symbol_bad_extension'], badness_mult, ext) + -- Double extension + bad extension == VERY bad + task:insert_result(settings['symbol_double_extension'], badness_mult, + string.format(".%s.%s", ext2, ext)) + return end end + if badness_mult then + -- Just bad extension + task:insert_result(settings['symbol_bad_extension'], badness_mult, ext) + end end if ext then diff --git a/test/functional/cases/105_mimetypes.robot b/test/functional/cases/105_mimetypes.robot index 1756377d4..5e3860ef4 100644 --- a/test/functional/cases/105_mimetypes.robot +++ b/test/functional/cases/105_mimetypes.robot @@ -23,6 +23,10 @@ Next-to-last Double Bad Extension ${result} = Scan Message With Rspamc ${TESTDIR}/messages/next2last-doublebad.eml Check Rspamc ${result} MIME_DOUBLE_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[\\.scr\\.xz\\]\\n re=1 +Date is followed by Bad Extension + ${result} = Scan Message With Rspamc ${TESTDIR}/messages/rar-date-bad-ext.eml + Check Rspamc ${result} MIME_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[scr\\]\\n re=1 + Rar4 ${result} = Scan Message With Rspamc ${TESTDIR}/messages/rar4.eml Check Rspamc ${result} MIME_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[exe\\]\\n re=1 diff --git a/test/functional/messages/rar-date-bad-ext.eml b/test/functional/messages/rar-date-bad-ext.eml new file mode 100644 index 000000000..309efece9 --- /dev/null +++ b/test/functional/messages/rar-date-bad-ext.eml @@ -0,0 +1,10 @@ +Content-Type: multipart/mixed; boundary="--=_CDA2A73617693A02A72D9869" + +----=_CDA2A73617693A02A72D9869 +Content-Type: application/octet-stream; name="06.12.2017.gz" +Content-Disposition: attachment; filename="06.12.2017.gz" +Content-Transfer-Encoding: base64 + +UmFyIRoHAM+QcwAADQAAAAAAAAATSHQgkDMAAgAAAAIAAAACEs1KfkazhksdMA4AICAAADA2 +LjEyLjIwMTcuc2NyALB/OjwwCsQ9ewBABwA= +----=_CDA2A73617693A02A72D9869-- |