Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

refactor(oauth): scope popup result listeners to the popup that was opened

damencho93f0e6dfbce1
diff --git a/react/features/calendar-sync/web/microsoftCalendar.ts b/react/features/calendar-sync/web/microsoftCalendar.ts
index 26e2b41a35..c9b17b31db 100644
--- a/react/features/calendar-sync/web/microsoftCalendar.ts
+++ b/react/features/calendar-sync/web/microsoftCalendar.ts
@@ -197,8 +197,10 @@ export const microsoftCalendarApi = {
* @private
* @returns {void}
*/
- function handleAuth({ data }: any) {
- if (!data || data.type !== 'ms-login') {
+ function handleAuth({ data, origin, source }: MessageEvent) {
+ if (source !== popupAuthWindow
+ || origin !== new URL(MS_API_CONFIGURATION.REDIRECT_URI).origin
+ || data?.type !== 'ms-login') {
return;
}
diff --git a/react/features/dropbox/functions.web.ts b/react/features/dropbox/functions.web.ts
index b7f01359ee..336987ce48 100644
--- a/react/features/dropbox/functions.web.ts
+++ b/react/features/dropbox/functions.web.ts
@@ -1,4 +1,5 @@
import { Dropbox, DropboxAuth } from 'dropbox';
+import { v4 as uuidv4 } from 'uuid';
import { IReduxState } from '../app/types';
@@ -6,16 +7,21 @@ import { IReduxState } from '../app/types';
* Executes the oauth flow.
*
* @param {string} authUrl - The URL to oauth service.
+ * @param {string} redirectURI - The return URL, whose page posts the result back to us.
* @returns {Promise<string>} - The URL with the authorization details.
*/
-function authorize(authUrl: string): Promise<string> {
- const windowName = `oauth${Date.now()}`;
+function authorize(authUrl: string, redirectURI: string): Promise<string> {
+ const windowName = `oauth${uuidv4()}`;
+ const redirectOrigin = new URL(redirectURI).origin;
return new Promise(resolve => {
// eslint-disable-next-line prefer-const
let popup: any;
- const handleAuth = ({ data }: { data: { type: string; url: string; windowName: string; }; }) => {
- if (data && data.type === 'dropbox-login' && data.windowName === windowName) {
+ const handleAuth = ({ data, origin, source }: MessageEvent) => {
+ if (source === popup
+ && origin === redirectOrigin
+ && data?.type === 'dropbox-login'
+ && data.windowName === windowName) {
if (popup) {
popup.close();
}
@@ -55,7 +61,7 @@ export function _authorizeDropbox(
return dropbox.getAuthenticationUrl(redirectURI, undefined, 'code', 'offline', undefined, undefined, true)
// @ts-ignore
- .then(authorize)
+ .then(authUrl => authorize(authUrl, redirectURI))
.then(returnUrl => {
const params = new URLSearchParams(new URL(returnUrl).search);
const code = params.get('code');