changeset 3388:7454274ead2f default tip

mod_privilege: fixed routing issue with message permission: The presence of `xmlns="jabber:client"` was causing trouble during routing, notably mod_smacks was not counting the outgoing stanza.
author Goffi <goffi@goffi.org>
date Sat, 01 Dec 2018 17:50:36 +0100
parents c5e8042b174c
children
files mod_privilege/mod_privilege.lua
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_privilege/mod_privilege.lua	Sat Dec 01 12:10:31 2018 +0100
+++ b/mod_privilege/mod_privilege.lua	Sat Dec 01 17:50:36 2018 +0100
@@ -332,6 +332,19 @@
 
 --> message permission <--
 
+local function clean_xmlns(node)
+	-- Recursively remove "jabber:client" attribute from node.
+	-- In Prosody internal routing, xmlns should not be set.
+	-- Keeping xmlns would lead to issues like mod_smacks ignoring the outgoing stanza,
+	-- so we remove all xmlns attributes with a value of "jabber:client"
+	if node.attr.xmlns == 'jabber:client' then
+		for childnode in node:childtags() do
+			clean_xmlns(childnode);
+		end
+		node.attr.xmlns = nil;
+	end
+end
+
 module:hook("message/host", function(event)
 	local session, stanza = event.origin, event.stanza;
 	local privilege_elt = stanza:get_child('privilege', _PRIV_ENT_NS)
@@ -346,6 +359,7 @@
 			if message_elt ~= nil then
 				local _, from_host, from_resource = jid.split(message_elt.attr.from)
 				if from_resource == nil and hosts[from_host] then -- we only accept bare jids from one of the server hosts
+					clean_xmlns(message_elt);  -- needed do to proper routing
 					-- at this point everything should be alright, we can send the message
 					prosody.core_route_stanza(nil, message_elt)
 				else -- trying to send a message from a forbidden entity