@@ -2,9 +2,10 @@ import { distance } from "fastest-levenshtein";
22import config from "../config" ;
33
44/** Most spam links try to typosquat 'discord' to trick users into thinking the link is safe (ex: "discorde")*/
5- const TYPOSQUAT_TARGET = "discord" ;
5+ const TYPOSQUAT_TARGET = [ "discord" , "github" , "steam" ] ;
6+ let susometer = false ;
67
7- function isSuspiciousLink ( link , threshold = 4 ) {
8+ function isSuspiciousLink ( link : string , threshold = 4 ) {
89 // get base domain
910 const matches = link . match ( / ^ h t t p s ? : \/ \/ ( \S + ?) \. / ) ;
1011 if ( ! matches ) return ;
@@ -13,13 +14,17 @@ function isSuspiciousLink(link, threshold = 4) {
1314 // expempt whitelist
1415 if ( config . whitelist . includes ( base ) ) return false ;
1516
16- // check levenshtein distance of domain to "discord"
17- const d = distance ( TYPOSQUAT_TARGET , base ) ;
18- // if distance is > 0 and < threshold, base is typosquating. Call foul
19- if ( d > 0 && d <= threshold ) {
20- return true ;
21- }
22- return false ;
17+ // check levenshtein distance of domain to all typosquat targets
18+
19+ TYPOSQUAT_TARGET . forEach ( ( element ) => {
20+ const d = distance ( element , base ) ;
21+ // if distance is > 0 and < threshold, base is typosquating. Call foul
22+ if ( d > 0 && d <= threshold ) {
23+ susometer = true ;
24+ }
25+ } ) ;
26+
27+ return susometer ;
2328}
2429
2530export { isSuspiciousLink } ;
0 commit comments