changeset 5857:ff90dad75352

mod_report_forward: Fixes for abuse contact address lookup in origin reporting
author Matthew Wild <mwild1@gmail.com>
date Sun, 03 Mar 2024 18:06:47 +0000
parents 6fe4dab27187
children 761142ee0ff2
files mod_report_forward/mod_report_forward.lua
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_report_forward/mod_report_forward.lua	Sun Mar 03 16:10:14 2024 +0000
+++ b/mod_report_forward/mod_report_forward.lua	Sun Mar 03 18:06:47 2024 +0000
@@ -17,7 +17,7 @@
 local contact_lookup_timeout = module:get_option_number("report_forward_contact_lookup_timeout", 180);
 
 local body_template = module:get_option_string("report_forward_body_template", [[
-SPAM/ABUSE REPORT
+SPAM/ABUSE REPORT 
 -----------------
 
 Reported JID: {reported_jid}
@@ -27,7 +27,7 @@
 
 {reported_message_time&The reported message was sent at: {reported_message_time}}
 
---
+-- 
 This message contains also machine-readable payloads, including XEP-0377, in case
 you want to automate handling of these reports. You can receive these reports
 to a different address by setting 'spam-report-addresses' in your server
@@ -39,12 +39,14 @@
 local function get_address(form, ...)
 	for i = 1, select("#", ...) do
 		local field_var = select(i, ...);
-		local field = form:get_child_with_attr("field", "jabber:x:data", "var", field_var);
+		local field = form:get_child_with_attr("field", nil, "var", field_var);
 		if field then
 			local parsed = url.parse(field:get_child_text("value"));
 			if parsed.scheme == "xmpp" and parsed.path and not parsed.query then
 				return parsed.path;
 			end
+		else
+			module:log("debug", "No field '%s'", field_var);
 		end
 	end
 end
@@ -54,16 +56,21 @@
 	local address = report_addresses:get(host);
 	if address then return address; end
 
-	local contact_query = st.iq({ to = host, from = module.host, id = new_id() })
+	local contact_query = st.iq({ type = "get", to = host, from = module.host, id = new_id() })
 		:query("http://jabber.org/protocol/disco#info");
 
 	return module:send_iq(contact_query, prosody.hosts[module.host], contact_lookup_timeout)
-		:next(function (response)
-			if response.attr.type ~= "result" then return; end
+		:next(function (result)
+			module:log("debug", "Processing contact form...");
+			local response = result.stanza;
+			if response.attr.type ~= "result" then
+				module:log("warn", "Failed to query contact addresses of %s: %s", host, response);
+				return;
+			end
 
 			for form in response.tags[1]:childtags("x", "jabber:x:data") do
 				local form_type = form:get_child_with_attr("field", nil, "var", "FORM_TYPE");
-				if form_type == "http://jabber.org/network/serverinfo" then
+				if form_type and form_type:get_child_text("value") == "http://jabber.org/network/serverinfo" then
 					address = get_address(form, "spam-report-addresses", "abuse-addresses");
 					break;
 				end
@@ -132,6 +139,8 @@
 				return;
 			end
 			send_report(origin_report_address, message);
+		end):catch(function (e)
+			module:log("error", "Failed to report to origin server: %s", e);
 		end);
 	end
 end