Skip to content

Commit

Permalink
Handle non-String web3 property access
Browse files Browse the repository at this point in the history
The web3 usage metrics added in #9144 assumed that all web3 properties
were strings. When a `Symbol` property is accessed, our `inpage.js`
script crashes because the `Symbol` cannot be serialized correctly.

A check has been added for non-string property access. The metric event
in these cases is set to the string "typeof ", followed by the type of
the key. (e.g. `typeof symbol` for a `Symbol` property).

Fixes #9234
  • Loading branch information
Gudahtt committed Aug 18, 2020
1 parent a89b667 commit 7ff6754
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/scripts/lib/setupWeb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,26 @@ export default function setupWeb3 (log) {
}

if (shouldLogUsage) {
const name = typeof key === 'string'
? key
: `typeof ${typeof key}`
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 get', name: key }],
params: [{ action: 'window.web3 get', name }],
})
}

// return value normally
return _web3[key]
},
set: (_web3, key, value) => {

const name = typeof key === 'string'
? key
: `typeof ${typeof key}`
if (shouldLogUsage) {
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 set', name: key }],
params: [{ action: 'window.web3 set', name }],
})
}

Expand Down

0 comments on commit 7ff6754

Please sign in to comment.