Merge pull request #1717 from vector-im/dbkr/fix_url_password_param
Use base64url encoding for the password param
This commit is contained in:
@@ -76,9 +76,18 @@ function waitForSync(client: MatrixClient) {
|
|||||||
function secureRandomString(entropyBytes: number): string {
|
function secureRandomString(entropyBytes: number): string {
|
||||||
const key = new Uint8Array(entropyBytes);
|
const key = new Uint8Array(entropyBytes);
|
||||||
crypto.getRandomValues(key);
|
crypto.getRandomValues(key);
|
||||||
|
// encode to base64url as this value goes into URLs
|
||||||
|
// base64url is just base64 with thw two non-alphanum characters swapped out for
|
||||||
|
// ones that can be put in a URL without encoding. Browser JS has a native impl
|
||||||
|
// for base64 encoding but only a string (there isn't one that takes a UInt8Array
|
||||||
|
// yet) so just use the built-in one and convert, replace the chars and strip the
|
||||||
|
// padding from the end (otherwise we'd need to pull in another dependency).
|
||||||
return btoa(
|
return btoa(
|
||||||
key.reduce((acc, current) => acc + String.fromCharCode(current), "")
|
key.reduce((acc, current) => acc + String.fromCharCode(current), "")
|
||||||
).replace(/=*$/, "");
|
)
|
||||||
|
.replace("+", "-")
|
||||||
|
.replace("/", "_")
|
||||||
|
.replace(/=*$/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -395,9 +404,16 @@ export function getRelativeRoomUrl(
|
|||||||
roomName?: string,
|
roomName?: string,
|
||||||
password?: string
|
password?: string
|
||||||
): string {
|
): string {
|
||||||
|
// The password shouldn't need URL encoding here (we generate URL-safe ones) but encode
|
||||||
|
// it in case it came from another client that generated a non url-safe one
|
||||||
|
const encodedPassword = password ? encodeURIComponent(password) : undefined;
|
||||||
|
if (password && encodedPassword !== password) {
|
||||||
|
logger.info("Encoded call password used non URL-safe chars: buggy client?");
|
||||||
|
}
|
||||||
|
|
||||||
return `/room/#${
|
return `/room/#${
|
||||||
roomName ? "/" + roomAliasLocalpartFromRoomName(roomName) : ""
|
roomName ? "/" + roomAliasLocalpartFromRoomName(roomName) : ""
|
||||||
}?roomId=${roomId}${password ? "&" + PASSWORD_STRING + password : ""}`;
|
}?roomId=${roomId}${password ? "&" + PASSWORD_STRING + encodedPassword : ""}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAvatarUrl(
|
export function getAvatarUrl(
|
||||||
|
|||||||
Reference in New Issue
Block a user