From 51a4aa382f445d186a8fa9918c5af74b322d4cd8 Mon Sep 17 00:00:00 2001 From: Laurent Turek Date: Tue, 21 Dec 2021 10:30:03 +0100 Subject: [PATCH 1/4] Implement addListener for chrome external connections --- packages/extension/src/background.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/extension/src/background.ts b/packages/extension/src/background.ts index 111364eae1..99210b76b8 100644 --- a/packages/extension/src/background.ts +++ b/packages/extension/src/background.ts @@ -28,6 +28,13 @@ chrome.runtime.onConnect.addListener((port): void => { port.onDisconnect.addListener(() => console.log(`Disconnected from ${port.name}`)); }); +// listen to external requests coming from other extensions +chrome.runtime.onConnectExternal.addListener((port): void => { + // message and disconnect handlers + port.onMessage.addListener((data: TransportRequestMessage) => handlers(data, port)); + port.onDisconnect.addListener(() => console.log(`Disconnected from ${port.name}`)); +}); + // initial setup cryptoWaitReady() .then((): void => { From 5399dc5eff0e2238edf07b712c2a8f6188a4482c Mon Sep 17 00:00:00 2001 From: Laurent Turek Date: Tue, 21 Dec 2021 10:30:46 +0100 Subject: [PATCH 2/4] Authorize chrome extension urls --- .../src/background/handlers/State.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/extension-base/src/background/handlers/State.ts b/packages/extension-base/src/background/handlers/State.ts index 7d982e1aff..da75261324 100644 --- a/packages/extension-base/src/background/handlers/State.ts +++ b/packages/extension-base/src/background/handlers/State.ts @@ -85,6 +85,8 @@ export enum NotificationOptions { const AUTH_URLS_KEY = 'authUrls'; +const AUTHORIZED_URL_SCHEMES = ['http', 'https', 'ipfs', 'ipns', 'chrome-extension']; + export default class State { readonly #authUrls: AuthUrls = {}; @@ -255,13 +257,23 @@ export default class State { }; private stripUrl (url: string): string { - assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`); + assert(url && this.urlIsAuthorized(url), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`); const parts = url.split('/'); return parts[2]; } + private urlIsAuthorized (url: string): boolean { + for (const authorizedScheme of AUTHORIZED_URL_SCHEMES) { + if (url.startsWith(`${authorizedScheme}:`)) { + return true; + } + } + + return false; + } + private updateIcon (shouldClose?: boolean): void { const authCount = this.numAuthRequests; const metaCount = this.numMetaRequests; From 76571ae6769d8b3e950a8a23fbf5358b3671b543 Mon Sep 17 00:00:00 2001 From: Laurent Turek Date: Tue, 21 Dec 2021 10:32:15 +0100 Subject: [PATCH 3/4] [OPTIONAL] Add website/extension origin when displaying websites access --- packages/extension-ui/src/Popup/AuthManagement/WebsiteEntry.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-ui/src/Popup/AuthManagement/WebsiteEntry.tsx b/packages/extension-ui/src/Popup/AuthManagement/WebsiteEntry.tsx index cc2e64b74b..768da77ede 100644 --- a/packages/extension-ui/src/Popup/AuthManagement/WebsiteEntry.tsx +++ b/packages/extension-ui/src/Popup/AuthManagement/WebsiteEntry.tsx @@ -28,7 +28,7 @@ function WebsiteEntry ({ className = '', info, toggleAuth, url }: Props): React. return (
- {url} + {info.origin} ({url})
Date: Tue, 21 Dec 2021 11:06:07 +0100 Subject: [PATCH 4/4] Authorize firefox extension url --- packages/extension-base/src/background/handlers/State.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-base/src/background/handlers/State.ts b/packages/extension-base/src/background/handlers/State.ts index da75261324..f8087a8e16 100644 --- a/packages/extension-base/src/background/handlers/State.ts +++ b/packages/extension-base/src/background/handlers/State.ts @@ -85,7 +85,7 @@ export enum NotificationOptions { const AUTH_URLS_KEY = 'authUrls'; -const AUTHORIZED_URL_SCHEMES = ['http', 'https', 'ipfs', 'ipns', 'chrome-extension']; +const AUTHORIZED_URL_SCHEMES = ['http', 'https', 'ipfs', 'ipns', 'chrome-extension', 'moz-extension']; export default class State { readonly #authUrls: AuthUrls = {};