Fix signTypedData_v4 chainId param validation (#9552)

feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent 5b8c07817a
commit 45ba657ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/scripts/lib/typed-message-manager.js
  2. 4
      app/scripts/metamask-controller.js
  3. 6
      test/unit/app/typed-message-manager.spec.js

@ -32,9 +32,9 @@ export default class TypedMessageManager extends EventEmitter {
/** /**
* Controller in charge of managing - storing, adding, removing, updating - TypedMessage. * Controller in charge of managing - storing, adding, removing, updating - TypedMessage.
*/ */
constructor ({ networkController }) { constructor ({ getCurrentChainId }) {
super() super()
this.networkController = networkController this._getCurrentChainId = getCurrentChainId
this.memStore = new ObservableStore({ this.memStore = new ObservableStore({
unapprovedTypedMessages: {}, unapprovedTypedMessages: {},
unapprovedTypedMessagesCount: 0, unapprovedTypedMessagesCount: 0,
@ -167,8 +167,7 @@ export default class TypedMessageManager extends EventEmitter {
assert.equal(validation.errors.length, 0, 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.') assert.equal(validation.errors.length, 0, 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.')
const { chainId } = data.domain const { chainId } = data.domain
if (chainId) { if (chainId) {
// eslint-disable-next-line radix const activeChainId = parseInt(this._getCurrentChainId(), 16)
const activeChainId = parseInt(this.networkController.getNetworkState())
assert.ok(!Number.isNaN(activeChainId), `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`) assert.ok(!Number.isNaN(activeChainId), `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`)
assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`) assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`)
} }

@ -290,7 +290,9 @@ export default class MetamaskController extends EventEmitter {
this.personalMessageManager = new PersonalMessageManager() this.personalMessageManager = new PersonalMessageManager()
this.decryptMessageManager = new DecryptMessageManager() this.decryptMessageManager = new DecryptMessageManager()
this.encryptionPublicKeyManager = new EncryptionPublicKeyManager() this.encryptionPublicKeyManager = new EncryptionPublicKeyManager()
this.typedMessageManager = new TypedMessageManager({ networkController: this.networkController }) this.typedMessageManager = new TypedMessageManager({
getCurrentChainId: this.networkController.getCurrentChainId.bind(this.networkController),
})
this.swapsController = new SwapsController({ this.swapsController = new SwapsController({
getBufferedGasLimit: this.txController.txGasUtil.getBufferedGasLimit.bind(this.txController.txGasUtil), getBufferedGasLimit: this.txController.txGasUtil.getBufferedGasLimit.bind(this.txController.txGasUtil),

@ -1,6 +1,5 @@
import assert from 'assert' import assert from 'assert'
import sinon from 'sinon' import sinon from 'sinon'
import NetworkController from '../../../app/scripts/controllers/network'
import TypedMessageManager from '../../../app/scripts/lib/typed-message-manager' import TypedMessageManager from '../../../app/scripts/lib/typed-message-manager'
describe('Typed Message Manager', function () { describe('Typed Message Manager', function () {
@ -9,11 +8,8 @@ describe('Typed Message Manager', function () {
const address = '0xc42edfcc21ed14dda456aa0756c153f7985d8813' const address = '0xc42edfcc21ed14dda456aa0756c153f7985d8813'
beforeEach(async function () { beforeEach(async function () {
const networkController = new NetworkController()
sinon.stub(networkController, 'getNetworkState').returns('0x1')
typedMessageManager = new TypedMessageManager({ typedMessageManager = new TypedMessageManager({
networkController, getCurrentChainId: sinon.fake.returns('0x1'),
}) })
msgParamsV1 = { msgParamsV1 = {

Loading…
Cancel
Save