Skip to content

Commit 39c8361

Browse files
Odyssey98slient-coder
authored andcommitted
fix: increase phishing list update interval and remove fuzzy matching
fix: unisat blacklist update fix: remove unisatblacklist etag fix
1 parent 52907b9 commit 39c8361

File tree

2 files changed

+63
-45
lines changed

2 files changed

+63
-45
lines changed

src/background/service/phishing.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -272,51 +272,20 @@ class PhishingService {
272272
}
273273

274274
// Check permanent whitelist - enhanced check including subdomains
275-
// First check the full domain
276275
if (this.whitelistSet.has(cleanHostname)) {
277276
return false;
278277
}
279278

280279
// Then check if it's a subdomain of a whitelisted domain
281280
const domainParts = cleanHostname.split('.');
282281
if (domainParts.length > 2) {
283-
// Try to match main domain (e.g., mail.google.com -> google.com)
284282
const mainDomain = domainParts.slice(domainParts.length - 2).join('.');
285283
if (this.whitelistSet.has(mainDomain)) {
286284
return false;
287285
}
288286
}
289287

290-
// Check blacklist
291-
if (this.blacklistSet.has(cleanHostname)) {
292-
// Check domain length - unusually long domains are more likely to be phishing sites
293-
if (cleanHostname.length > 30) {
294-
return true;
295-
}
296-
297-
// If it's a common short domain, double-check
298-
if (cleanHostname.split('.').length <= 2 && cleanHostname.length < 15) {
299-
const tld = cleanHostname.split('.').pop();
300-
if (['com', 'org', 'net', 'io', 'app', 'dev'].includes(tld || '')) {
301-
// Add to temporary whitelist to avoid checking again
302-
this.temporaryWhitelist.add(cleanHostname);
303-
return false;
304-
}
305-
}
306-
307-
return true;
308-
}
309-
310-
// Check fuzzy match patterns (most expensive check last)
311-
if (this.config.fuzzylist && this.config.fuzzylist.length > 0) {
312-
for (const pattern of this.config.fuzzylist) {
313-
if (cleanHostname.includes(pattern)) {
314-
return true;
315-
}
316-
}
317-
}
318-
319-
return false;
288+
return this.blacklistSet.has(cleanHostname);
320289
} catch (error) {
321290
console.error('[PhishingService] Check error:', error);
322291
// Default to safe on error

src/background/utils/fetch.ts

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,47 @@ async function fetchWithTimeout(url: string, options: RequestInit = {}, timeoutM
6262
* @returns Phishing configuration object
6363
*/
6464
export const fetchPhishingList = async (forceRefresh = false): Promise<any> => {
65+
let cachedData: any = null;
66+
let useCache = false;
67+
6568
// If not forcing refresh, try to use cache first
6669
if (!forceRefresh) {
6770
try {
68-
const cachedData = await getFromLocalCache();
71+
cachedData = await getFromLocalCache();
6972
if (cachedData && cachedData.lastFetchTime) {
7073
const cacheAge = Date.now() - cachedData.lastFetchTime;
7174

72-
// If cache is fresh enough, use it directly
75+
// If cache is fresh enough, use it directly (but still fetch UNISAT)
7376
if (cacheAge < MIN_CACHE_AGE) {
7477
console.log('[Phishing] Using recent cache, age:', Math.round(cacheAge / 60000), 'minutes');
75-
return cachedData;
78+
useCache = true;
7679
}
7780
}
7881
} catch (error) {
7982
console.error('[Phishing] Cache check failed:', error);
8083
}
8184
}
8285

86+
// If using cache and not forcing refresh, return early for most sources
87+
// But always fetch UNISAT source
88+
if (useCache && !forceRefresh) {
89+
// Create a working copy of cached data for UNISAT updates
90+
const mergedData = JSON.parse(JSON.stringify(cachedData));
91+
92+
// Always fetch UNISAT source
93+
try {
94+
await fetchAndMergeUnisat(mergedData);
95+
96+
// Update the cache with the UNISAT updates
97+
await saveToLocalCache(mergedData);
98+
return mergedData;
99+
} catch (error) {
100+
console.error('[Phishing] UNISAT source fetch failed, using cache only:', error);
101+
return cachedData;
102+
}
103+
}
104+
105+
// If not using cache, fetch from all sources
83106
const fetchOptions: RequestInit = {
84107
cache: 'no-cache',
85108
headers: {
@@ -128,16 +151,10 @@ export const fetchPhishingList = async (forceRefresh = false): Promise<any> => {
128151
console.error('[Phishing] Backup source fetch failed:', error);
129152
}
130153

154+
// Always try to fetch UNISAT source
131155
try {
132-
const response = await fetchWithTimeout(PHISHING_SOURCES.UNISAT, fetchOptions);
133-
134-
if (response.ok) {
135-
const data = await response.json();
136-
mergePhishingData(mergedData, data);
137-
mergedData.sources.push('UNISAT');
138-
hasAnySourceSucceeded = true;
139-
console.log('[Phishing] Successfully fetched from UNISAT source');
140-
}
156+
await fetchAndMergeUnisat(mergedData);
157+
hasAnySourceSucceeded = true;
141158
} catch (error) {
142159
console.error('[Phishing] Unisat source fetch failed:', error);
143160
}
@@ -150,7 +167,7 @@ export const fetchPhishingList = async (forceRefresh = false): Promise<any> => {
150167

151168
// All remote sources failed, try using cache (regardless of age)
152169
try {
153-
const cachedData = await getFromLocalCache();
170+
cachedData = await getFromLocalCache();
154171
if (cachedData) {
155172
console.warn('[Phishing] Using cached data as all remote sources failed');
156173
return cachedData;
@@ -163,6 +180,38 @@ export const fetchPhishingList = async (forceRefresh = false): Promise<any> => {
163180
throw new Error('Failed to fetch phishing list from all available sources');
164181
};
165182

183+
/**
184+
* Fetches UNISAT phishing list and merges it into target data
185+
* This function is separated to allow always fetching UNISAT data
186+
* @param targetData The data object to merge UNISAT data into
187+
* @returns Promise<boolean> indicating success
188+
*/
189+
async function fetchAndMergeUnisat(targetData: any): Promise<boolean> {
190+
const fetchOptions: RequestInit = {
191+
cache: 'no-cache',
192+
headers: {
193+
Accept: 'application/json'
194+
}
195+
};
196+
197+
const response = await fetchWithTimeout(PHISHING_SOURCES.UNISAT, fetchOptions);
198+
199+
if (response.ok) {
200+
const data = await response.json();
201+
mergePhishingData(targetData, data);
202+
203+
// Only add to sources if not already there
204+
if (!targetData.sources.includes('UNISAT')) {
205+
targetData.sources.push('UNISAT');
206+
}
207+
208+
console.log('[Phishing] Successfully fetched from UNISAT source');
209+
return true;
210+
}
211+
212+
throw new Error('Failed to fetch from UNISAT source');
213+
}
214+
166215
function mergePhishingData(target: any, source: any): void {
167216
if (Array.isArray(source.blacklist)) {
168217
target.blacklist = [...new Set([...target.blacklist, ...source.blacklist])];

0 commit comments

Comments
 (0)