aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/is-phish.js
blob: ce51c353d05a2a6915dabf71d42d6d2aa23d5433 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const levenshtein = require('fast-levenshtein')
const LEVENSHTEIN_TOLERANCE = 4

// credit to @sogoiii and @409H for their help!
// Return a boolean on whether or not a phish is detected.
function isPhish({ hostname, blacklist, whitelist, fuzzylist }) {

  // check if the domain is part of the whitelist.
  if (whitelist && whitelist.includes(hostname)) return false

  // check if the domain is part of the blacklist.
  if (blacklist && blacklist.includes(hostname)) return true

  // check for similar values.
  const levenshteinForm = hostname.replace(/\./g, '')
  const levenshteinMatched = fuzzylist.some((element) => {
    return levenshtein.get(element, levenshteinForm) <= LEVENSHTEIN_TOLERANCE
  })

  return levenshteinMatched
}

module.exports = isPhish