1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Handle non-String web3 property access (#9256)

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
This commit is contained in:
Mark Stacey 2020-08-18 12:01:43 -03:00 committed by GitHub
parent f7e4e209ef
commit 27e1189c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,9 +44,10 @@ export default function setupWeb3 (log) {
}
if (shouldLogUsage) {
const name = stringifyKey(key)
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 get', name: key }],
params: [{ action: 'window.web3 get', name }],
})
}
@ -54,11 +55,11 @@ export default function setupWeb3 (log) {
return _web3[key]
},
set: (_web3, key, value) => {
const name = stringifyKey(key)
if (shouldLogUsage) {
window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage',
params: [{ action: 'window.web3 set', name: key }],
params: [{ action: 'window.web3 set', name }],
})
}
@ -120,3 +121,15 @@ export default function setupWeb3 (log) {
function triggerReset () {
global.location.reload()
}
/**
* Returns a "stringified" key. Keys that are already strings are returned
* unchanged, and any non-string values are returned as "typeof <type>".
*
* @param {any} key - The key to stringify
*/
function stringifyKey (key) {
return typeof key === 'string'
? key
: `typeof ${typeof key}`
}