Skip to content

Commit 2d1b1f9

Browse files
author
jagdeep sidhu
committed
restrict post messages to origin if used
1 parent 6aaf0f5 commit 2d1b1f9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

source/scripts/ContentScript/inject/BaseProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class BaseProvider extends EventEmitter {
328328
type,
329329
data,
330330
},
331-
'*'
331+
window.location.origin
332332
);
333333
});
334334
}

trezor-usb-permissions.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@
1919
});
2020
setStatus('USB permission granted. You can close this tab/window.');
2121
try {
22-
window.opener &&
22+
if (window.opener) {
23+
let openerOrigin = '*';
24+
try {
25+
if (document.referrer) {
26+
let url = new URL(document.referrer);
27+
openerOrigin = url.origin;
28+
}
29+
} catch (_) {
30+
openerOrigin = '*';
31+
}
2332
window.opener.postMessage(
2433
{ type: 'trezor-usb-permission-granted' },
25-
'*'
34+
openerOrigin
2635
);
36+
}
2737
} catch (_) {}
2838
} catch (e) {
2939
setStatus(e && e.message ? e.message : 'USB permission error', true);

0 commit comments

Comments
 (0)