limit to roomId

This commit is contained in:
Half-Shot
2025-07-21 12:22:49 +01:00
parent 99c4686689
commit c4921f3855
2 changed files with 14 additions and 11 deletions

View File

@@ -82,11 +82,14 @@ describe("UrlParams", () => {
getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId, getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId,
).toBe(ROOM_ID); ).toBe(ROOM_ID);
}); });
it("handles params with unprintable characters", () => { it("(roomId with unprintable characters)", () => {
const invisibleChar = "\u2066"; const invisibleChar = "\u2066";
expect( expect(
getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}${invisibleChar}`, "") getRoomIdentifierFromUrl(
.roomId, "",
`?roomId=${invisibleChar}${ROOM_ID}${invisibleChar}`,
"",
).roomId,
).toBe(ROOM_ID); ).toBe(ROOM_ID);
}); });
}); });

View File

@@ -220,8 +220,6 @@ class ParamParser {
private queryParams: URLSearchParams; private queryParams: URLSearchParams;
public constructor(search: string, hash: string) { public constructor(search: string, hash: string) {
// Replace any non-printable characters that another client may have inserted.
search = search.replaceAll(/^[^ -~]+|[^ -~]+$/g, "");
this.queryParams = new URLSearchParams(search); this.queryParams = new URLSearchParams(search);
const fragmentQueryStart = hash.indexOf("?"); const fragmentQueryStart = hash.indexOf("?");
@@ -260,8 +258,6 @@ export const getUrlParams = (
search = window.location.search, search = window.location.search,
hash = window.location.hash, hash = window.location.hash,
): UrlParams => { ): UrlParams => {
// Replace any non-printable characters that another client may have inserted.
search = search.replaceAll(/^[^ -~]+|[^ -~]+$/g, "");
const parser = new ParamParser(search, hash); const parser = new ParamParser(search, hash);
const fontScale = parseFloat(parser.getParam("fontScale") ?? ""); const fontScale = parseFloat(parser.getParam("fontScale") ?? "");
@@ -391,10 +387,14 @@ export function getRoomIdentifierFromUrl(
// Make sure roomId is valid // Make sure roomId is valid
let roomId: string | null = parser.getParam("roomId"); let roomId: string | null = parser.getParam("roomId");
if (!roomId?.startsWith("!")) { if (roomId !== null) {
roomId = null; // Replace any non-printable characters that another client may have inserted.
} else if (!roomId.includes("")) { roomId = roomId.replaceAll(/^[^ -~]+|[^ -~]+$/g, "");
roomId = null; if (!roomId.startsWith("!")) {
roomId = null;
} else if (!roomId.includes("")) {
roomId = null;
}
} }
return { return {