diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-07-28 06:22:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-28 06:22:09 +0800 |
commit | d15e402ed87bf7533250c49a7972a7b1a12c99c2 (patch) | |
tree | 3bbeb674eb53c7dc7a9f616c75b63825cbe2848f /app/scripts/lib | |
parent | e3b5bb2052d59afbf9c2761af883de719261062e (diff) | |
parent | 7c71ee1babcaad19dbe7db6c5abfefe2f9654781 (diff) | |
download | tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar.gz tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar.bz2 tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar.lz tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar.xz tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.tar.zst tangerine-wallet-browser-d15e402ed87bf7533250c49a7972a7b1a12c99c2.zip |
Merge pull request #1838 from MetaMask/i1805-LiveBlacklistUpdating
Live blacklist updating
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/is-phish.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/scripts/lib/is-phish.js b/app/scripts/lib/is-phish.js new file mode 100644 index 000000000..68c09e4ac --- /dev/null +++ b/app/scripts/lib/is-phish.js @@ -0,0 +1,38 @@ +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, updatedBlacklist = null }) { + var strCurrentTab = hostname + + // check if the domain is part of the whitelist. + if (whitelistedDomains && whitelistedDomains.includes(strCurrentTab)) { return false } + + // Allow updating of blacklist: + if (updatedBlacklist) { + blacklistedDomains = blacklistedDomains.concat(updatedBlacklist) + } + + // check if the domain is part of the blacklist. + const isBlacklisted = blacklistedDomains && blacklistedDomains.includes(strCurrentTab) + + // 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 + } + }) + + return isBlacklisted || levenshteinMatched +} + +module.exports = isPhish |