Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: xss possibilities through window.open #364

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/src/telegram-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@

/* PATCHED */ const origin = REACT_APP_TG_BOT_ORIGIN;
/* PATCHED */ var popup_url = Telegram.Login.widgetsOrigin + '/auth?bot_id=' + encodeURIComponent(options.bot_id) + '&origin=' + encodeURIComponent(origin) + (options.request_access ? '&request_access=' + encodeURIComponent(options.request_access) : '') + ('&lang=' + encodeURIComponent(options.lang)) + '&return_to=' + encodeURIComponent(origin);
var popup = window.open(popup_url, '_blank', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',status=0,location=0,menubar=0,toolbar=0');
/* PATCHED */ var popup = window.open(popup_url, '_blank', 'noreferrer,noopener,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',status=0,location=0,menubar=0,toolbar=0');
TelegramLogin.popups[bot_id] = {
window: popup,
authFinished: false
Expand Down
3 changes: 3 additions & 0 deletions apps/extension/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class ExtensionAppSdk extends BaseApp {

openPage = (url: string) => {
return new Promise<void>((resolve, reject) => {
if (!url.startsWith('http')) {
reject('Invalid url');
}
browser.tabs.create({ url }).then(newTab => {
const error = checkForError();
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/tablet/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class TabletAppSdk extends BaseApp implements IAppSdk {
};

openPage = async (url: string) => {
getWindow()?.open(url, '_blank');
getWindow()?.open(url, '_blank', 'noreferrer,noopener');
};

version = packageJson.version ?? 'Unknown';
Expand Down
3 changes: 3 additions & 0 deletions apps/twa/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export class TwaAppSdk extends BaseApp {
};

openPage = async (url: string) => {
if (!url.startsWith('http')) {
throw new Error('Invalid url');
}
if (url.includes('t.me')) {
this.utils.openTelegramLink(url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please change native telegram utils to custom function:

function safeWindowOpen(url: string) {
window.open(url, '_blank', 'noreferrer');
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/web-swap-widget/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WidgetAppSdk extends BaseApp {
};

openPage = async (url: string) => {
window.open(url, '_black');
window.open(url, '_black', 'noreferrer,noopener');
};

disableScroll = disableScroll;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class BrowserAppSdk extends BaseApp {
this.topMessage(notification);
};
openPage = async (url: string) => {
window.open(url, '_black');
window.open(url, '_black', 'noreferrer,noopener');
};

disableScroll = disableScroll;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/telegram-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
var popup = window.open(
popup_url,
'_blank',
'width=' +
/* PATCHED */ 'noreferrer,noopener,width=' +
width +
',height=' +
height +
Expand Down
Loading