-
-
Notifications
You must be signed in to change notification settings - Fork 13
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(vault): fix default network id setting #222
Conversation
Here's the code health analysis summary for commits Analysis Summary
|
set( | ||
produce((state) => { | ||
state.accounts[network][address] = { | ||
state.accounts[networkId][address] = { |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
library input
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the prototype pollution issue, we need to ensure that the networkId
parameter cannot be set to special property names like __proto__
, constructor
, or prototype
. We can achieve this by adding a check to reject these values before using them as keys in the state.accounts
object.
The best way to fix this without changing existing functionality is to add a validation step for networkId
in each function where it is used. If networkId
is one of the special property names, we can return early or throw an error.
-
Copy modified lines R22-R24 -
Copy modified lines R40-R42 -
Copy modified lines R55-R57 -
Copy modified lines R70-R72 -
Copy modified lines R85-R87
@@ -21,2 +21,5 @@ | ||
ensureAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -36,2 +39,5 @@ | ||
setAccountInfo: (networkId, address, accountInfo) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
const { accounts } = get() | ||
@@ -48,2 +54,5 @@ | ||
setTransactions: (networkId, address, transactions) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
const { accounts } = get() | ||
@@ -60,2 +69,5 @@ | ||
addAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -72,2 +84,5 @@ | ||
removeAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( |
set( | ||
produce((state) => { | ||
state.accounts[network][address] = { | ||
state.accounts[networkId][address] = { |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
library input
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the prototype pollution vulnerability, we need to ensure that networkId
cannot be set to special property names like __proto__
, constructor
, or prototype
. One way to achieve this is by adding a check to reject these values before using them as keys. Alternatively, we can use a Map
object instead of a plain object to store the accounts, as Map
does not have the same prototype pollution risks.
The best way to fix the problem without changing existing functionality is to add a check to reject special property names. This approach is straightforward and does not require significant changes to the existing code structure.
-
Copy modified lines R22-R24 -
Copy modified lines R52-R54 -
Copy modified lines R67-R69 -
Copy modified lines R82-R84
@@ -21,2 +21,5 @@ | ||
ensureAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -48,2 +51,5 @@ | ||
setTransactions: (networkId, address, transactions) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
const { accounts } = get() | ||
@@ -60,2 +66,5 @@ | ||
addAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -72,2 +81,5 @@ | ||
removeAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( |
state.accounts[network][address] = { | ||
if (!state.accounts?.[networkId]?.[address]) { | ||
state.accounts[networkId] = state.accounts[networkId] || {} | ||
state.accounts[networkId][address] = { |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
library input
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we need to ensure that networkId
cannot be used to manipulate the prototype of the object. One effective way to achieve this is by validating networkId
to ensure it does not contain any dangerous values like __proto__
, constructor
, or prototype
. Alternatively, we can use a Map
object instead of a plain object to store the accounts, as Map
is not vulnerable to prototype pollution.
The best way to fix the problem without changing existing functionality is to validate networkId
before using it as a key. We will add a check to ensure networkId
is not one of the dangerous values.
-
Copy modified lines R22-R24 -
Copy modified lines R40-R42 -
Copy modified lines R55-R57 -
Copy modified lines R70-R72 -
Copy modified lines R85-R87
@@ -21,2 +21,5 @@ | ||
ensureAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -36,2 +39,5 @@ | ||
setAccountInfo: (networkId, address, accountInfo) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
const { accounts } = get() | ||
@@ -48,2 +54,5 @@ | ||
setTransactions: (networkId, address, transactions) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
const { accounts } = get() | ||
@@ -60,2 +69,5 @@ | ||
addAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( | ||
@@ -72,2 +84,5 @@ | ||
removeAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
throw new Error('Invalid networkId'); | ||
} | ||
set( |
set( | ||
produce((state) => { | ||
delete state.accounts[network][address] | ||
delete state.accounts[networkId][address] |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
library input
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the prototype pollution vulnerability, we need to ensure that the networkId
parameter cannot be used to modify Object.prototype
. This can be achieved by validating the networkId
and rejecting any values that could lead to prototype pollution, such as __proto__
, constructor
, or prototype
.
The best way to fix this without changing existing functionality is to add a validation check for networkId
before it is used as a key in the state.accounts
object. If networkId
is one of the restricted values, we should return early or handle it appropriately.
-
Copy modified lines R22-R24 -
Copy modified lines R52-R54 -
Copy modified lines R67-R69 -
Copy modified lines R82-R84
@@ -21,2 +21,5 @@ | ||
ensureAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
return; | ||
} | ||
set( | ||
@@ -48,2 +51,5 @@ | ||
setTransactions: (networkId, address, transactions) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
return; | ||
} | ||
const { accounts } = get() | ||
@@ -60,2 +66,5 @@ | ||
addAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
return; | ||
} | ||
set( | ||
@@ -72,2 +81,5 @@ | ||
removeAccount: (networkId, address) => { | ||
if (networkId === '__proto__' || networkId === 'constructor' || networkId === 'prototype') { | ||
return; | ||
} | ||
set( |
Describe changes
Ticket or discussion link
Review checklist
Screenshots