mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Begin implementing live-updating blacklist, not working yet
This commit is contained in:
parent
0deb617d8f
commit
3d8ebf2265
@ -90,6 +90,10 @@ function setupController (initState) {
|
|||||||
|
|
||||||
extension.runtime.onConnect.addListener(connectRemote)
|
extension.runtime.onConnect.addListener(connectRemote)
|
||||||
function connectRemote (remotePort) {
|
function connectRemote (remotePort) {
|
||||||
|
if (remotePort.name === 'blacklister') {
|
||||||
|
return setupBlacklist(connectRemote)
|
||||||
|
}
|
||||||
|
|
||||||
var isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification'
|
var isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification'
|
||||||
var portStream = new PortStream(remotePort)
|
var portStream = new PortStream(remotePort)
|
||||||
if (isMetaMaskInternalProcess) {
|
if (isMetaMaskInternalProcess) {
|
||||||
@ -135,6 +139,29 @@ function setupController (initState) {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Listen for new pages and return if blacklisted:
|
||||||
|
function setupBlacklist (port) {
|
||||||
|
console.log('Blacklist connection established')
|
||||||
|
const handler = handleNewPageLoad.bind(port)
|
||||||
|
port.onMessage.addListener(handler)
|
||||||
|
setTimeout(() => {
|
||||||
|
port.onMessage.removeListener(handler)
|
||||||
|
}, 30000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleNewPageLoad (message) {
|
||||||
|
const { pageLoaded } = message
|
||||||
|
console.log('blaclist message received', message.pageLoaded)
|
||||||
|
if (!pageLoaded || !global.metamaskController) return
|
||||||
|
|
||||||
|
const state = global.metamaskController.getState()
|
||||||
|
const { blacklist } = state.metamask
|
||||||
|
|
||||||
|
if (blacklist && blacklist.includes(pageLoaded)) {
|
||||||
|
this.postMessage({ 'blacklist': pageLoaded })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Etc...
|
// Etc...
|
||||||
//
|
//
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
const blacklistedDomains = require('etheraddresslookup/blacklists/domains.json')
|
const extension = require('extensionizer')
|
||||||
|
console.log('blacklister content script loaded.')
|
||||||
|
|
||||||
function detectBlacklistedDomain() {
|
const port = extension.runtime.connect({ name: 'blacklister' })
|
||||||
var strCurrentTab = window.location.hostname
|
port.postMessage({ 'pageLoaded': window.location.hostname })
|
||||||
if (blacklistedDomains && blacklistedDomains.includes(strCurrentTab)) {
|
port.onMessage.addListener(redirectIfBlacklisted)
|
||||||
|
|
||||||
|
function redirectIfBlacklisted (response) {
|
||||||
|
const { blacklist } = response
|
||||||
|
console.log('blacklister contentscript received blacklist response')
|
||||||
|
const host = window.location.hostname
|
||||||
|
if (blacklist && blacklist === host) {
|
||||||
window.location.href = 'https://metamask.io/phishing.html'
|
window.location.href = 'https://metamask.io/phishing.html'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', function() {
|
|
||||||
detectBlacklistedDomain()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
|
const recentBlacklist = require('etheraddresslookup/blacklists/domains.json')
|
||||||
|
|
||||||
// every ten minutes
|
// every ten minutes
|
||||||
const POLLING_INTERVAL = 300000
|
const POLLING_INTERVAL = 300000
|
||||||
@ -9,6 +10,7 @@ class InfuraController {
|
|||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
const initState = extend({
|
const initState = extend({
|
||||||
infuraNetworkStatus: {},
|
infuraNetworkStatus: {},
|
||||||
|
blacklist: recentBlacklist,
|
||||||
}, opts.initState)
|
}, opts.initState)
|
||||||
this.store = new ObservableStore(initState)
|
this.store = new ObservableStore(initState)
|
||||||
}
|
}
|
||||||
@ -30,12 +32,24 @@ class InfuraController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLocalBlacklist () {
|
||||||
|
return fetch('https://api.infura.io/v1/blacklist')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then((parsedResponse) => {
|
||||||
|
this.store.updateState({
|
||||||
|
blacklist: parsedResponse,
|
||||||
|
})
|
||||||
|
return parsedResponse
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
scheduleInfuraNetworkCheck () {
|
scheduleInfuraNetworkCheck () {
|
||||||
if (this.conversionInterval) {
|
if (this.conversionInterval) {
|
||||||
clearInterval(this.conversionInterval)
|
clearInterval(this.conversionInterval)
|
||||||
}
|
}
|
||||||
this.conversionInterval = setInterval(() => {
|
this.conversionInterval = setInterval(() => {
|
||||||
this.checkInfuraNetworkStatus()
|
this.checkInfuraNetworkStatus()
|
||||||
|
this.updateLocalBlacklist()
|
||||||
}, POLLING_INTERVAL)
|
}, POLLING_INTERVAL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user