Skip to content

Scam Detector fix false positive #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"steamcommunity",
"freenitro",
"usd",
"earn",
"^earn",
".exe"
],
"hostWhitelist": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ private boolean containsSuspiciousKeyword(String token) {
return config.getSuspiciousKeywords()
.stream()
.map(keyword -> keyword.toLowerCase(Locale.US))
.anyMatch(preparedToken::contains);
.anyMatch(keyword -> {
// Simple regex-inspired syntax "^foo"
if (!keyword.isEmpty() && keyword.charAt(0) == '^') {
return preparedToken.startsWith(keyword.substring(1));
} else {
return preparedToken.contains(keyword);
}
});
}

private boolean isHostSimilarToKeyword(String host, String keyword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void setUp() {
ScamBlockerConfig scamConfig = mock(ScamBlockerConfig.class);
when(config.getScamBlocker()).thenReturn(scamConfig);

when(scamConfig.getSuspiciousKeywords())
.thenReturn(Set.of("nitro", "boob", "sexy", "sexi", "esex", "steam", "gift", "onlyfans",
"bitcoin", "btc", "promo", "trader", "trading", "whatsapp", "crypto", "claim",
"teen", "adobe", "hack", "steamcommunity", "freenitro", "usd", "earn", ".exe"));
when(scamConfig.getSuspiciousKeywords()).thenReturn(Set.of("nitro", "boob", "sexy", "sexi",
"esex", "steam", "gift", "onlyfans", "bitcoin", "btc", "promo", "trader", "trading",
"whatsapp", "crypto", "claim", "teen", "adobe", "hack", "steamcommunity",
"freenitro", "usd", "^earn", ".exe"));
when(scamConfig.getHostWhitelist()).thenReturn(Set.of("discord.com", "discord.media",
"discordapp.com", "discordapp.net", "discordstatus.com"));
when(scamConfig.getHostBlacklist()).thenReturn(Set.of("bit.ly", "discord.gg", "teletype.in",
Expand All @@ -54,6 +54,18 @@ void detectsRealScam(String scamMessage) {
assertTrue(isScamResult);
}

@ParameterizedTest
@MethodSource("provideRealFalsePositiveMessages")
@DisplayName("Can ignore real false positive messages")
void ignoresFalsePositives(String falsePositiveMessage) {
// GIVEN a real false positive message
// WHEN analyzing it
boolean isScamResult = scamDetector.isScam(falsePositiveMessage);

// THEN does not flag it as scam
assertFalse(isScamResult);
}

@Test
@DisplayName("Can detect messages that contain blacklisted websites as scam")
void detectsBlacklistedWebsite() {
Expand Down Expand Up @@ -227,4 +239,10 @@ private static List<String> provideRealScamMessages() {
"Urgently looking for mods & collab managers https://discord.gg/cryptohireo",
"Check this - https://transfer.sh/get/ajmkh3l7tzop/Setup.exe");
}

private static List<String> provideRealFalsePositiveMessages() {
return List
.of("""
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types""");
}
}
Loading