-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: Update json-rpc-provider & json-rpc-middleware & json-rpc-filters #10098
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
Changes from all commits
205db8f
d927d34
4d2c65f
63d560a
fbd8509
f1e0653
e4e7599
4a914af
e1d2a04
0c1a8a1
69a39cc
e160aa5
98fba92
242934d
6cfbed3
dfae3be
1342855
cd52169
c6e47ed
eb65e5c
ff9d996
6031165
119c662
ddfb55d
49cf6fa
010a194
306f90e
a98f7d3
b7b8f28
def0c9d
21b26c3
6c61321
0debc05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| # ReDoS vulnerability, no impact to this application, and fix not backported yet to the versions we use | ||
|
|
||
| GHSA-c2qf-rxjj-qqgw | ||
|
|
||
| # ip SSRF improper categorization in isPublic, since it only affect dev tools on, and the server is actually a local server, this advisory shouldn't apply to this use cases | ||
|
|
||
| GHSA-2p57-rm9w-gvfp | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| import { | ||
| JsonRpcEngine, | ||
| import { JsonRpcEngine, JsonRpcMiddleware } from '@metamask/json-rpc-engine'; | ||
| import type { ProviderConfig } from '@metamask/network-controller'; | ||
| import { providerErrors, rpcErrors } from '@metamask/rpc-errors'; | ||
| import type { TransactionParams } from '@metamask/transaction-controller'; | ||
| import type { | ||
| Json, | ||
| JsonRpcFailure, | ||
| JsonRpcMiddleware, | ||
| JsonRpcParams, | ||
| JsonRpcRequest, | ||
| JsonRpcResponse, | ||
| JsonRpcSuccess, | ||
| } from 'json-rpc-engine'; | ||
| import type { TransactionParams } from '@metamask/transaction-controller'; | ||
| import type { ProviderConfig } from '@metamask/network-controller'; | ||
| import { providerErrors, rpcErrors } from '@metamask/rpc-errors'; | ||
| } from '@metamask/utils'; | ||
| import Engine from '../Engine'; | ||
| import { store } from '../../store'; | ||
| import { getPermittedAccounts } from '../Permissions'; | ||
|
|
@@ -93,8 +94,8 @@ const jsonrpc = '2.0' as const; | |
| * @throws If the given value is not a valid {@link JsonRpcSuccess} object. | ||
| */ | ||
| function assertIsJsonRpcSuccess( | ||
| response: JsonRpcResponse<unknown>, | ||
| ): asserts response is JsonRpcSuccess<unknown> { | ||
| response: JsonRpcResponse<Json>, | ||
| ): asserts response is JsonRpcSuccess<Json> { | ||
| if ('error' in response) { | ||
| throw new Error(`Response failed with error '${JSON.stringify('error')}'`); | ||
| } else if (!('result' in response)) { | ||
|
|
@@ -195,8 +196,8 @@ async function callMiddleware({ | |
| middleware, | ||
| request, | ||
| }: { | ||
| middleware: JsonRpcMiddleware<unknown, unknown>; | ||
| request: JsonRpcRequest<unknown>; | ||
| middleware: JsonRpcMiddleware<JsonRpcParams, Json>; | ||
| request: JsonRpcRequest<JsonRpcParams>; | ||
| }) { | ||
| const engine = new JsonRpcEngine(); | ||
| engine.push(middleware); | ||
|
|
@@ -376,7 +377,6 @@ describe('getRpcMethodMiddleware', () => { | |
| permissionController.createPermissionMiddleware({ | ||
| origin: hostMock, | ||
| }); | ||
| // @ts-expect-error JsonRpcId (number | string | void) doesn't match PS middleware's id, which is (string | number | null) | ||
| engine.push(permissionMiddleware); | ||
| const middleware = getRpcMethodMiddleware(getMinimalOptions()); | ||
| engine.push(middleware); | ||
|
|
@@ -943,7 +943,8 @@ describe('getRpcMethodMiddleware', () => { | |
| it('returns a JSON-RPC error if an error is thrown when adding this transaction', async () => { | ||
| // Omit `from` and `chainId` here to skip validation for simplicity | ||
| // Downcast needed here because `from` is required by this type | ||
| const mockTransactionParameters = {} as TransactionParams; | ||
| const mockTransactionParameters = {} as (TransactionParams & | ||
| JsonRpcParams)[]; | ||
| // Transaction fails before returning a result | ||
| mockAddTransaction.mockImplementation(async () => { | ||
| throw new Error('Failed to add transaction'); | ||
|
|
@@ -958,20 +959,26 @@ describe('getRpcMethodMiddleware', () => { | |
| method: 'eth_sendTransaction', | ||
| params: [mockTransactionParameters], | ||
| }; | ||
| const expectedError = rpcErrors.internal('Failed to add transaction'); | ||
| const expectedError = rpcErrors.internal('Internal JSON-RPC error.'); | ||
| const expectedErrorCauseMessage = 'Failed to add transaction'; | ||
|
|
||
| const response = await callMiddleware({ middleware, request }); | ||
|
|
||
| expect((response as JsonRpcFailure).error.code).toBe(expectedError.code); | ||
| expect((response as JsonRpcFailure).error.message).toBe( | ||
| expectedError.message, | ||
| ); | ||
| // @ts-expect-error - TODO: This should type | ||
tommasini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect((response as JsonRpcFailure).error.data.cause.message).toBe( | ||
| expectedErrorCauseMessage, | ||
| ); | ||
| }); | ||
|
|
||
| it('returns a JSON-RPC error if an error is thrown after approval', async () => { | ||
| // Omit `from` and `chainId` here to skip validation for simplicity | ||
| // Downcast needed here because `from` is required by this type | ||
| const mockTransactionParameters = {} as TransactionParams; | ||
| const mockTransactionParameters = {} as (TransactionParams & | ||
| JsonRpcParams)[]; | ||
| setupGlobalState({ | ||
| addTransactionResult: Promise.reject( | ||
| new Error('Failed to process transaction'), | ||
|
|
@@ -987,14 +994,19 @@ describe('getRpcMethodMiddleware', () => { | |
| method: 'eth_sendTransaction', | ||
| params: [mockTransactionParameters], | ||
| }; | ||
| const expectedError = rpcErrors.internal('Failed to process transaction'); | ||
| const expectedError = rpcErrors.internal('Internal JSON-RPC error.'); | ||
| const expectedErrorCauseMessage = 'Failed to process transaction'; | ||
|
|
||
| const response = await callMiddleware({ middleware, request }); | ||
|
|
||
| expect((response as JsonRpcFailure).error.code).toBe(expectedError.code); | ||
| expect((response as JsonRpcFailure).error.message).toBe( | ||
| expectedError.message, | ||
| ); | ||
| // @ts-expect-error - TODO: This should type | ||
| expect((response as JsonRpcFailure).error.data.cause.message).toBe( | ||
| expectedErrorCauseMessage, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -1060,7 +1072,7 @@ describe('getRpcMethodMiddleware', () => { | |
| method: 'personal_ecRecover', | ||
| params: [helloWorldMessage], | ||
| }; | ||
| const expectedError = rpcErrors.internal('Missing signature parameter'); | ||
| const expectedError = rpcErrors.internal('Internal JSON-RPC error.'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know if there's a possibility of breaking UI since the error shown is different than what was there before?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amazing question! There is a thread going on around this! |
||
|
|
||
| const response = await callMiddleware({ middleware, request }); | ||
|
|
||
|
|
@@ -1079,9 +1091,9 @@ describe('getRpcMethodMiddleware', () => { | |
| jsonrpc, | ||
| id: 1, | ||
| method: 'personal_ecRecover', | ||
| params: [undefined, helloWorldSignature], | ||
| params: [undefined, helloWorldSignature] as JsonRpcParams, | ||
| }; | ||
| const expectedError = rpcErrors.internal('Missing data parameter'); | ||
| const expectedError = rpcErrors.internal('Internal JSON-RPC error.'); | ||
|
|
||
| const response = await callMiddleware({ middleware, request }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.