Bladeren bron

fix: Updates docs and verification to halt joining process.

When returning the error and showing to user not allowed screen we were not completely halting the prejoin operation when token verification fails on room join and the token is valid in general.
master
damencho 4 jaren geleden
bovenliggende
commit
0354dbe889
1 gewijzigde bestanden met toevoegingen van 9 en 3 verwijderingen
  1. 9
    3
      resources/prosody-plugins/mod_token_verification.lua

+ 9
- 3
resources/prosody-plugins/mod_token_verification.lua Bestand weergeven

40
 end
40
 end
41
 load_config();
41
 load_config();
42
 
42
 
43
+-- verify user and whether he is allowed to join a room based on the token information
43
 local function verify_user(session, stanza)
44
 local function verify_user(session, stanza)
44
 	log("debug", "Session token: %s, session room: %s",
45
 	log("debug", "Session token: %s, session room: %s",
45
 		tostring(session.auth_token),
46
 		tostring(session.auth_token),
49
 	local user_jid = stanza.attr.from;
50
 	local user_jid = stanza.attr.from;
50
 	if is_admin(user_jid) then
51
 	if is_admin(user_jid) then
51
 		log("debug", "Token not required from admin user: %s", user_jid);
52
 		log("debug", "Token not required from admin user: %s", user_jid);
52
-		return nil;
53
+		return true;
53
 	end
54
 	end
54
 
55
 
55
     log("debug",
56
     log("debug",
64
     end
65
     end
65
 	log("debug",
66
 	log("debug",
66
         "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to);
67
         "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to);
68
+    return true;
67
 end
69
 end
68
 
70
 
69
 module:hook("muc-room-pre-create", function(event)
71
 module:hook("muc-room-pre-create", function(event)
70
 	local origin, stanza = event.origin, event.stanza;
72
 	local origin, stanza = event.origin, event.stanza;
71
 	log("debug", "pre create: %s %s", tostring(origin), tostring(stanza));
73
 	log("debug", "pre create: %s %s", tostring(origin), tostring(stanza));
72
-	return verify_user(origin, stanza);
74
+    if not verify_user(origin, stanza) then
75
+        return true; -- Returning any value other than nil will halt processing of the event
76
+    end
73
 end);
77
 end);
74
 
78
 
75
 module:hook("muc-occupant-pre-join", function(event)
79
 module:hook("muc-occupant-pre-join", function(event)
76
 	local origin, room, stanza = event.origin, event.room, event.stanza;
80
 	local origin, room, stanza = event.origin, event.room, event.stanza;
77
 	log("debug", "pre join: %s %s", tostring(room), tostring(stanza));
81
 	log("debug", "pre join: %s %s", tostring(room), tostring(stanza));
78
-	return verify_user(origin, stanza);
82
+    if not verify_user(origin, stanza) then
83
+        return true; -- Returning any value other than nil will halt processing of the event
84
+    end
79
 end);
85
 end);
80
 
86
 
81
 for event_name, method in pairs {
87
 for event_name, method in pairs {

Laden…
Annuleren
Opslaan