Skip to content

Commit e511860

Browse files
fix(extension): LW-10206 fix trezor security vulnerabilities (#1023)
* fix(extension): fix trezor security vulnerabilities * fix(extension): add missing types --------- Co-authored-by: Szymon Masłowski <szymon.maslowski@iohk.io>
1 parent 3e70afd commit e511860

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

apps/browser-extension-wallet/src/lib/scripts/trezor/trezor-content-script.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { runtime } from 'webextension-polyfill';
2+
import { AllowedOrigins } from './types';
23

34
// Communicate from background script to popup
45
let port = runtime.connect({ name: 'trezor-connect' });
@@ -12,6 +13,7 @@ port.onDisconnect.addListener(() => {
1213

1314
// communicate from popup to background script
1415
window.addEventListener('message', (event) => {
16+
if (event.origin !== AllowedOrigins.TREZOR_CONNECT) throw new Error('Origin not allowed');
1517
if (port && event.source === window && event.data) {
1618
port.postMessage({ data: event.data });
1719
}

apps/browser-extension-wallet/src/lib/scripts/trezor/trezor-usb-permissions.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { runtime, tabs } from 'webextension-polyfill';
2-
3-
// Handling messages from usb permissions iframe
4-
5-
const url = 'https://connect.trezor.io/8/';
2+
import { AllowedOrigins } from './types';
63

74
/* Handling messages from usb permissions iframe */
85
const switchToPopupTab = async (event?: BeforeUnloadEvent) => {
@@ -21,13 +18,15 @@ const switchToPopupTab = async (event?: BeforeUnloadEvent) => {
2118

2219
// find tab by popup pattern and switch to it
2320
const currentTabs = await tabs.query({
24-
url: `${url}popup.html`
21+
url: `${AllowedOrigins.TREZOR_CONNECT_POPUP_BASE_URL}/popup.html`
2522
});
2623
if (currentTabs.length < 0) return;
2724
tabs.update(currentTabs[0].id, { active: true });
2825
};
2926

3027
window.addEventListener('message', async (event) => {
28+
if (event.origin !== AllowedOrigins.TREZOR_CONNECT) throw new Error('Origin not allowed');
29+
3130
if (event.data === 'usb-permissions-init') {
3231
const iframe = document.querySelector('#trezor-usb-permissions');
3332
if (!iframe || !(iframe instanceof HTMLIFrameElement)) {
@@ -55,7 +54,7 @@ window.addEventListener('load', () => {
5554
instance.style.border = '0px';
5655
instance.style.width = '100%';
5756
instance.style.height = '100%';
58-
instance.setAttribute('src', `${url}extension-permissions.html`);
57+
instance.setAttribute('src', `${AllowedOrigins.TREZOR_CONNECT_POPUP_BASE_URL}/extension-permissions.html`);
5958
instance.setAttribute('allow', 'usb');
6059

6160
if (document.body) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum AllowedOrigins {
2+
TREZOR_CONNECT = 'https://connect.trezor.io',
3+
TREZOR_CONNECT_POPUP_BASE_URL = 'https://connect.trezor.io/8'
4+
}

0 commit comments

Comments
 (0)