Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat: Filter iq rayo respects the actor of grant moderation.
damenchoc4d553c60574
diff --git a/resources/prosody-plugins/mod_filter_iq_jibri.lua b/resources/prosody-plugins/mod_filter_iq_jibri.luaindex f61b539ad1..70cc0e2ac2 100644--- a/resources/prosody-plugins/mod_filter_iq_jibri.lua+++ b/resources/prosody-plugins/mod_filter_iq_jibri.lua@@ -37,7 +37,7 @@ module:hook("pre-iq/full", function(event)endif token == nil- or not is_feature_allowed(session,+ or not is_feature_allowed(session.jitsi_meet_context_features,(jibri.attr.recording_mode == 'file' and 'recording' or 'livestreaming')) thenmodule:log("info",diff --git a/resources/prosody-plugins/mod_filter_iq_rayo.lua b/resources/prosody-plugins/mod_filter_iq_rayo.luaindex 88a1de8b28..f8871a21de 100644--- a/resources/prosody-plugins/mod_filter_iq_rayo.lua+++ b/resources/prosody-plugins/mod_filter_iq_rayo.lua@@ -2,8 +2,21 @@ local new_throttle = require "util.throttle".create;local st = require "util.stanza";local token_util = module:require "token/util".new(module);-local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;-local is_feature_allowed = module:require "util".is_feature_allowed;+local util = module:require 'util';+local room_jid_match_rewrite = util.room_jid_match_rewrite;+local is_feature_allowed = util.is_feature_allowed;+local get_room_from_jid = util.get_room_from_jid;+local is_healthcheck_room = util.is_healthcheck_room;+local jid_bare = require "util.jid".bare;++local sessions = prosody.full_sessions;++local main_muc_component_host = module:get_option_string('main_muc');+if main_muc_component_host == nil then+ module:log('error', 'main_muc not configured. Cannot proceed.');+ return;+end+local main_muc_service;-- no token configuration but requiredif token_util == nil then@@ -11,6 +24,11 @@ if token_util == nil thenreturn;end+local um_is_admin = require 'core.usermanager'.is_admin;+local function is_admin(jid)+ return um_is_admin(jid, module.host);+end+-- The maximum number of simultaneous calls,-- and also the maximum number of new calls per minute that a session is allowed to create.local limit_outgoing_calls;@@ -47,12 +65,15 @@ module:hook("pre-iq/full", function(event)endend- if token == nil+ if (token == nilor roomName == nilor not token_util:verify_room(session, room_jid_match_rewrite(roomName))- or not is_feature_allowed(session,- (dial.attr.to == 'jitsi_meet_transcribe' and 'transcription'- or 'outbound-call'))+ or not is_feature_allowed(session.jitsi_meet_context_features,+ (dial.attr.to == 'jitsi_meet_transcribe' and 'transcription' or 'outbound-call')))+ -- if current user is not allowed, but was granted moderation by a user+ -- that is allowed by its features we want to allow it+ and not is_feature_allowed(session.granted_jitsi_meet_context_features,+ (dial.attr.to == 'jitsi_meet_transcribe' and 'transcription' or 'outbound-call'))thenmodule:log("warn","Filtering stanza dial, stanza:%s", tostring(stanza));@@ -60,6 +81,16 @@ module:hook("pre-iq/full", function(event)return true;end+ -- we get current user_id or group, or the one from the granted one+ -- so guests and the user that granted rights are sharing same limit, as guest can be without token+ local user_id, group_id = nil, session.jitsi_meet_context_group;+ if session.jitsi_meet_context_user then+ user_id = session.jitsi_meet_context_user["id"];+ else+ user_id = session.granted_jitsi_meet_context_user_id;+ group_id = session.granted_jitsi_meet_context_group_id;+ end+-- now lets check any limits if configuredif limit_outgoing_calls > 0 thenif not session.dial_out_throttle then@@ -68,8 +99,7 @@ module:hook("pre-iq/full", function(event)endif not session.dial_out_throttle:poll(1) -- we first check the throttle so we can mark one incoming dial for the balance- or get_concurrent_outgoing_count(session.jitsi_meet_context_user["id"], session.jitsi_meet_context_group)- >= limit_outgoing_calls+ or get_concurrent_outgoing_count(user_id, group_id) >= limit_outgoing_callsthenmodule:log("warn","Filtering stanza dial, stanza:%s, outgoing calls limit reached", tostring(stanza));@@ -79,7 +109,7 @@ module:hook("pre-iq/full", function(event)end-- now lets insert token information if any- if session and session.jitsi_meet_context_user then+ if session and user_id then-- First remove any 'header' element if it already-- exists, so it cannot be spoofed by a clientstanza:maptags(@@ -98,7 +128,7 @@ module:hook("pre-iq/full", function(event)dial:tag("header", {xmlns = "urn:xmpp:rayo:1",name = OUT_INITIATOR_USER_ATTR_NAME,- value = session.jitsi_meet_context_user["id"] });+ value = user_id });dial:up();-- Add the initiator group information if it is present@@ -120,54 +150,36 @@ end);-- @return returns the count of concurrent callsfunction get_concurrent_outgoing_count(context_user, context_group)local count = 0;- for _, host in pairs(hosts) do- local component = host;- if component then- local muc = component.modules.muc- local rooms = nil;- if muc and rawget(muc,"rooms") then- -- We're running 0.9.x or 0.10 (old MUC API)- return muc.rooms;- elseif muc and rawget(muc,"live_rooms") then- -- We're running >=0.11 (new MUC API)- rooms = muc.live_rooms();- elseif muc and rawget(muc,"each_room") then- -- We're running trunk<0.11 (each_room is later [DEPRECATED])- rooms = muc.each_room(true);- end+ local rooms = main_muc_service.live_rooms();++ -- now lets iterate over rooms and occupants and search for+ -- call initiated by the user+ for room in rooms do+ for _, occupant in room:each_occupant() do+ for _, presence in occupant:each_session() do++ local initiator = presence:get_child('initiator', 'http://jitsi.org/protocol/jigasi');- -- now lets iterate over rooms and occupants and search for- -- call initiated by the user- if rooms then- for room in rooms do- for _, occupant in room:each_occupant() do- for _, presence in occupant:each_session() do-- local initiator = presence:get_child('initiator', 'http://jitsi.org/protocol/jigasi');-- local found_user = false;- local found_group = false;-- if initiator then- initiator:maptags(function (tag)- if tag.name == "header"- and tag.attr.name == OUT_INITIATOR_USER_ATTR_NAME then- found_user = tag.attr.value == context_user;- elseif tag.name == "header"- and tag.attr.name == OUT_INITIATOR_GROUP_ATTR_NAME then- found_group = tag.attr.value == context_group;- end-- return tag;- end );- -- if found a jigasi participant initiated by the concurrent- -- participant, count it- if found_user- and (context_group == nil or found_group) then- count = count + 1;- end- end+ local found_user = false;+ local found_group = false;++ if initiator then+ initiator:maptags(function (tag)+ if tag.name == "header"+ and tag.attr.name == OUT_INITIATOR_USER_ATTR_NAME then+ found_user = tag.attr.value == context_user;+ elseif tag.name == "header"+ and tag.attr.name == OUT_INITIATOR_GROUP_ATTR_NAME then+ found_group = tag.attr.value == context_group;end++ return tag;+ end );+ -- if found a jigasi participant initiated by the concurrent+ -- participant, count it+ if found_user+ and (context_group == nil or found_group) then+ count = count + 1;endendend@@ -178,3 +190,64 @@ function get_concurrent_outgoing_count(context_user, context_group)endmodule:hook_global('config-reloaded', load_config);++-- process a host module directly if loaded or hooks to wait for its load+function process_host_module(name, callback)+ local function process_host(host)+ if host == name then+ callback(module:context(host), host);+ end+ end++ if prosody.hosts[name] == nil then+ module:log('debug', 'No host/component found, will wait for it: %s', name)++ -- when a host or component is added+ prosody.events.add_handler('host-activated', process_host);+ else+ process_host(name);+ end+end++function process_set_affiliation(event)+ local actor, affiliation, jid, previous_affiliation, room+ = event.actor, event.affiliation, event.jid, event.previous_affiliation, event.room;+ local actor_session = sessions[actor];++ if is_admin(jid) or is_healthcheck_room(room.jid) or not actor or not previous_affiliation+ or not actor_session or not actor_session.jitsi_meet_context_features then+ return;+ end++ local occupant;+ for _, o in room:each_occupant() do+ if o.bare_jid == jid then+ occupant = o;+ end+ end++ if not occupant then+ return;+ end++ local occupant_session = sessions[occupant.jid];+ if not occupant_session then+ return;+ end++ if previous_affiliation == 'none' and affiliation == 'owner' then+ occupant_session.granted_jitsi_meet_context_features = actor_session.jitsi_meet_context_features;+ occupant_session.granted_jitsi_meet_context_user_id = actor_session.jitsi_meet_context_user["id"];+ occupant_session.granted_jitsi_meet_context_group_id = actor_session.jitsi_meet_context_group;+ elseif previous_affiliation == 'owner' and ( affiliation == 'member' or affiliation == 'none' ) then+ occupant_session.granted_jitsi_meet_context_features = nil;+ occupant_session.granted_jitsi_meet_context_user_id = nil;+ occupant_session.granted_jitsi_meet_context_group_id = nil;+ end+end++process_host_module(main_muc_component_host, function(host_module, host)+ main_muc_service = prosody.hosts[host].modules.muc;++ host_module:hook("muc-pre-set-affiliation", process_set_affiliation);+end);diff --git a/resources/prosody-plugins/mod_muc_transcription_filter.lua b/resources/prosody-plugins/mod_muc_transcription_filter.luaindex 308902edf3..b66e44a1d9 100644--- a/resources/prosody-plugins/mod_muc_transcription_filter.lua+++ b/resources/prosody-plugins/mod_muc_transcription_filter.lua@@ -11,7 +11,7 @@ function filter_transcription_tag(event)local stanza = event.stanza;local session = event.origin;if stanza and stanza.name == "presence" then- if not is_feature_allowed(session,'transcription') then+ if not is_feature_allowed(session.jitsi_meet_context_features,'transcription') thenstanza:maptags(function(tag)if tag and tag.name == filtered_tag_name thenmodule:log("info", "Removing %s tag from presence stanza!", filtered_tag_name);@@ -28,4 +28,4 @@ module:hook("presence/bare", filter_transcription_tag);module:hook("presence/full", filter_transcription_tag);module:hook("presence/host", filter_transcription_tag);-module:log("info", "Loaded mod_muc_transcription_filter!");\ No newline at end of file+module:log("info", "Loaded mod_muc_transcription_filter!");diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.luaindex 3c8898537b..bfff82ab2d 100644--- a/resources/prosody-plugins/util.lib.lua+++ b/resources/prosody-plugins/util.lib.lua@@ -249,9 +249,8 @@ end-- the token) and the value of the feature is true.-- If features is not present in the token we skip feature detection and allow-- everything.-function is_feature_allowed(session, feature)- if (session.jitsi_meet_context_features == nil- or session.jitsi_meet_context_features[feature] == "true" or session.jitsi_meet_context_features[feature] == true) then+function is_feature_allowed(features, ft)+ if (features == nil or features[ft] == "true" or features[ft] == true) thenreturn true;elsereturn false;