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
fix(logging): strip JWT signatures before logging (#17900)
bgrozev63f2b2713a2f
diff --git a/react/features/app/actions.native.ts b/react/features/app/actions.native.tsindex d58feacae8..6c655408d8 100644--- a/react/features/app/actions.native.ts+++ b/react/features/app/actions.native.ts@@ -13,6 +13,7 @@ import {} from '../base/config/functions.native';import { connect, disconnect, setLocationURL } from '../base/connection/actions.native';import { JITSI_CONNECTION_URL_KEY } from '../base/connection/constants';+import { stripJwtSignatures } from '../base/jwt/functions';import { loadConfig } from '../base/lib-jitsi-meet/functions.native';import { createDesiredLocalTracks } from '../base/tracks/actions.native';import isInsecureRoomName from '../base/util/isInsecureRoomName';@@ -48,7 +49,7 @@ export * from './actions.any';* @returns {Function}*/export function appNavigate(uri?: string, options: IReloadNowOptions = {}) {- logger.info(`appNavigate to ${uri}`);+ logger.info(`appNavigate to ${stripJwtSignatures(uri)}`);return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {let location = parseURIString(uri);@@ -86,7 +87,7 @@ export function appNavigate(uri?: string, options: IReloadNowOptions = {}) {const { hostname: currentHostName, pathname: currentPathName } = currentLocationURL;if (currentHostName === hostname && currentPathName === pathname) {- logger.warn(`Joining same conference using URL: ${currentLocationURL}`);+ logger.warn(`Joining same conference using URL: ${stripJwtSignatures(currentLocationURL)}`);return;}@@ -198,7 +199,7 @@ export function reloadNow() {const newURL = addTrackStateToURL(locationURL, state);const reloadAction = () => {- logger.info(`Reloading the conference using URL: ${locationURL}`);+ logger.info(`Reloading the conference using URL: ${stripJwtSignatures(locationURL)}`);dispatch(appNavigate(toURLString(newURL), {hidePrejoin: truediff --git a/react/features/app/actions.web.ts b/react/features/app/actions.web.tsindex 9c88eae7fb..4cc0cf5e83 100644--- a/react/features/app/actions.web.ts+++ b/react/features/app/actions.web.ts@@ -7,6 +7,7 @@ import {} from '../base/config/actions';import { buildConfigURL } from '../base/config/functions.any';import { setLocationURL } from '../base/connection/actions.web';+import { stripJwtSignatures } from '../base/jwt/functions';import { loadConfig } from '../base/lib-jitsi-meet/functions.web';import { isEmbedded } from '../base/util/embedUtils';import { parseURIString } from '../base/util/uri';@@ -187,7 +188,7 @@ export function reloadNow() {const { locationURL } = state['features/base/connection'];const reloadAction = () => {- logger.info(`Reloading the conference using URL: ${locationURL}`);+ logger.info(`Reloading the conference using URL: ${stripJwtSignatures(locationURL)}`);// Fire videoConferenceLeft before navigation so it is delivered// while the postis channel is still active. postMessage sent fromdiff --git a/react/features/base/jwt/functions.ts b/react/features/base/jwt/functions.tsindex 302715a854..470e5785d1 100644--- a/react/features/base/jwt/functions.ts+++ b/react/features/base/jwt/functions.ts@@ -32,6 +32,18 @@ export function parseJWTFromURLParams(url: URL | typeof window.location = windowreturn jwt ? jwt : parseURLParams(url, true, 'search').jwt;}+/**+ * Removes the signature from every JSON Web Token (JWT) in a value, for example+ * a URL with a jwt param, so that the value can be logged. A JWT with a valid+ * signature is a bearer credential. The header and the payload alone are not.+ *+ * @param {URL|string} value - The value which may contain JWTs.+ * @returns {string} The value as a string, with the JWT signatures removed.+ */+export function stripJwtSignatures(value?: URL | string) {+ return String(value).replace(/(eyJ[\w-]*\.[\w-]*)\.[\w-]+/g, '$1');+}+/*** Returns the user name after decoding the jwt.*diff --git a/resources/prosody-plugins/mod_muc_auth_ban.lua b/resources/prosody-plugins/mod_muc_auth_ban.luaindex 6132d37678..c202320f29 100644--- a/resources/prosody-plugins/mod_muc_auth_ban.lua+++ b/resources/prosody-plugins/mod_muc_auth_ban.lua@@ -76,8 +76,9 @@ local function shouldAllow(session)endelseban_check_error_count();- module:log("warn", "Error code:%s contacting url:%s content:%s room:%s tenant:%s",- code, ACCESS_MANAGER_URL, content, session.jitsi_web_query_room, session.jitsi_web_query_prefix);+ module:log("warn", "Error code:%s contacting url:%s content:%s room:%s tenant:%s token:%s",+ code, ACCESS_MANAGER_URL, content, session.jitsi_web_query_room, session.jitsi_web_query_prefix,+ tostring(util.strip_jwt_signature(token)));endenddiff --git a/resources/prosody-plugins/mod_muc_size.lua b/resources/prosody-plugins/mod_muc_size.luaindex 0c90bc9a11..db3815d3bc 100644--- a/resources/prosody-plugins/mod_muc_size.lua+++ b/resources/prosody-plugins/mod_muc_size.lua@@ -56,7 +56,7 @@ local muc_domain_prefix-- Load shared utility library. If it fails (e.g. a transitive dependency is-- missing in the current environment) log the error and fall back to inline-- implementations so the HTTP routes are always registered.-local async_handler_wrapper, get_room_from_jid, build_room_address, is_focus;+local async_handler_wrapper, get_room_from_jid, build_room_address, is_focus, strip_jwt_signature;local ok_util, util_or_err = pcall(function() return module:require "util" end);if ok_util thenlocal util = util_or_err;@@ -64,6 +64,7 @@ if ok_util thenget_room_from_jid = util.get_room_from_jid;build_room_address = util.build_room_address;is_focus = util.is_focus;+ strip_jwt_signature = util.strip_jwt_signature;elsemodule:log("warn", "mod_muc_size: util.lib.lua unavailable (%s); using inline fallbacks",tostring(util_or_err));@@ -86,6 +87,10 @@ elseis_focus = function(nick)return string.sub(nick, -string.len("/focus")) == "/focus";end;+ strip_jwt_signature = function(token)+ if token == nil then return nil end+ return tostring(token):match('^([^.]*%.[^.]*)%.') or '[redacted]';+ end;endlocal tostring = tostring;@@ -140,8 +145,8 @@ function verify_token(token, room_address)endif not token_util:verify_room(session, room_address) then- log("warn", "Token not allowed to join: %s token room: %s token sub: %s",- tostring(room_address), tostring(session.jitsi_meet_room),+ log("warn", "Token %s not allowed to join: %s token room: %s token sub: %s",+ tostring(strip_jwt_signature(token)), tostring(room_address), tostring(session.jitsi_meet_room),tostring(session.jitsi_meet_domain));return false;enddiff --git a/resources/prosody-plugins/mod_token_verification.lua b/resources/prosody-plugins/mod_token_verification.luaindex 28908ed9d1..f927781a7a 100644--- a/resources/prosody-plugins/mod_token_verification.lua+++ b/resources/prosody-plugins/mod_token_verification.lua@@ -48,9 +48,8 @@ if token_util == nil thenendmodule:log("debug",- "%s - starting MUC token verifier app_id: %s app_secret: %s allow empty: %s",- tostring(host), tostring(token_util.appId), tostring(token_util.appSecret),- tostring(token_util.allowEmptyToken));+ "%s - starting MUC token verifier app_id: %s allow empty: %s",+ tostring(host), tostring(token_util.appId), tostring(token_util.allowEmptyToken));-- option to disable room modification (sending muc config form) for guest that do not provide tokenlocal require_token_for_moderation;@@ -66,7 +65,7 @@ load_config();local function verify_user(session, stanza)if DEBUG thenmodule:log("debug", "Session token: %s, session room: %s",- tostring(session.auth_token), tostring(session.jitsi_meet_room));+ tostring(util.strip_jwt_signature(session.auth_token)), tostring(session.jitsi_meet_room));end-- token not required for admin users@@ -97,8 +96,9 @@ local function verify_user(session, stanza)reason = 'Room and token mismatched';end- module:log('error', 'User %s not allowed to join: %s token room: %s token sub: %s err: %s reason: %s',- user_jid, tostring(stanza.attr.to), tostring(session.jitsi_meet_room),+ module:log('error', 'User %s not allowed to join: %s token: %s token room: %s token sub: %s err: %s reason: %s',+ user_jid, tostring(stanza.attr.to), tostring(util.strip_jwt_signature(session.auth_token)),+ tostring(session.jitsi_meet_room),tostring(session.jitsi_meet_domain), err, reason);local response = st.error_reply(stanza, 'cancel', 'not-allowed', reason);diff --git a/resources/prosody-plugins/util.lib.lua b/resources/prosody-plugins/util.lib.luaindex 6155921fac..e374c2009a 100644--- a/resources/prosody-plugins/util.lib.lua+++ b/resources/prosody-plugins/util.lib.lua@@ -358,6 +358,22 @@ function ends_with(str, ending)return ending == "" or str:sub(-#ending) == endingend+--- Returns a JWT without its signature, safe to write to the logs.+-- A token with a valid signature is a bearer credential. The header and+-- the payload alone cannot be used to authenticate.+-- @param token the JWT+-- @return 'header.payload', nil for a nil token, or '[redacted]' when the+-- value does not have the form of a JWT+function strip_jwt_signature(token)+ if token == nil then+ return nil;+ end++ local unsigned = tostring(token):match('^([^.]*%.[^.]*)%.');++ return unsigned or '[redacted]';+end+-- healthcheck rooms in jicofo starts with a string '__jicofo-health-check'function is_healthcheck_room(room_jid)return starts_with(room_jid, "__jicofo-health-check");@@ -820,6 +836,7 @@ return {split_string = split_string;starts_with = starts_with;starts_with_one_of = starts_with_one_of;+ strip_jwt_signature = strip_jwt_signature;table_add = table_add;table_compare = table_compare;table_shallow_copy = table_shallow_copy;diff --git a/tests/prosody/lua/util_spec.lua b/tests/prosody/lua/util_spec.luaindex ed066ae676..43ff990ebc 100644--- a/tests/prosody/lua/util_spec.lua+++ b/tests/prosody/lua/util_spec.lua@@ -254,6 +254,27 @@ describe("util.lib", function()end)end)+ -- -----------------------------------------------------------------------+ describe("strip_jwt_signature", function()+ it("returns nil for nil token", function()+ assert.is_nil(M.strip_jwt_signature(nil))+ end)++ it("removes the signature from a JWT", function()+ assert.equal("eyJhbGciOiJIUzI1NiJ9.eyJyb29tIjoiKiJ9",+ M.strip_jwt_signature("eyJhbGciOiJIUzI1NiJ9.eyJyb29tIjoiKiJ9.c2lnbmF0dXJl"))+ end)++ it("keeps only the first two parts of a JWE", function()+ assert.equal("aGVhZGVy.a2V5", M.strip_jwt_signature("aGVhZGVy.a2V5.aXY.Y2lwaGVy.dGFn"))+ end)++ it("redacts a value that is not a JWT", function()+ assert.equal("[redacted]", M.strip_jwt_signature("not-a-jwt"))+ assert.equal("[redacted]", M.strip_jwt_signature("header.payload"))+ end)+ end)+-- -----------------------------------------------------------------------describe("starts_with_one_of", function()it("returns false for nil string", function()