commit fa9cb98: [Minor] Virustotal: Improve errors handling

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Nov 2 12:14:10 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-11-02 12:12:34 +0000
URL: https://github.com/rspamd/rspamd/commit/fa9cb9810a70fc333afc7c86e53e5f4f6ee7f29e (HEAD -> master)

[Minor] Virustotal: Improve errors handling

---
 lualib/lua_scanners/virustotal.lua | 31 +++++++++++++++++++++++++++----
 1 file 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',


More information about the Commits mailing list