Skip to content

Commit 887e837

Browse files
committed
fix(connect-mobile): improve connectSrc validation
1 parent e97ff7b commit 887e837

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/connect-mobile/src/index.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import EventEmitter from 'events';
22

33
import * as ERRORS from '@trezor/connect/src/constants/errors';
4-
import { parseConnectSettings } from '@trezor/connect/src/data/connectSettings';
4+
import { corsValidator, parseConnectSettings } from '@trezor/connect/src/data/connectSettings';
5+
import { DEEPLINK_VERSION } from '@trezor/connect/src/data/version';
56
import type { CallMethodPayload } from '@trezor/connect/src/events/call';
67
import { ConnectFactoryDependencies, factory } from '@trezor/connect/src/factory';
78
import type {
@@ -44,12 +45,22 @@ export class TrezorConnectDeeplink implements ConnectFactoryDependencies<Connect
4445
throw new Error('Unsupported right now');
4546
}
4647

48+
private validateConnectSrc(connectSrc?: string) {
49+
if (connectSrc === 'trezorsuitelite://connect') return connectSrc;
50+
51+
return corsValidator(connectSrc);
52+
}
53+
4754
public init(settings: InitFullSettings<ConnectSettingsMobile>) {
4855
if (!settings.deeplinkOpen) {
4956
throw new Error('TrezorConnect native requires "deeplinkOpen" setting.');
5057
}
58+
const connectSrc = this.validateConnectSrc(settings.connectSrc);
59+
5160
this._settings = {
5261
...parseConnectSettings({ ...this._settings, ...settings }),
62+
connectSrc: this.validateConnectSrc(settings.connectSrc),
63+
deeplinkUrl: `${connectSrc}deeplink/${DEEPLINK_VERSION}/`,
5364
deeplinkOpen: settings.deeplinkOpen,
5465
deeplinkCallbackUrl: settings.deeplinkCallbackUrl,
5566
};

packages/connect/src/data/connectSettings.ts

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export const parseConnectSettings = (input: Partial<ConnectSettings> = {}) => {
8686
settings.iframeSrc = `${src}iframe.html`;
8787
settings.popupSrc = `${src}popup.html`;
8888
settings.webusbSrc = `${src}webusb.html`;
89-
settings.deeplinkUrl = `${src}deeplink/${DEEPLINK_VERSION}/`;
9089

9190
if (typeof input.transportReconnect === 'boolean') {
9291
settings.transportReconnect = input.transportReconnect;

0 commit comments

Comments
 (0)