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

fix: skip blockaid validations for users internal accounts #10264

Merged
merged 9 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions app/core/RPCMethods/eth_sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ jest.mock('../../core/Engine', () => ({
providerConfig: { chainId: '0x1' },
},
},
AccountsController: {
state: {
internalAccounts: { accounts: [] },
},
listAccounts: () => [],
},
},
}));

Expand Down
27 changes: 27 additions & 0 deletions app/lib/ppom/ppom-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jest.mock('../../core/Engine', () => ({
providerConfig: { chainId: CHAIN_ID_MOCK },
},
},
AccountsController: {
state: {
internalAccounts: { accounts: [] },
},
listAccounts: () => [],
},
},
}));

Expand Down Expand Up @@ -110,6 +116,27 @@ describe('PPOM Utils', () => {
expect(spyTransactionAction).toBeCalledTimes(0);
});

it('should not validate if request is send to users own account ', async () => {
const spyTransactionAction = jest.spyOn(
TransactionActions,
'setTransactionSecurityAlertResponse',
);
MockEngine.context.PreferencesController.state.securityAlertsEnabled =
false;
digiwand marked this conversation as resolved.
Show resolved Hide resolved
digiwand marked this conversation as resolved.
Show resolved Hide resolved
MockEngine.context.AccountsController.listAccounts = (() => [
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jpuri marked this conversation as resolved.
Show resolved Hide resolved
{ address: '0x0c54FcCd2e384b4BB6f2E405Bf5Cbc15a017AaFb' } as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
]) as any;
await PPOMUtil.validateRequest(mockRequest, CHAIN_ID_MOCK);
expect(MockEngine.context.PPOMController?.usePPOM).toHaveBeenCalledTimes(
0,
);
expect(spyTransactionAction).toHaveBeenCalledTimes(0);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
MockEngine.context.AccountsController.listAccounts = (() => []) as any;
});

it('should not validate user if on a non supporting blockaid network', async () => {
const spyTransactionAction = jest.spyOn(
TransactionActions,
Expand Down
17 changes: 17 additions & 0 deletions app/lib/ppom/ppom-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function validateRequest(req: PPOMRequest, transactionId?: string) {
PPOMController: ppomController,
PreferencesController,
NetworkController,
AccountsController,
jpuri marked this conversation as resolved.
Show resolved Hide resolved
} = Engine.context;

const chainId = NetworkController.state.providerConfig.chainId;
Expand All @@ -80,6 +81,22 @@ async function validateRequest(req: PPOMRequest, transactionId?: string) {
return;
}

if (req.method === 'eth_sendTransaction') {
jpuri marked this conversation as resolved.
Show resolved Hide resolved
const internalAccounts = AccountsController.listAccounts();
const toAddress: string | undefined = (
req?.params?.[0] as Record<string, string>
).to;

if (
internalAccounts.some(
({ address }: { address: string }) =>
address?.toLowerCase() === toAddress?.toLowerCase(),
)
) {
return;
}
}

const isTransaction = isTransactionRequest(req);
let securityAlertResponse: SecurityAlertResponse | undefined;

Expand Down
Loading