diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-02 12:12:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-02 12:13:03 +0000 |
commit | fa9cb9810a70fc333afc7c86e53e5f4f6ee7f29e (patch) | |
tree | adbb361dd1d57bfbca96b3ffa42b2d804e4ad474 /lualib/lua_scanners/virustotal.lua | |
parent | 5b382e87d83c4ab8ca95c13e6817a4c21bc171bc (diff) | |
download | rspamd-fa9cb9810a70fc333afc7c86e53e5f4f6ee7f29e.tar.gz rspamd-fa9cb9810a70fc333afc7c86e53e5f4f6ee7f29e.zip |
[Minor] Virustotal: Improve errors handling
Diffstat (limited to 'lualib/lua_scanners/virustotal.lua')
-rw-r--r-- | lualib/lua_scanners/virustotal.lua | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lualib/lua_scanners/virustotal.lua b/lualib/lua_scanners/virustotal.lua index b36d57ce5..8e27b3f48 100644 --- a/lualib/lua_scanners/virustotal.lua +++ b/lualib/lua_scanners/virustotal.lua @@ -110,6 +110,11 @@ local function virustotal_check(task, content, digest, rule) lua_util.debugm(rule.name, task, '%s: hash %s clean (not found)', rule.log_prefix) end + elseif code == 204 then + -- Request rate limit exceeded + rspamd_logger.infox(task, 'virustotal request rate limit exceeded') + task:insert_result(rule.symbol_fail, 1.0, 'rate limit exceeded') + return else rspamd_logger.errx(task, 'invalid HTTP code: %s, body: %s, headers: %s', code, body, headers) task:insert_result(rule.symbol_fail, 1.0, 'Bad HTTP code: ' .. code) @@ -126,10 +131,28 @@ local function virustotal_check(task, content, digest, rule) if res then local obj = parser:get_object() if not obj.positives then - rspamd_logger.errx(task, 'invalid JSON reply: %s, body: %s, headers: %s', - 'no positives element', body, headers) - task:insert_result(rule.symbol_fail, 1.0, 'Bad JSON reply: no `positives` element') - return + if obj.response_code then + if obj.response_code == 0 then + cached = 'OK' + if rule['log_clean'] then + rspamd_logger.infox(task, '%s: hash %s clean (not found)', + rule.log_prefix, hash) + else + lua_util.debugm(rule.name, task, '%s: hash %s clean (not found)', + rule.log_prefix) + end + else + rspamd_logger.errx(task, 'invalid JSON reply: %s, body: %s, headers: %s', + 'bad response code: ' .. tostring(obj.response_code), body, headers) + task:insert_result(rule.symbol_fail, 1.0, 'Bad JSON reply: no `positives` element') + return + end + else + rspamd_logger.errx(task, 'invalid JSON reply: %s, body: %s, headers: %s', + 'no response_code', body, headers) + task:insert_result(rule.symbol_fail, 1.0, 'Bad JSON reply: no `positives` element') + return + end end if obj.positives < rule.minimum_engines then lua_util.debugm(rule.name, task, '%s: hash %s has not enough hits: %s where %s is min', |