Feat: reject hosts accept third-party

This commit is contained in:
SukkaW 2024-09-23 09:56:07 +08:00
parent b91747e07f
commit ce95a2414a
2 changed files with 27 additions and 20 deletions

View File

@ -9,7 +9,8 @@ export const HOSTS: HostsSource[] = [
['https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt', null, true, TTL.TWO_WEEKS()],
['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', null, false, TTL.THREE_DAYS()],
['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-AdBlock.txt', null, false, TTL.THREE_DAYS()],
['https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', null, true, TTL.THREE_HOURS()]
['https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', null, true, TTL.THREE_HOURS()],
['https://raw.githubusercontent.com/durablenapkin/block/refs/heads/master/tvstream.txt', null, true, TTL.THREE_HOURS()]
];
export const HOSTS_EXTRA: HostsSource[] = [
@ -29,17 +30,7 @@ export const HOSTS_EXTRA: HostsSource[] = [
export const DOMAIN_LISTS: HostsSource[] = [
// CoinBlockerList
// Although the hosts file is still actively maintained, the hosts_browser file is not updated since 2021-07, so we set a 14 days cache ttl
['https://zerodot1.gitlab.io/CoinBlockerLists/list_browser.txt', [], true, TTL.TWO_WEEKS()],
// Curben's UrlHaus Malicious URL Blocklist
[
'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-domains.txt',
[
'https://urlhaus-filter.pages.dev/urlhaus-filter-domains.txt',
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-domains.txt'
],
true, TTL.THREE_HOURS()
]
['https://zerodot1.gitlab.io/CoinBlockerLists/list_browser.txt', [], true, TTL.TWO_WEEKS()]
];
export const DOMAIN_LISTS_EXTRA: HostsSource[] = [
@ -67,6 +58,15 @@ export const DOMAIN_LISTS_EXTRA: HostsSource[] = [
'https://malware-filter.gitlab.io/pup-filter/pup-filter-domains.txt'
],
true, TTL.TWO_WEEKS()
],
// Curben's UrlHaus Malicious URL Blocklist
[
'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-domains.txt',
[
'https://urlhaus-filter.pages.dev/urlhaus-filter-domains.txt',
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-domains.txt'
],
true, TTL.THREE_HOURS()
]
];
@ -86,7 +86,7 @@ export const PHISHING_DOMAIN_LISTS_EXTRA: [HostsSource, HostsSource] = [
]
];
type AdGuardFilterSource = [main: string, mirrors: string[] | null, ttl: number];
type AdGuardFilterSource = [main: string, mirrors: string[] | null, ttl: number, allowThirdParty?: boolean];
export const ADGUARD_FILTERS: AdGuardFilterSource[] = [
// EasyList
@ -151,9 +151,9 @@ export const ADGUARD_FILTERS: AdGuardFilterSource[] = [
export const ADGUARD_FILTERS_EXTRA: AdGuardFilterSource[] = [
// AdGuard Annoyances filter
['https://filters.adtidy.org/android/filters/14_optimized.txt', null, TTL.THREE_HOURS()],
['https://filters.adtidy.org/android/filters/14_optimized.txt', null, TTL.THREE_HOURS(), true],
// AdGuard Cookie Notices
['https://filters.adtidy.org/extension/ublock/filters/18_optimized.txt', null, TTL.THREE_HOURS()],
['https://filters.adtidy.org/extension/ublock/filters/18_optimized.txt', null, TTL.THREE_HOURS(), true],
// EasyList Germany filter
[
'https://easylist.to/easylistgermany/easylistgermany.txt',
@ -173,9 +173,10 @@ export const ADGUARD_FILTERS_EXTRA: AdGuardFilterSource[] = [
TTL.THREE_HOURS()
],
// AdGuard Popup Overlay
['https://filters.adtidy.org/extension/ublock/filters/19_optimized.txt', null, TTL.THREE_HOURS()],
['https://filters.adtidy.org/extension/ublock/filters/19_optimized.txt', null, TTL.THREE_HOURS(), true],
// AdGuard Mobile Banner
['https://filters.adtidy.org/extension/ublock/filters/20_optimized.txt', null, TTL.THREE_HOURS()],
// almost all generic rule
// ['https://filters.adtidy.org/extension/ublock/filters/20_optimized.txt', null, TTL.THREE_HOURS()],
// uBlock Origin Badware Risk List
[
'https://ublockorigin.github.io/uAssetsCDN/filters/badware.min.txt',

View File

@ -148,7 +148,8 @@ export async function processFilterRules(
parentSpan: Span,
filterRulesUrl: string,
fallbackUrls?: readonly string[] | null,
ttl: number | null = null
ttl: number | null = null,
allowThirdParty = false
): Promise<{ white: string[], black: string[], foundDebugDomain: boolean }> {
const [white, black, warningMessages] = await parentSpan.traceChild(`process filter rules: ${filterRulesUrl}`).traceAsyncFn((span) => fsFetchCache.apply<Readonly<[
white: string[],
@ -167,7 +168,7 @@ export async function processFilterRules(
* @param {string} line
*/
const lineCb = (line: string) => {
const result = parse(line, MUTABLE_PARSE_LINE_RESULT);
const result = parse(line, MUTABLE_PARSE_LINE_RESULT, allowThirdParty);
const flag = result[1];
if (flag === ParseType.Null) {
@ -295,7 +296,7 @@ const kwfilter = createKeywordFilter([
'^popup'
]);
export function parse($line: string, result: [string, ParseType]): [hostname: string, flag: ParseType] {
export function parse($line: string, result: [string, ParseType], allowThirdParty: boolean): [hostname: string, flag: ParseType] {
if (
// doesn't include
!$line.includes('.') // rule with out dot can not be a domain
@ -391,6 +392,11 @@ export function parse($line: string, result: [string, ParseType]): [hostname: st
return result;
}
if (_3p) {
if (allowThirdParty) {
result[0] = hostname;
result[1] = isIncludeAllSubDomain ? ParseType.BlackIncludeSubdomain : ParseType.BlackAbsolute;
return result;
}
result[1] = ParseType.Null;
return result;
}