Browse Source

[Feature] Add rule to detect broken content type

tags/1.5.2
Vsevolod Stakhov 7 years ago
parent
commit
5244e86317
2 changed files with 38 additions and 1 deletions
  1. 11
    1
      rules/misc.lua
  2. 27
    0
      src/lua/lua_mimepart.c

+ 11
- 1
rules/misc.lua View File

@@ -168,7 +168,7 @@ rspamd_config.R_SUSPICIOUS_URL = {
end
return false
end,
score = 6.0,
score = 5.0,
one_shot = true,
description = 'Obfusicated or suspicious URL has been found in a message',
group = 'url'
@@ -183,6 +183,16 @@ rspamd_config.BROKEN_HEADERS = {
description = 'Headers structure is likely broken'
}

rspamd_config.BROKEN_CONTENT_TYPE = {
callback = function(task)
return fun.any(function(p) return p:is_broken() end,
task:get_parts())
end,
score = 3.0,
group = 'header',
description = 'Message has part with broken content type'
}

rspamd_config.HEADER_RCONFIRM_MISMATCH = {
callback = function (task)
local header_from = nil

+ 27
- 0
src/lua/lua_mimepart.c View File

@@ -288,6 +288,12 @@ LUA_FUNCTION_DEF (mimepart, get_text);
* @return {string} 128 characters hex string with digest of the part
*/
LUA_FUNCTION_DEF (mimepart, get_digest);
/***
* @method mime_part:is_broken()
* Returns true if mime part has incorrectly specified content type
* @return {bool} true if a part has bad content type
*/
LUA_FUNCTION_DEF (mimepart, is_broken);

static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_content),
@@ -302,6 +308,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, is_archive),
LUA_INTERFACE_DEF (mimepart, get_archive),
LUA_INTERFACE_DEF (mimepart, is_text),
LUA_INTERFACE_DEF (mimepart, is_broken),
LUA_INTERFACE_DEF (mimepart, get_text),
LUA_INTERFACE_DEF (mimepart, get_digest),
{"__tostring", rspamd_lua_class_tostring},
@@ -738,6 +745,26 @@ lua_mimepart_is_text (lua_State * L)
return 1;
}

static gint
lua_mimepart_is_broken (lua_State * L)
{
struct rspamd_mime_part *part = lua_check_mimepart (L);

if (part == NULL) {
return luaL_error (L, "invalid arguments");
}

if (part->ct) {
lua_pushboolean (L, (part->ct->flags & RSPAMD_CONTENT_TYPE_BROKEN) ?
true : false);
}
else {
lua_pushboolean (L, true);
}

return 1;
}

static gint
lua_mimepart_get_image (lua_State * L)
{

Loading…
Cancel
Save