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:
parent
f7e4e209ef
commit
27e1189c91
@ -44,9 +44,10 @@ export default function setupWeb3 (log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldLogUsage) {
|
if (shouldLogUsage) {
|
||||||
|
const name = stringifyKey(key)
|
||||||
window.ethereum.request({
|
window.ethereum.request({
|
||||||
method: 'metamask_logInjectedWeb3Usage',
|
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]
|
return _web3[key]
|
||||||
},
|
},
|
||||||
set: (_web3, key, value) => {
|
set: (_web3, key, value) => {
|
||||||
|
const name = stringifyKey(key)
|
||||||
if (shouldLogUsage) {
|
if (shouldLogUsage) {
|
||||||
window.ethereum.request({
|
window.ethereum.request({
|
||||||
method: 'metamask_logInjectedWeb3Usage',
|
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 () {
|
function triggerReset () {
|
||||||
global.location.reload()
|
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}`
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user