diff options
author | kumavis <aaron@kumavis.me> | 2017-08-03 06:54:59 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2017-08-03 06:54:59 +0800 |
commit | 8c6f01b91094564df59d6d95b6f43b811e711824 (patch) | |
tree | 19ed66e8fd54b4324d8e5750de061c6562ace19b /app/scripts/lib | |
parent | ecaa235b5e3331defab75dad72593951fdf37790 (diff) | |
download | tangerine-wallet-browser-8c6f01b91094564df59d6d95b6f43b811e711824.tar.gz tangerine-wallet-browser-8c6f01b91094564df59d6d95b6f43b811e711824.tar.zst tangerine-wallet-browser-8c6f01b91094564df59d6d95b6f43b811e711824.zip |
blacklist controller - breakout from metamask and infura controllers
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/is-phish.js | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/app/scripts/lib/is-phish.js b/app/scripts/lib/is-phish.js index 21c68b0d6..ce51c353d 100644 --- a/app/scripts/lib/is-phish.js +++ b/app/scripts/lib/is-phish.js @@ -1,38 +1,23 @@ const levenshtein = require('fast-levenshtein') -const blacklistedMetaMaskDomains = ['metamask.com'] -let blacklistedDomains = require('etheraddresslookup/blacklists/domains.json').concat(blacklistedMetaMaskDomains) -const whitelistedMetaMaskDomains = ['metamask.io', 'www.metamask.io'] -const whitelistedDomains = require('etheraddresslookup/whitelists/domains.json').concat(whitelistedMetaMaskDomains) const LEVENSHTEIN_TOLERANCE = 4 -const LEVENSHTEIN_CHECKS = ['myetherwallet', 'myetheroll', 'ledgerwallet', 'metamask'] - // credit to @sogoiii and @409H for their help! // Return a boolean on whether or not a phish is detected. -function isPhish({ hostname, blacklist }) { - var strCurrentTab = hostname +function isPhish({ hostname, blacklist, whitelist, fuzzylist }) { // check if the domain is part of the whitelist. - if (whitelistedDomains && whitelistedDomains.includes(strCurrentTab)) { return false } - - // Allow updating of blacklist: - if (blacklist) { - blacklistedDomains = blacklistedDomains.concat(blacklist) - } + if (whitelist && whitelist.includes(hostname)) return false // check if the domain is part of the blacklist. - const isBlacklisted = blacklistedDomains && blacklistedDomains.includes(strCurrentTab) + if (blacklist && blacklist.includes(hostname)) return true // check for similar values. - let levenshteinMatched = false - var levenshteinForm = strCurrentTab.replace(/\./g, '') - LEVENSHTEIN_CHECKS.forEach((element) => { - if (levenshtein.get(element, levenshteinForm) <= LEVENSHTEIN_TOLERANCE) { - levenshteinMatched = true - } + const levenshteinForm = hostname.replace(/\./g, '') + const levenshteinMatched = fuzzylist.some((element) => { + return levenshtein.get(element, levenshteinForm) <= LEVENSHTEIN_TOLERANCE }) - return isBlacklisted || levenshteinMatched + return levenshteinMatched } module.exports = isPhish |