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)
|
||||
function connectRemote (remotePort) {
|
||||
if (remotePort.name === 'blacklister') {
|
||||
return setupBlacklist(connectRemote)
|
||||
}
|
||||
|
||||
var isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification'
|
||||
var portStream = new PortStream(remotePort)
|
||||
if (isMetaMaskInternalProcess) {
|
||||
@ -135,6 +139,29 @@ function setupController (initState) {
|
||||
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...
|
||||
//
|
||||
|
@ -1,13 +1,16 @@
|
||||
const blacklistedDomains = require('etheraddresslookup/blacklists/domains.json')
|
||||
const extension = require('extensionizer')
|
||||
console.log('blacklister content script loaded.')
|
||||
|
||||
function detectBlacklistedDomain() {
|
||||
var strCurrentTab = window.location.hostname
|
||||
if (blacklistedDomains && blacklistedDomains.includes(strCurrentTab)) {
|
||||
const port = extension.runtime.connect({ name: 'blacklister' })
|
||||
port.postMessage({ 'pageLoaded': window.location.hostname })
|
||||
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.addEventListener('load', function() {
|
||||
detectBlacklistedDomain()
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
const ObservableStore = require('obs-store')
|
||||
const extend = require('xtend')
|
||||
const recentBlacklist = require('etheraddresslookup/blacklists/domains.json')
|
||||
|
||||
// every ten minutes
|
||||
const POLLING_INTERVAL = 300000
|
||||
@ -9,6 +10,7 @@ class InfuraController {
|
||||
constructor (opts = {}) {
|
||||
const initState = extend({
|
||||
infuraNetworkStatus: {},
|
||||
blacklist: recentBlacklist,
|
||||
}, opts.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 () {
|
||||
if (this.conversionInterval) {
|
||||
clearInterval(this.conversionInterval)
|
||||
}
|
||||
this.conversionInterval = setInterval(() => {
|
||||
this.checkInfuraNetworkStatus()
|
||||
this.updateLocalBlacklist()
|
||||
}, POLLING_INTERVAL)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user