fix(auth): encode telegram start payload safely
This commit is contained in:
@@ -1,10 +1,21 @@
|
|||||||
|
function toBase64Url(value: string) {
|
||||||
|
if (typeof Buffer !== 'undefined') {
|
||||||
|
return Buffer.from(value, 'utf8').toString('base64url');
|
||||||
|
}
|
||||||
|
|
||||||
|
return btoa(value)
|
||||||
|
.replace(/\+/g, '-')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=+$/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
export function buildMessengerBotStartUrl(baseUrl: string, email: string) {
|
export function buildMessengerBotStartUrl(baseUrl: string, email: string) {
|
||||||
const normalizedEmail = email.trim().toLowerCase();
|
const normalizedEmail = email.trim().toLowerCase();
|
||||||
if (!baseUrl || !normalizedEmail) {
|
if (!baseUrl || !normalizedEmail) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = encodeURIComponent(`login:${normalizedEmail}`);
|
const payload = encodeURIComponent(toBase64Url(`login:${normalizedEmail}`));
|
||||||
const separator = baseUrl.includes('?') ? '&' : '?';
|
const separator = baseUrl.includes('?') ? '&' : '?';
|
||||||
return `${baseUrl}${separator}start=${payload}`;
|
return `${baseUrl}${separator}start=${payload}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user