Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e] Add Malicious Dapp interaction test #5764

Merged
merged 11 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions e2e/7_maliciousDappConnection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import WalletConnect from '@walletconnect/client';
import {
beforeAllcleanApp,
afterAllcleanApp,
openDeeplinkFromBackground,
importWalletFlow,
checkIfVisible,
delay,
swipe,
waitAndTap,
} from './helpers';

let connector: any = null;
let uri = null;
let account = null;

describe('Check malicious dapp warning', () => {
beforeAll(async () => {
await beforeAllcleanApp({ hardhat: false });
});
afterAll(async () => {
await afterAllcleanApp({ hardhat: false });
});

it('watches a wallet and loads wallet screen', async () => {
await importWalletFlow();
});

it('Should handle WC connect request from a malicious source and reject it', async () => {
// Setting up WalletConnect with a malicious clientMeta
connector = new WalletConnect({
bridge: 'https://bridge.walletconnect.org',
clientMeta: {
description: 'Malicious Dapp trying to connect',
icons: ['https://example.com/malicious-icon.png'],
name: 'Malicious-Dapp',
url: 'https://test-dap-welps.vercel.app/',
},
});

await connector.createSession();
uri = connector.uri;

// Awaiting connection attempt
const maliciousConnectionAttempt = new Promise((resolve, reject) => {
connector.on('connect', async (error: any) => {
if (error) {
reject(error);
}
// Logic to reject if the domain is not trusted
if (connector.clientMeta.url.includes('malicious-dapp.com')) {
Fixed Show fixed Hide fixed
console.warn('Connection attempt from untrusted domain:', connector.clientMeta.url);
reject(new Error('Connection from untrusted source rejected'));
}
});
});

// Simulating user opening the deep link from the malicious site
const baseUrl = 'https://rnbwapp.com';
const encodedUri = encodeURIComponent(uri);
const fullUrl = `${baseUrl}/wc?uri=${encodedUri}`;

// Simulating user opening the deep link from the malicious site
await openDeeplinkFromBackground(fullUrl);

try {
await maliciousConnectionAttempt;
throw new Error('Malicious connection should not have been established');
} catch (error) {
console.log('Successfully blocked malicious connection:', error);
}
});
});
3 changes: 2 additions & 1 deletion e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { expect, device, element, by, waitFor } from 'detox';
import { parseEther } from '@ethersproject/units';
import { WALLET_VARS } from './testVariables';

const TESTING_WALLET = '0x3Cb462CDC5F809aeD0558FBEe151eD5dC3D3f608';

Expand Down Expand Up @@ -36,7 +37,7 @@ export async function importWalletFlow() {
await checkIfExists('import-sheet');
await clearField('import-sheet-input');
await device.disableSynchronization();
await typeText('import-sheet-input', process.env.TEST_SEEDS, false);
await typeText('import-sheet-input', WALLET_VARS.SEED_WALLET.PK, false);
await checkIfElementHasString('import-sheet-button-label', 'Continue');
await waitAndTap('import-sheet-button');
await checkIfVisible('wallet-info-modal');
Expand Down
1 change: 1 addition & 0 deletions e2e/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ beforeAll(async () => {
'.*rainbowme-res.cloudinary.com*',
'.*rainbow-proxy-rpc.rainbowdotme.workers.*',
'.*localhost:8081/assets/src/assets*.',
'.*arc-graphql.rainbowdotme.workers.dev*.',
]);
});
Loading
Loading