comparison mod_delegation/mod_delegation.lua @ 4939:7d6ae8bb95dc

mod_delegation: use clean_xmlns to remove jabber:client namespace from node: for the same reason as in mod_privilege, `jabber:client` namespace is removed with the clean_xmlns method coming from there. Furthermore, the forwarded <iq> stanza use the `jabber:client` xmlns while the stanza may come from a component with e.g. `jabber:component:accept` xmlns, this can lead to inconsistencies between the <iq> stanza and children (like <error> element).
author Goffi <goffi@goffi.org>
date Sat, 28 May 2022 16:42:13 +0200
parents 679f1834dbdb
children
comparison
equal deleted inserted replaced
4938:bc8832c6696b 4939:7d6ae8bb95dc
168 --> delegated namespaces hook <-- 168 --> delegated namespaces hook <--
169 169
170 local managing_ent_error 170 local managing_ent_error
171 local stanza_cache = {} -- we cache original stanza to build reply 171 local stanza_cache = {} -- we cache original stanza to build reply
172 172
173 local function clean_xmlns(node)
174 -- Recursively remove "jabber:client" attribute from node.
175 -- In Prosody internal routing, xmlns should not be set.
176 -- Keeping xmlns would lead to issues like mod_smacks ignoring the outgoing stanza,
177 -- so we remove all xmlns attributes with a value of "jabber:client"
178 -- note: this function comes from mod_privilege
179 if node.attr.xmlns == 'jabber:client' then
180 for childnode in node:childtags() do
181 clean_xmlns(childnode)
182 end
183 node.attr.xmlns = nil
184 end
185 end
186
173 local function managing_ent_result(event) 187 local function managing_ent_result(event)
174 -- this function manage iq results from the managing entity 188 -- this function manage iq results from the managing entity
175 -- it do a couple of security check before sending the 189 -- it do a couple of security check before sending the
176 -- result to the managed entity 190 -- result to the managed entity
177 local stanza = event.stanza 191 local stanza = event.stanza
207 module:log("warn", "ignoring invalid iq result from managing entity %s", stanza.attr.from) 221 module:log("warn", "ignoring invalid iq result from managing entity %s", stanza.attr.from)
208 stanza_cache[stanza.attr.from][stanza.attr.id] = nil 222 stanza_cache[stanza.attr.from][stanza.attr.id] = nil
209 return true 223 return true
210 end 224 end
211 225
212 iq.attr.xmlns = nil 226 clean_xmlns(iq)
213 227
214 local original = stanza_cache[stanza.attr.from][stanza.attr.id] 228 local original = stanza_cache[stanza.attr.from][stanza.attr.id]
215 stanza_cache[stanza.attr.from][stanza.attr.id] = nil 229 stanza_cache[stanza.attr.from][stanza.attr.id] = nil
216 -- we get namespace from original and not iq 230 -- we get namespace from original and not iq
217 -- because the namespace can be lacking in case of error 231 -- because the namespace can be lacking in case of error