Skip to content

Commit 9076f04

Browse files
authored
Merge pull request #25 from ctnkaan/more-links
implemented more scam link types
2 parents 79049a7 + 614ddcc commit 9076f04

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/commands/scamLinkDetector.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export = {
77
name: "scamLinkDetector",
88
description: "Detects scam links",
99
callback: (message: MessageType) => {
10-
const banned_words: string[] = ["nitro", "i leave from cs:go"];
10+
const banned_words: string[] = [
11+
"nitro",
12+
"i leave from cs:go",
13+
"mediafire"
14+
];
1115
let isScamLink: boolean = false;
1216

1317
//search spam word in message.content
@@ -31,6 +35,8 @@ export = {
3135
const suspiciousLinks: string[] = [];
3236
links.forEach((l) => {
3337
const isSus = isSuspiciousLink(l);
38+
console.log(l, isSus);
39+
3440
if (isSus) {
3541
suspiciousLinks.push(l);
3642
}

src/util/isSuspiciousLink.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { distance } from "fastest-levenshtein";
22
import 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(/^https?:\/\/(\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

2530
export { isSuspiciousLink };

0 commit comments

Comments
 (0)