From 22e5105506338a8177a8ad1e2aeb2c34c5850ac5 Mon Sep 17 00:00:00 2001 From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Wed, 14 Sep 2022 12:09:32 +0300 Subject: [Fix] Avoid overriding IP with Sender IP --- contrib/elastic/rspamd_template.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/elastic/rspamd_template.json b/contrib/elastic/rspamd_template.json index 94f54f1c9..a13fea2e5 100644 --- a/contrib/elastic/rspamd_template.json +++ b/contrib/elastic/rspamd_template.json @@ -90,6 +90,10 @@ "webmail": { "type": "boolean" }, + "sender_ip": { + "ignore_above": 1024, + "type": "keyword" + }, "geoip": { "properties": { "city_name": { -- cgit v1.2.3 From 09717437a9c72d3a61cd45d9dc2f49a54432d5c0 Mon Sep 17 00:00:00 2001 From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Wed, 14 Sep 2022 12:16:29 +0300 Subject: Update elastic.lua --- src/plugins/lua/elastic.lua | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index 8d20720bc..b93186f9a 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -121,29 +121,26 @@ local function get_general_metadata(task) local r = {} local ip_addr = task:get_ip() - r.webmail = false - if ip_addr and ip_addr:is_valid() then r.is_local = ip_addr:is_local() - local origin = task:get_header('X-Originating-IP') - if origin then - origin = string.sub(origin, 2, -2) - local rspamd_ip = require "rspamd_ip" - local test = rspamd_ip.from_string(origin) - - if test and test:is_valid() then - r.webmail = true - r.ip = origin - else - r.ip = tostring(ip_addr) - end - else - r.ip = tostring(ip_addr) - end + r.ip = tostring(ip_addr) else r.ip = '127.0.0.1' end + r.webmail = false + r.sender_ip = 'unknown' + local origin = task:get_header('X-Originating-IP') + if origin then + origin = origin:gsub('%[', ''):gsub('%]', '') + local rspamd_ip = require "rspamd_ip" + local origin_ip = rspamd_ip.from_string(origin) + if origin_ip and origin_ip:is_valid() then + r.webmail = true + r.sender_ip = origin -- use string here + end + end + r.direction = "Inbound" r.user = task:get_user() or 'unknown' r.qid = task:get_queue_id() or 'unknown' -- cgit v1.2.3 From 9ab32f929e32d21b26b39d5954b81438ecd9fe9a Mon Sep 17 00:00:00 2001 From: Dmitriy Alekseev <1865999+dragoangel@users.noreply.github.com> Date: Wed, 14 Sep 2022 14:21:11 +0300 Subject: Update rspamd_template.json --- contrib/elastic/rspamd_template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elastic/rspamd_template.json b/contrib/elastic/rspamd_template.json index a13fea2e5..ebd87faef 100644 --- a/contrib/elastic/rspamd_template.json +++ b/contrib/elastic/rspamd_template.json @@ -1,7 +1,7 @@ { "mappings": { "_meta": { - "version": "5.5.2" + "version": "5.5.3" }, "date_detection": false, "dynamic_templates": [ -- cgit v1.2.3