1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Live update blacklist from Infura

This commit is contained in:
Dan Finlay 2017-07-26 16:30:54 -07:00
parent f147b928b2
commit 8b1726cc55
5 changed files with 17 additions and 13 deletions

View File

@ -2,6 +2,8 @@
## Current Master
- Continuously update blacklist for known phishing sites in background.
## 3.9.2 2017-7-26
- Fix bugs that could sometimes result in failed transactions after switching networks.

View File

@ -55,8 +55,13 @@
},
{
"run_at": "document_start",
"matches": ["http://*/*", "https://*/*"],
"js": ["scripts/blacklister.js"]
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"js": ["scripts/blacklister.js"],
"all_frames": true
}
],
"permissions": [

View File

@ -91,7 +91,7 @@ function setupController (initState) {
extension.runtime.onConnect.addListener(connectRemote)
function connectRemote (remotePort) {
if (remotePort.name === 'blacklister') {
return setupBlacklist(connectRemote)
return checkBlacklist(remotePort)
}
var isMetaMaskInternalProcess = remotePort.name === 'popup' || remotePort.name === 'notification'
@ -140,25 +140,23 @@ function setupController (initState) {
}
// Listen for new pages and return if blacklisted:
function setupBlacklist (port) {
console.log('Blacklist connection established')
const handler = handleNewPageLoad.bind(port)
function checkBlacklist (port) {
const handler = handleNewPageLoad.bind(null, port)
port.onMessage.addListener(handler)
setTimeout(() => {
port.onMessage.removeListener(handler)
}, 30000)
}
function handleNewPageLoad (message) {
function handleNewPageLoad (port, 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
const { blacklist } = state
if (blacklist && blacklist.includes(pageLoaded)) {
this.postMessage({ 'blacklist': pageLoaded })
port.postMessage({ 'blacklist': pageLoaded })
}
}

View File

@ -1,13 +1,11 @@
const extension = require('extensionizer')
console.log('blacklister content script loaded.')
const port = extension.runtime.connect({ name: 'blacklister' })
var 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'

View File

@ -65,3 +65,4 @@ function restoreContextAfterImports () {
console.warn('MetaMask - global.define could not be overwritten.')
}
}