# HG changeset patch # User Goffi # Date 1430757840 -7200 # Node ID ef85c42ad9778640e9a6a031d7ed1ece87f7bd47 # Parent c48c7f948cfb50d026685b28887a6ddf0858b2d0 mod_delegation: fixed bad handling of error replies from managing entity diff -r c48c7f948cfb -r ef85c42ad977 mod_delegation/mod_delegation.lua --- a/mod_delegation/mod_delegation.lua Mon May 04 18:43:17 2015 +0200 +++ b/mod_delegation/mod_delegation.lua Mon May 04 18:44:00 2015 +0200 @@ -183,18 +183,22 @@ end local iq = forwarded.tags[1] - if #forwarded ~= 1 or iq.name ~= "iq" or #iq ~= 1 then + if #forwarded ~= 1 or iq.name ~= "iq" or + (iq.attr.type =='result' and #iq ~= 1) or + (iq.attr.type == 'error' and #iq > 2) then module:log("warn", "ignoring invalid iq result from managing entity %s", stanza.attr.from) stanza_cache[stanza.attr.from][stanza.attr.id] = nil return true end - local namespace = iq.tags[1].xmlns - local ns_data = ns_delegations[namespace] local original = stanza_cache[stanza.attr.from][stanza.attr.id] stanza_cache[stanza.attr.from][stanza.attr.id] = nil + -- we get namespace from original and not iq + -- because the namespace can be lacking in case of error + local namespace = original.tags[1].attr.xmlns + local ns_data = ns_delegations[namespace] - if stanza.attr.from ~= ns_data.connected or iq.attr.type ~= "result" or + if stanza.attr.from ~= ns_data.connected or (iq.attr.type ~= "result" and iq.attr.type ~= "error") or iq.attr.id ~= original.attr.id or iq.attr.to ~= original.attr.from then module:log("warn", "ignoring forbidden iq result from managing entity %s, please check that the component is no trying to do something bad (stanza: %s)", stanza.attr.from, tostring(stanza)) module:send(st.error_reply(original, 'cancel', 'service-unavailable'))