Perf: bail out phishing calculation early

This commit is contained in:
SukkaW 2024-09-06 00:17:23 +08:00
parent f61804ff51
commit 48e8808511

View File

@ -100,7 +100,7 @@ const BLACK_TLD = new Set([
]); ]);
const WHITELIST_MAIN_DOMAINS = new Set([ const WHITELIST_MAIN_DOMAINS = new Set([
'w3s.link', // ipfs gateway // 'w3s.link', // ipfs gateway
// 'dweb.link', // ipfs gateway // 'dweb.link', // ipfs gateway
// 'nftstorage.link', // ipfs gateway // 'nftstorage.link', // ipfs gateway
'fleek.cool', // ipfs gateway 'fleek.cool', // ipfs gateway
@ -196,19 +196,22 @@ export const getPhishingDomains = (parentSpan: Span) => parentSpan.traceChild('g
domainScoreMap[apexDomain] += 2; domainScoreMap[apexDomain] += 2;
} }
} }
if (
subdomain
&& !WHITELIST_MAIN_DOMAINS.has(apexDomain)
) {
domainScoreMap[apexDomain] += calcDomainAbuseScore(subdomain); domainScoreMap[apexDomain] += calcDomainAbuseScore(subdomain);
} }
}
}); });
for (const domain in domainCountMap) { for (const apexDomain in domainCountMap) {
if ( if (
!WHITELIST_MAIN_DOMAINS.has(domain) // !WHITELIST_MAIN_DOMAINS.has(apexDomain)
&& ( domainScoreMap[apexDomain] >= 12
domainScoreMap[domain] >= 12 || (domainScoreMap[apexDomain] >= 5 && domainCountMap[apexDomain] >= 4)
|| (domainScoreMap[domain] >= 5 && domainCountMap[domain] >= 4)
)
) { ) {
domainArr.push(`.${domain}`); domainArr.push(`.${apexDomain}`);
} }
} }
@ -217,10 +220,9 @@ export const getPhishingDomains = (parentSpan: Span) => parentSpan.traceChild('g
return domainArr; return domainArr;
}); });
export function calcDomainAbuseScore(subdomain: string | null) { export function calcDomainAbuseScore(subdomain: string) {
let weight = 0; let weight = 0;
if (subdomain) {
const hitLowKeywords = lowKeywords(subdomain); const hitLowKeywords = lowKeywords(subdomain);
const sensitiveKeywordsHit = sensitiveKeywords(subdomain); const sensitiveKeywordsHit = sensitiveKeywords(subdomain);
@ -259,7 +261,6 @@ export function calcDomainAbuseScore(subdomain: string | null) {
} }
} }
} }
}
return weight; return weight;
} }