Mercurial > prosody-modules
comparison mod_privilege/mod_privilege.lua @ 3393:7454274ead2f
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 | e9226e3bdeba |
| children | 3ddab718f717 |
comparison
equal
deleted
inserted
replaced
| 3387:c5e8042b174c | 3393:7454274ead2f |
|---|---|
| 330 end); | 330 end); |
| 331 | 331 |
| 332 | 332 |
| 333 --> message permission <-- | 333 --> message permission <-- |
| 334 | 334 |
| 335 local function clean_xmlns(node) | |
| 336 -- Recursively remove "jabber:client" attribute from node. | |
| 337 -- In Prosody internal routing, xmlns should not be set. | |
| 338 -- Keeping xmlns would lead to issues like mod_smacks ignoring the outgoing stanza, | |
| 339 -- so we remove all xmlns attributes with a value of "jabber:client" | |
| 340 if node.attr.xmlns == 'jabber:client' then | |
| 341 for childnode in node:childtags() do | |
| 342 clean_xmlns(childnode); | |
| 343 end | |
| 344 node.attr.xmlns = nil; | |
| 345 end | |
| 346 end | |
| 347 | |
| 335 module:hook("message/host", function(event) | 348 module:hook("message/host", function(event) |
| 336 local session, stanza = event.origin, event.stanza; | 349 local session, stanza = event.origin, event.stanza; |
| 337 local privilege_elt = stanza:get_child('privilege', _PRIV_ENT_NS) | 350 local privilege_elt = stanza:get_child('privilege', _PRIV_ENT_NS) |
| 338 if privilege_elt==nil then return; end | 351 if privilege_elt==nil then return; end |
| 339 local _, to_host = jid.split(stanza.attr.to) | 352 local _, to_host = jid.split(stanza.attr.to) |
| 344 and privilege_elt.tags[1].attr.xmlns==_FORWARDED_NS then | 357 and privilege_elt.tags[1].attr.xmlns==_FORWARDED_NS then |
| 345 local message_elt = privilege_elt.tags[1]:get_child('message', 'jabber:client') | 358 local message_elt = privilege_elt.tags[1]:get_child('message', 'jabber:client') |
| 346 if message_elt ~= nil then | 359 if message_elt ~= nil then |
| 347 local _, from_host, from_resource = jid.split(message_elt.attr.from) | 360 local _, from_host, from_resource = jid.split(message_elt.attr.from) |
| 348 if from_resource == nil and hosts[from_host] then -- we only accept bare jids from one of the server hosts | 361 if from_resource == nil and hosts[from_host] then -- we only accept bare jids from one of the server hosts |
| 362 clean_xmlns(message_elt); -- needed do to proper routing | |
| 349 -- at this point everything should be alright, we can send the message | 363 -- at this point everything should be alright, we can send the message |
| 350 prosody.core_route_stanza(nil, message_elt) | 364 prosody.core_route_stanza(nil, message_elt) |
| 351 else -- trying to send a message from a forbidden entity | 365 else -- trying to send a message from a forbidden entity |
| 352 module:log("warn", "Entity "..tostring(session.full_jid).." try to send a message from "..tostring(message_elt.attr.from)) | 366 module:log("warn", "Entity "..tostring(session.full_jid).." try to send a message from "..tostring(message_elt.attr.from)) |
| 353 session.send(st.error_reply(stanza, 'auth', 'forbidden')) | 367 session.send(st.error_reply(stanza, 'auth', 'forbidden')) |
