Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(prosody): check refreshed token claims against every joined room

damencho8d080b68a4c6
diff --git a/resources/prosody-plugins/README.md b/resources/prosody-plugins/README.md
index 866742ed1e..d925a79f8c 100644
--- a/resources/prosody-plugins/README.md
+++ b/resources/prosody-plugins/README.md
@@ -95,7 +95,7 @@
- jitsi_meet_context_features - The features from the context, added after token verify.
- jitsi_meet_context_room - The room settings from the jwt context, added after token verify.
- jitsi_meet_room - The room name in jwt token, added after token verify.
-- jitsi_meet_verified_room - The jid of the room the session was verified for on join. Set by mod_token_verification.lua and used to re-check claims that are refreshed later, when a resuming connection presents a different token.
+- jitsi_meet_verified_rooms - The jids of the rooms the session was verified for on join (a set, jid → true). Set by mod_token_verification.lua and used to re-check claims that are refreshed later, when a resuming connection presents a different token.
- jitsi_meet_str_tenant - The tenant in the context. Added after token verify.
- jitsi_meet_domain - The domain in the jwt ('sub' claim). Added after token verify. Can be the domain if not tenant is used or the tenant itself in lowercase.
- customusername - from a query parameter to be used with combination with "pre-jitsi-authentication" event to pre-set a known jid to a session.
diff --git a/resources/prosody-plugins/mod_token_verification.lua b/resources/prosody-plugins/mod_token_verification.lua
index f927781a7a..4aa1eb6b50 100644
--- a/resources/prosody-plugins/mod_token_verification.lua
+++ b/resources/prosody-plugins/mod_token_verification.lua
@@ -5,10 +5,10 @@
-- are exempt. Anonymous users (no token) are allowed through. When
-- token_verification_require_token_for_moderation is set, also blocks room
-- config IQs (e.g. granting moderator status) from unauthenticated users.
--- Records the verified conference on the session (jitsi_meet_verified_room) and
--- answers the 'jitsi-verify-session-rooms' event, so that a session whose JWT
--- claims are refreshed after the join (mod_auth_token, on stream resumption) is
--- re-checked against it.
+-- Records the verified conferences on the session (jitsi_meet_verified_rooms)
+-- and answers the 'jitsi-verify-session-rooms' event, so that a session whose
+-- JWT claims are refreshed after the join (mod_auth_token, on stream
+-- resumption) is re-checked against them.
-- Token authentication
-- Copyright (C) 2021-present 8x8, Inc.
@@ -17,6 +17,7 @@ local host = module.host;
local st = require "util.stanza";
local jid_split = require 'util.jid'.split;
local jid_bare = require 'util.jid'.bare;
+local jid_host = require 'util.jid'.host;
local util = module:require 'util';
local is_admin = util.is_admin;
@@ -111,10 +112,16 @@ local function verify_user(session, stanza)
end
if DEBUG then module:log("debug", "allowed: %s to enter/create room: %s", user_jid, stanza.attr.to); end
- -- Remember the conference this session was verified for, so claims that are
- -- refreshed later (mod_auth_token, on stream resumption) can be checked
- -- against it without going through a join again.
- session.jitsi_meet_verified_room = jid_bare(stanza.attr.to);
+ -- Remember every conference this session was verified for, so claims that
+ -- are refreshed later (mod_auth_token, on stream resumption) can be checked
+ -- against all of them without going through a join again. A session can be
+ -- an occupant of several rooms at once.
+ local verified_rooms = session.jitsi_meet_verified_rooms;
+ if not verified_rooms then
+ verified_rooms = {};
+ session.jitsi_meet_verified_rooms = verified_rooms;
+ end
+ verified_rooms[jid_bare(stanza.attr.to)] = true;
return true;
end
@@ -139,7 +146,7 @@ module:hook("muc-occupant-pre-join", function(event)
measure_success(1);
end, 99);
--- Verifies the token claims currently on a session against the conference it
+-- Verifies the token claims currently on a session against every conference it
-- was verified for on join. Fired by mod_auth_token when a connection resuming
-- a hibernating session (XEP-0198) presents a different token, which refreshes
-- the claims of the live session: the hooks above only run at join time, so
@@ -148,25 +155,30 @@ end, 99);
-- verified on join.
module:hook_global('jitsi-verify-session-rooms', function(event)
local session = event.session;
- local room_jid = session.jitsi_meet_verified_room;
-
- if not room_jid then
- return;
- end
+ local verified_rooms = session.jitsi_meet_verified_rooms;
- -- Being an occupant is deliberately not required: a session that moved into
- -- a breakout room has left the main room it joined, and that main room is
- -- still the conference its claims have to cover. Only a room that is gone
- -- (everyone left while the session was hibernating) is skipped.
- if not prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then
+ if not verified_rooms then
return;
end
- local res, err, reason = token_util:verify_room(session, room_jid);
-
- if not res then
- measure_fail(1);
- return { res = false; room = room_jid; error = err; reason = reason; };
+ local get_room_from_jid = prosody.hosts[host].modules.muc.get_room_from_jid;
+
+ for room_jid in pairs(verified_rooms) do
+ -- The event is global: rooms on another MUC component are checked by the
+ -- instance loaded there.
+ -- Being an occupant is deliberately not required: a session that moved
+ -- into a breakout room has left the main room it joined, and that main
+ -- room is still the conference its claims have to cover. Only a room
+ -- that is gone (everyone left while the session was hibernating) is
+ -- skipped.
+ if jid_host(room_jid) == host and get_room_from_jid(room_jid) then
+ local res, err, reason = token_util:verify_room(session, room_jid);
+
+ if not res then
+ measure_fail(1);
+ return { res = false; room = room_jid; error = err; reason = reason; };
+ end
+ end
end
measure_success(1);
diff --git a/tests/prosody/mod_auth_token_spec.js b/tests/prosody/mod_auth_token_spec.js
index dacd8fa2b3..74f48396a7 100644
--- a/tests/prosody/mod_auth_token_spec.js
+++ b/tests/prosody/mod_auth_token_spec.js
@@ -323,6 +323,106 @@ describe('mod_auth_token (claims on XEP-0198 resumption)', () => {
assert.equal(payload.file.fileId, 'file-after-resume');
});
+ /**
+ * Sets up a participant occupying two rooms, A and B, on one session, with a
+ * join token whose room claim is a pattern covering both and that grants no
+ * features. The session connects for room A, so file-sharing operations
+ * target A, where a second occupant receives the broadcasts.
+ */
+ async function setupMultiRoom() {
+ const n = ++roomCounter;
+ const roomA = `resumea${n}`;
+ const roomB = `resumeb${n}`;
+ const jidA = `${roomA}@${CONFERENCE}`;
+ const jidB = `${roomB}@${CONFERENCE}`;
+ const pattern = `^resume[ab]${n}$`;
+ const focusA = await joinWithFocus(jidA);
+ const focusB = await joinWithFocus(jidB);
+ const participant = await tokenClient(roomA, mintAsapToken({
+ room: pattern,
+ context: {
+ room: { regex: true },
+ user: { id: 'user-a',
+ name: 'user-a' }
+ }
+ }));
+ const other = await tokenClient(roomA, tokenFor(roomA));
+
+ clients.push(focusA, focusB, participant, other);
+ await other.joinRoom(jidA);
+
+ for (const jid of [ jidA, jidB ]) {
+ const presence = await participant.joinRoom(jid);
+
+ assert.notEqual(presence.attrs.type, 'error', `participant must be able to join ${jid}`);
+ }
+
+ addFile(participant, 'baseline-multi', 'file-before-resume');
+ assertForbidden(await waitForReply(participant, 'baseline-multi'),
+ 'file-upload must be refused before the token swap');
+ await assertNoBroadcast(other);
+
+ return { n,
+ roomB,
+ pattern,
+ participant,
+ other };
+ }
+
+ it('ignores features from a token that covers only one of the rooms the session occupies', async () => {
+ // B was joined last, but the session is still in A, so a token scoped
+ // to B alone does not cover every conference the session is in.
+ const { roomB, pattern, participant, other } = await setupMultiRoom();
+
+ const reconnected = participant.waitForReconnect();
+
+ participant.dropConnection({ token: tokenFor(roomB, { 'file-upload': true }) });
+ await reconnected;
+
+ const session = await getSessionLive(participant.jid);
+
+ assert.equal(session.jitsi_meet_room, pattern,
+ 'room claim of a token that does not cover every joined conference must not be adopted');
+ assert.ok(!session.jitsi_meet_context_features?.['file-upload'],
+ 'features of a token that does not cover every joined conference must not be adopted');
+
+ addFile(participant, 'after-multi-1', 'file-after-resume');
+ assertForbidden(await waitForReply(participant, 'after-multi-1'),
+ 'file-upload must still be refused in A after resuming with a token for B only');
+ await assertNoBroadcast(other);
+ });
+
+ it('adopts the claims of a rotated token that covers all the rooms the session occupies', async () => {
+ const { n, pattern, participant, other } = await setupMultiRoom();
+
+ const rotatedToken = mintAsapToken({
+ room: pattern,
+ context: {
+ room: { regex: true },
+ user: { id: 'user-a',
+ name: 'user-a' },
+ features: { 'file-upload': true }
+ }
+ });
+
+ const reconnected = participant.waitForReconnect();
+
+ participant.dropConnection({ token: rotatedToken });
+ await reconnected;
+
+ const session = await getSessionLive(participant.jid);
+
+ assert.equal(session.jitsi_meet_context_features['file-upload'], true,
+ `features of a token covering resumea${n} and resumeb${n} must be adopted`);
+
+ addFile(participant, 'after-multi-2', 'file-after-resume');
+
+ const payload = await waitForBroadcast(other);
+
+ assert.equal(payload.event, 'add');
+ assert.equal(payload.file.fileId, 'file-after-resume');
+ });
+
/**
* Sets up a meeting whose moderator has moved into a breakout room: it
* joins the main room, registers a breakout room, joins it and then leaves