# HG changeset patch # User Matthew Wild # Date 1678560109 0 # Node ID d0d251abf595cf25d982936f9033e9452652131e # Parent f6c71d9d6dc0297878da5ee2b0fa5474bfddf915 mod_firewall: Add 'REPORT TO' to report (XEP-0377) a stanza to a specified JID diff -r f6c71d9d6dc0 -r d0d251abf595 mod_firewall/README.markdown --- 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 diff -r f6c71d9d6dc0 -r d0d251abf595 mod_firewall/actions.lib.lua --- 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;