Changeset

5235:d0d251abf595

mod_firewall: Add 'REPORT TO' to report (XEP-0377) a stanza to a specified JID
author Matthew Wild <mwild1@gmail.com>
date Sat, 11 Mar 2023 18:41:49 +0000
parents 5234:f6c71d9d6dc0
children 5236:ff8623e2f9d9
files mod_firewall/README.markdown mod_firewall/actions.lib.lua
diffstat 2 files changed, 41 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_firewall/README.markdown	Sat Mar 11 18:29:38 2023 +0000
+++ b/mod_firewall/README.markdown	Sat Mar 11 18:41:49 2023 +0000
@@ -626,11 +626,29 @@
 These actions cause a new stanza to be generated and sent somewhere.
 Processing of the original stanza will continue beyond these actions.
 
-  Action                  Description
-  ----------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------
-  `REPLY=text`            Reply to the stanza (assumed to be a message) with the given text.
-  `COPY=jid`              Make a copy of the stanza and send the copy to the specified JID. The copied stanza flows through Prosody's routing code, and as such is affected by firewall rules. Be careful to avoid loops.
-  `FORWARD=jid`           Forward a copy of the stanza to the given JID (using XEP-0297). The stanza will be sent from the current host's JID.
+  Action                   Description
+  ------------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------
+  `REPLY=text`             Reply to the stanza (assumed to be a message) with the given text.
+  `COPY=jid`               Make a copy of the stanza and send the copy to the specified JID. The copied stanza flows through Prosody's routing code, and as such is affected by firewall rules. Be careful to avoid loops.
+  `FORWARD=jid`            Forward a copy of the stanza to the given JID (using XEP-0297). The stanza will be sent from the current host's JID.
+
+### Reporting
+
+  Action                    Description
+  ------------------------  ---------------------------------------------------------------------------------------------------------------------------------------------------------
+  `REPORT=jid reason text`  Forwards the full stanza to `jid` with a XEP-0377 abuse report attached.
+
+Only the `jid` is mandatory. The `reason` parameter should be either `abuse`, `spam` or a custom URI. If not specified, it defaults to `abuse`.
+After the reason, some human-readable text may be included to explain the report.
+
+Example:
+
+```
+KIND: message
+TO: honeypot@example.com
+REPORT TO=antispam.example.com spam Caught by the honeypot!
+DROP.
+```
 
 ### Stanza modification
 
--- a/mod_firewall/actions.lib.lua	Sat Mar 11 18:29:38 2023 +0000
+++ b/mod_firewall/actions.lib.lua	Sat Mar 11 18:41:49 2023 +0000
@@ -241,4 +241,22 @@
 	       { "rostermanager", "core_post_stanza", "st", "split_to", "bare_to", "bare_from" };
 end
 
+function action_handlers.REPORT_TO(spec)
+	local where, reason, text = spec:match("^%s*(%S+) *(%S*) *(.*)$");
+	if reason == "spam" then
+		reason = "urn:xmpp:reporting:spam";
+	elseif reason == "abuse" or not reason then
+		reason = "urn:xmpp:reporting:abuse";
+	end
+	local code = [[
+		local newstanza = st.stanza("message", { to = %q, from = current_host }):tag("forwarded", { xmlns = "urn:xmpp:forward:0" });
+		local tmp_stanza = st.clone(stanza); tmp_stanza.attr.xmlns = "jabber:client"; newstanza:add_child(tmp_stanza):up();
+		newstanza:tag("report", { xmlns = "urn:xmpp:reporting:1", reason = %q })
+		do local text = %q; if text ~= "" then newstanza:text_tag("text", text); end end
+		newstanza:up();
+		core_post_stanza(session, newstanza);
+	]];
+	return code:format(where, reason, text), { "core_post_stanza", "current_host", "st" };
+end
+
 return action_handlers;