1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Disable rate limiting for signature approval requests (#18594)

This commit is contained in:
Matthew Walsh 2023-04-14 18:33:53 +01:00 committed by GitHub
parent d85d2318a3
commit fa32c5deb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 17 deletions

View File

@ -409,6 +409,14 @@ describe('SignController', () => {
);
});
it('does not throw if accepting approval throws', async () => {
messengerMock.call.mockImplementation(() => {
throw new Error('Test Error');
});
await signController[signMethodName](messageParamsMock);
});
it('rejects message on error', async () => {
keyringControllerMock[signMethodName].mockReset();
keyringControllerMock[signMethodName].mockRejectedValue(
@ -468,6 +476,14 @@ describe('SignController', () => {
'Cancel',
);
});
it('does not throw if rejecting approval throws', async () => {
messengerMock.call.mockImplementation(() => {
throw new Error('Test Error');
});
await signController[cancelMethodName](messageParamsMock);
});
});
describe('message manager events', () => {

View File

@ -33,12 +33,13 @@ import {
RejectRequest,
} from '@metamask/approval-controller';
import { MetaMetricsEventCategory } from '../../../shared/constants/metametrics';
import { MESSAGE_TYPE } from '../../../shared/constants/app';
import PreferencesController from './preferences';
const controllerName = 'SignController';
const methodNameSign = 'eth_sign';
const methodNamePersonalSign = 'personal_sign';
const methodNameTypedSign = 'eth_signTypedData';
const methodNameSign = MESSAGE_TYPE.ETH_SIGN;
const methodNamePersonalSign = MESSAGE_TYPE.PERSONAL_SIGN;
const methodNameTypedSign = MESSAGE_TYPE.ETH_SIGN_TYPED_DATA;
const stateMetadata = {
unapprovedMsgs: { persist: false, anonymous: false },
@ -636,14 +637,22 @@ export default class SignController extends BaseControllerV2<
}
private _acceptApproval(messageId: string) {
this.messagingSystem.call('ApprovalController:acceptRequest', messageId);
try {
this.messagingSystem.call('ApprovalController:acceptRequest', messageId);
} catch (error) {
log.info('Failed to accept signature approval request', error);
}
}
private _rejectApproval(messageId: string) {
this.messagingSystem.call(
'ApprovalController:rejectRequest',
messageId,
'Cancel',
);
try {
this.messagingSystem.call(
'ApprovalController:rejectRequest',
messageId,
'Cancel',
);
} catch (error) {
log.info('Failed to reject signature approval request', error);
}
}
}

View File

@ -97,8 +97,8 @@ import {
import { MILLISECOND, SECOND } from '../../shared/constants/time';
import {
ORIGIN_METAMASK,
///: BEGIN:ONLY_INCLUDE_IN(flask)
MESSAGE_TYPE,
///: BEGIN:ONLY_INCLUDE_IN(flask)
SNAP_DIALOG_TYPES,
///: END:ONLY_INCLUDE_IN
POLLING_TOKEN_ENVIRONMENT_TYPES,
@ -260,6 +260,11 @@ export default class MetamaskController extends EventEmitter {
name: 'ApprovalController',
}),
showApprovalRequest: opts.showUserConfirmation,
typesExcludedFromRateLimiting: [
MESSAGE_TYPE.ETH_SIGN,
MESSAGE_TYPE.PERSONAL_SIGN,
MESSAGE_TYPE.ETH_SIGN_TYPED_DATA,
],
});
const networkControllerMessenger = this.controllerMessenger.getRestricted({

View File

@ -228,7 +228,7 @@
"@material-ui/core": "^4.11.0",
"@metamask/address-book-controller": "^2.0.0",
"@metamask/announcement-controller": "^3.0.0",
"@metamask/approval-controller": "^2.0.0",
"@metamask/approval-controller": "^2.1.0",
"@metamask/assets-controllers": "^5.0.0",
"@metamask/base-controller": "^2.0.0",
"@metamask/contract-metadata": "^2.3.1",

View File

@ -3602,16 +3602,16 @@ __metadata:
languageName: node
linkType: hard
"@metamask/approval-controller@npm:^2.0.0":
version: 2.0.0
resolution: "@metamask/approval-controller@npm:2.0.0"
"@metamask/approval-controller@npm:^2.0.0, @metamask/approval-controller@npm:^2.1.0":
version: 2.1.0
resolution: "@metamask/approval-controller@npm:2.1.0"
dependencies:
"@metamask/base-controller": ^2.0.0
"@metamask/controller-utils": ^3.0.0
"@metamask/controller-utils": ^3.1.0
eth-rpc-errors: ^4.0.0
immer: ^9.0.6
nanoid: ^3.1.31
checksum: 1db5f9c21b04fa4688c17cdfb7da0a14b3fee084fbd8c0cfdcc41572e54140ce093c24b811b85e8ee9d3ccd8987db04d9150d7c6d5ab21daf72b4364a05f3428
checksum: 207380e3ed0007aec3b9efcde62ac3ece9fa46cc7b9e6157c0d54271e0936b5a9a05e59adcfb1e47e3f3df397d2d2dc757f3b97745528695182e7c66a5207aca
languageName: node
linkType: hard
@ -24159,7 +24159,7 @@ __metadata:
"@material-ui/core": ^4.11.0
"@metamask/address-book-controller": ^2.0.0
"@metamask/announcement-controller": ^3.0.0
"@metamask/approval-controller": ^2.0.0
"@metamask/approval-controller": ^2.1.0
"@metamask/assets-controllers": ^5.0.0
"@metamask/auto-changelog": ^2.1.0
"@metamask/base-controller": ^2.0.0