fix(base/util): prevent double URL encoding of non-ASCII room names

Room names with non-ASCII characters (e.g. ò) were double URL-encoded
when appended as query parameters to websocket, conference-request, and
keepalive URLs. getBackendSafeRoomName() returns a percent-encoded string
which was then re-encoded by URLSearchParams.append() via appendURLParam().

Extract getNormalizedRoomName() that decodes, NFKC-normalizes, and
lowercases without percent-encoding, and use it in the appendURLParam
call sites. getBackendSafeRoomName() is refactored to call it internally,
preserving identical behavior for all other callers.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Aaron van MeertenandClaude Opus 4.6 authored and Дамян Минков committed 2026-03-08 08:22:22 -05:00
1 parent 0f33b88774
commit 6f8414e67f
3 files changed
+28 -15

No files matched your search

+2 -2
View File
@@ -18,7 +18,7 @@ import isInsecureRoomName from '../base/util/isInsecureRoomName';
import { parseURLParams } from '../base/util/parseURLParams';
import {
appendURLParam,
getBackendSafeRoomName,
getNormalizedRoomName,
parseURIString,
toURLString
} from '../base/util/uri';
@@ -110,7 +110,7 @@ export function appNavigate(uri?: string, options: IReloadNowOptions = {}) {
let url = `${baseURL}config.js`;
// XXX In order to support multiple shards, tell the room to the deployment.
room && (url = appendURLParam(url, 'room', getBackendSafeRoomName(room) ?? ''));
room && (url = appendURLParam(url, 'room', getNormalizedRoomName(room) ?? ''));
const { release } = parseURLParams(location, true, 'search');
@@ -9,7 +9,8 @@ import { isEmbedded } from '../util/embedUtils';
import { parseURLParams } from '../util/parseURLParams';
import {
appendURLParam,
getBackendSafeRoomName
getBackendSafeRoomName,
getNormalizedRoomName
} from '../util/uri';
import {
@@ -142,7 +143,7 @@ export function constructOptions(state: IReduxState) {
const { room } = state['features/base/conference'];
if (serviceUrl && room) {
const roomName = getBackendSafeRoomName(room);
const roomName = getNormalizedRoomName(room);
options.serviceUrl = appendURLParam(serviceUrl, 'room', roomName ?? '');
+23 -11
View File
@@ -134,12 +134,13 @@ export function getBackendSafePath(path?: string): string | undefined {
}
/**
* Converts a room name to a backend-safe format. Properly lowercased and url encoded.
* Decodes, NFKC-normalizes, and lowercases a room name without percent-encoding the result.
* Use this when the result will be passed to an API (e.g. URLSearchParams) that encodes automatically.
*
* @param {string?} room - The room name to convert.
* @param {string?} room - The room name to normalize.
* @returns {string?}
*/
export function getBackendSafeRoomName(room?: string): string | undefined {
export function getNormalizedRoomName(room?: string): string | undefined {
if (!room) {
return room;
}
@@ -162,16 +163,27 @@ export function getBackendSafeRoomName(room?: string): string | undefined {
// Only decoded and normalized strings can be lowercased properly.
room = room?.toLowerCase();
// But we still need to (re)encode it.
room = encodeURIComponent(room ?? '');
/* eslint-enable no-param-reassign */
// Unfortunately we still need to lowercase it, because encoding a string will
// add some uppercase characters, but some backend services
// expect it to be full lowercase. However lowercasing an encoded string
// doesn't change the string value.
return room.toLowerCase();
return room;
}
/**
* Converts a room name to a backend-safe format. Properly lowercased and url encoded.
*
* @param {string?} room - The room name to convert.
* @returns {string?}
*/
export function getBackendSafeRoomName(room?: string): string | undefined {
const normalized = getNormalizedRoomName(room);
if (!normalized) {
return normalized;
}
// Lowercase again after encoding because encodeURIComponent produces uppercase hex digits,
// but some backend services expect fully lowercase encoded strings.
return encodeURIComponent(normalized).toLowerCase();
}
/**