85degree / prosody-modules

Automatically exported from code.google.com/p/prosody-modules
MIT License
0 stars 0 forks source link

mod_privacy_lists does not respect the item order #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've the following list active:
<iq id='QX5tg-147' type='set'>
<query xmlns="jabber:iq:privacy"><list name="projectmaxs">
<item action="allow" order="1" type="subscription" 
value="to"><iq/><message/><presence-out/></item>
<item action="allow" order="2" type="subscription" value="both"/>
<item action="deny" order="2147483647"/>
<item action="allow" order="4" type="jid" value="conference.geekplace.eu"/>
<item action="allow" order="5" type="jid" value="xmpp.geekplace.eu"/>
<item action="allow" order="6" type="jid" value="xmpp2.geekplace.eu"/>
<item action="allow" order="7" type="jid" value="proxy.geekplace.eu"/>
<item action="allow" order="2147483646" type="jid" value="geekplace.eu"/>
</list></query></iq>

but the module still blocks certain 'allowed' stanzas:
Aug 14 18:33:08 geekplace.eu:privacy_lists      debug   stanza blocked: iq, to: 
geekplace.eu, from: emulator44@geekplace.eu/MAXS

I've added the following log statement to checkIfNeedToBeBlocked at the 
beginning of the "for _,item in ipairs(list.items) do" loop:
module:log("debug", "pl type %s value %s action %s", tostring(item.type), 
tostring(item.value), tostring(item.action));

and another log statement before the
                if apply then
                        if block then
section
module:log("debug", "pl item apply %s block %s", tostring(apply), 
tostring(block));

Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl type subscription 
value to action allow
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl item apply false 
block false
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl type subscription 
value both action allow
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl item apply false 
block false
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl type nil value nil 
action deny
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   pl item apply true 
block true
Aug 14 22:03:28 geekplace.eu:privacy_lists      debug   stanza blocked: iq, to: 
geekplace.eu, from: emulator44@geekplace.eu/MAXS

Notice that after the two 'subscription' type items are processed, it goes 
right into the fall-through case with type 'nil' that denies the stanza.

That leads me to the conclusion that the module does not respect the order of 
the items, but instead processes them in the order they are sent by client. 
Strangely I found that the module does in fact (or at least tries to) sort the 
privacy list's items:
table.sort(list, function(a, b) return a.order < b.order; end);

Original issue reported on code.google.com by fschm...@gmail.com on 14 Aug 2014 at 8:12

GoogleCodeExporter commented 9 years ago
For completeness, here is a diff of my changes:
diff -r 25be5fde250f mod_privacy_lists/mod_privacy_lists.lua
--- a/mod_privacy_lists/mod_privacy_lists.lua   Sun Aug 10 13:08:56 2014 +0100
+++ b/mod_privacy_lists/mod_privacy_lists.lua   Thu Aug 14 22:29:17 2014 +0200
@@ -341,6 +341,7 @@
                ) then
                        apply = true;
                end
+               module:log("debug", "pl type %s value %s action %s", 
tostring(item.type), tostring(item.value), tostring(item.action));
                if apply then
                        local evilJid = {};
                        apply = false;
@@ -358,6 +359,7 @@
                                (evilJid.host and item.value == evilJid.host) then
                                apply = true;
                                block = (item.action == "deny");
+                               module:log("debug", "pl jid action %s value 
%s", item.action, item.value);
                        elseif item.type == "group" then
                                local roster = load_roster(session.username, session.host);
                                local roster_entry = roster[jid_join(evilJid.node, evilJid.host)];
@@ -384,6 +386,7 @@
                                block = (item.action == "deny");
                        end
                end
+               module:log("debug", "pl item apply %s block %s", 
tostring(apply), tostring(block));
                if apply then
                        if block then
                                -- drop and not bounce groupchat messages, otherwise users will get kicked

Original comment by fschm...@gmail.com on 14 Aug 2014 at 8:30

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 5410f5c30d63.

Original comment by MWild1 on 16 Aug 2014 at 4:55