Browse Source

Adds prosody module to filter incoming rayo iqs based on jwt token.

Returns forbidden error message if module is enabled and the user sending a dialout rayo command is not authenticated through jwt token or is not allowed to enter the room name from the rayo iq.
master
damencho 8 years ago
parent
commit
61e637a639
1 changed files with 41 additions and 0 deletions
  1. 41
    0
      resources/prosody-plugins/mod_filter_iq_rayo.lua

+ 41
- 0
resources/prosody-plugins/mod_filter_iq_rayo.lua View File

@@ -0,0 +1,41 @@
1
+local st = require "util.stanza";
2
+
3
+local token_util = module:require "token/util".new(module);
4
+
5
+-- no token configuration but required
6
+if token_util == nil then
7
+    log("error", "no token configuration but it is required");
8
+    return;
9
+end
10
+
11
+-- filters rayo iq in case of requested from not jwt authenticated sessions
12
+module:hook("pre-iq/full", function(event)
13
+    local stanza = event.stanza;
14
+    if stanza.name == "iq" then
15
+        local dial = stanza:get_child('dial', 'urn:xmpp:rayo:1');
16
+        if dial then
17
+            local session = event.origin;
18
+            local token = session.auth_token;
19
+
20
+            -- find header with attr name 'JvbRoomName' and extract its value
21
+            local headerName = 'JvbRoomName';
22
+            local roomName;
23
+            for _, child in ipairs(dial.tags) do
24
+                if (child.name == 'header'
25
+                        and child.attr.name == headerName) then
26
+                    roomName = child.attr.value;
27
+                    break;
28
+                end
29
+            end
30
+
31
+            if token == nil
32
+                or roomName == nil
33
+                or not token_util:verify_room(session, roomName) then
34
+                module:log("info",
35
+                    "Filtering stanza dial, stanza:%s", tostring(stanza));
36
+                session.send(st.error_reply(stanza, "auth", "forbidden"));
37
+                return true;
38
+            end
39
+        end
40
+    end
41
+end);

Loading…
Cancel
Save