mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Hook MetaMaskController up with phishing detection page
This commit is contained in:
parent
58d856bd84
commit
c92fee7771
@ -1,6 +1,7 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const pump = require('pump')
|
const pump = require('pump')
|
||||||
|
const querystring = require('querystring')
|
||||||
const LocalMessageDuplexStream = require('post-message-stream')
|
const LocalMessageDuplexStream = require('post-message-stream')
|
||||||
const PongStream = require('ping-pong-stream/pong')
|
const PongStream = require('ping-pong-stream/pong')
|
||||||
const ObjectMultiplex = require('obj-multiplex')
|
const ObjectMultiplex = require('obj-multiplex')
|
||||||
@ -199,5 +200,8 @@ function blacklistedDomainCheck () {
|
|||||||
function redirectToPhishingWarning () {
|
function redirectToPhishingWarning () {
|
||||||
console.log('MetaMask - routing to Phishing Warning component')
|
console.log('MetaMask - routing to Phishing Warning component')
|
||||||
const extensionURL = extension.runtime.getURL('phishing.html')
|
const extensionURL = extension.runtime.getURL('phishing.html')
|
||||||
window.location.href = extensionURL + '#' + window.location.hostname
|
window.location.href = `${extensionURL}#${querystring.stringify({
|
||||||
|
hostname: window.location.hostname,
|
||||||
|
href: window.location.href,
|
||||||
|
})}`
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,59 @@
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (window.location.pathname === '/phishing.html') {
|
if (window.location.pathname === '/phishing.html') {
|
||||||
document.getElementById('esdbLink').innerHTML = '<b>To read more about this scam, navigate to: <a href="https://etherscamdb.info/domain/' + window.location.hash.substring(1) + '"> https://etherscamdb.info/domain/' + window.location.hash.substring(1) + '</a></b>'
|
const {hostname} = parseHash()
|
||||||
|
document.getElementById('esdbLink').innerHTML = '<b>To read more about this scam, navigate to: <a href="https://etherscamdb.info/domain/' + hostname + '"> https://etherscamdb.info/domain/' + hostname + '</a></b>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const querystring = require('querystring')
|
||||||
|
const dnode = require('dnode')
|
||||||
|
const { EventEmitter } = require('events')
|
||||||
|
const PortStream = require('extension-port-stream')
|
||||||
|
const extension = require('extensionizer')
|
||||||
|
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||||
|
const { getEnvironmentType } = require('./lib/util')
|
||||||
|
const ExtensionPlatform = require('./platforms/extension')
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', start)
|
||||||
|
|
||||||
|
function start () {
|
||||||
|
const windowType = getEnvironmentType(window.location.href)
|
||||||
|
|
||||||
|
global.platform = new ExtensionPlatform()
|
||||||
|
global.METAMASK_UI_TYPE = windowType
|
||||||
|
|
||||||
|
const extensionPort = extension.runtime.connect({ name: windowType })
|
||||||
|
const connectionStream = new PortStream(extensionPort)
|
||||||
|
const mx = setupMultiplex(connectionStream)
|
||||||
|
setupControllerConnection(mx.createStream('controller'), (err, metaMaskController) => {
|
||||||
|
if (err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const suspect = parseHash()
|
||||||
|
const unsafeContinue = () => {
|
||||||
|
window.location.href = suspect.href
|
||||||
|
}
|
||||||
|
const continueLink = document.getElementById('unsafe-continue')
|
||||||
|
continueLink.addEventListener('click', () => {
|
||||||
|
metaMaskController.whitelistPhishingDomain(suspect.hostname)
|
||||||
|
unsafeContinue()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupControllerConnection (connectionStream, cb) {
|
||||||
|
const eventEmitter = new EventEmitter()
|
||||||
|
const accountManagerDnode = dnode({
|
||||||
|
sendUpdate (state) {
|
||||||
|
eventEmitter.emit('update', state)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
|
||||||
|
accountManagerDnode.once('remote', (accountManager) => cb(null, accountManager))
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseHash () {
|
||||||
|
const hash = window.location.hash.substring(1)
|
||||||
|
return querystring.parse(hash)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user