Skip to content
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

Add $denyallow modifier support #2923

Closed
ameshkov opened this issue Apr 5, 2021 · 5 comments
Closed

Add $denyallow modifier support #2923

ameshkov opened this issue Apr 5, 2021 · 5 comments
Assignees
Milestone

Comments

@ameshkov
Copy link
Member

ameshkov commented Apr 5, 2021

This issue explains the need for it:
#2917

Here's the spec on $denyallow in content blockers: AdguardTeam/CoreLibs#1304 (comment)

@ainar-g I've assigned it to v0.106.0 since I am going to implement it myself, it shouldn't slow down the release.

See the spec below.

denyallow

(Since v0.106.0.)

You can use the $denyallow modifier to exclude domains from the blocking rule. To add multiple domains to one rule, use the | character as a separator.

The syntax is:

$denyallow=domain1|domain2|...

It allows avoiding creating unnecessary "exception" rules when our blocking rule covers too many domains. Here's a simple use-case, you may want to block everything save for a couple of TLD domains. You could use the standard approach, i.e. rules like this:

! Block everything
/.*/
! Unblock a couple of TLDs
@@||com^
@@||net^

The problem with this approach is that this way you will also unblock tracking domains that are located on those TLDs (i.e. google-analytics.com). Here's how to solve this with $denyallow:

*$denyallow=com|net

Examples

  • *$denyallow=com|net — Block everything save for *.com and *.net.
  • @@*$denyallow=com|net — Unblock everything save for *.com and *.net
  • ||example.org^$denyallow=sub.example.org — Block example.org and *.example.org, but don't block sub.example.org
@ameshkov ameshkov added this to the v0.106.0 milestone Apr 5, 2021
@ameshkov ameshkov self-assigned this Apr 5, 2021
adguard pushed a commit to AdguardTeam/urlfilter that referenced this issue Apr 26, 2021
See the modifier description here: AdguardTeam/AdGuardHome#2923
adguard pushed a commit to AdguardTeam/urlfilter that referenced this issue Apr 26, 2021
Merge in DNS/urlfilter from denyallow to master

Squashed commit of the following:

commit 2da9fe5
Merge: 067508d a2e2c86
Author: Andrey Meshkov <am@adguard.com>
Date:   Mon Apr 26 15:51:54 2021 +0300

    Merge branch 'master' into denyallow

commit 067508d
Author: Andrey Meshkov <am@adguard.com>
Date:   Mon Apr 26 15:49:18 2021 +0300

    fix review comments

commit 405d8ed
Author: Andrey Meshkov <am@adguard.com>
Date:   Mon Apr 26 15:42:43 2021 +0300

    Added  priority test

commit 04195dd
Author: Andrey Meshkov <am@adguard.com>
Date:   Mon Apr 26 15:38:17 2021 +0300

    Allow TLD in  and

commit a616ee4
Author: Andrey Meshkov <am@adguard.com>
Date:   Mon Apr 26 15:22:23 2021 +0300

    Added $denyallow modifier

    See the modifier description here: AdguardTeam/AdGuardHome#2923
adguard pushed a commit that referenced this issue Apr 26, 2021
Merge in DNS/adguard-home from 2981-fix-dnsrewrite to master

Closes #2981.
Updates #2923.

Squashed commit of the following:

commit 578754d
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Apr 23 17:07:24 2021 +0300

    all: upd urlfilter
@ainar-g
Copy link
Contributor

ainar-g commented Apr 28, 2021

It seems like this is fully merged and documented, so I'll close the issue.

@ainar-g ainar-g closed this as completed Apr 28, 2021
@kiwilad-nz
Copy link

Just recently installed in docker to trial AdguardHome. Have to say superb, everything appears to be working as intended but don't know if this new addition is working as intended or I am adding the entry wrong.

I am having issues trying to use this feature as resolving stops entirely once adding the below rule.

I was on the understanding that if I added the below, any other TLD (such as .cn) that isn't listed below would be blocked AND would also block any subdomains that were in blocklists that were found in the below TLD's?

*$denyallow=au|ca|cc|ch|co|de|eu|fm|fr|gg|gl|im|io|it|lt|ly|me|ms|nl|nz|sk|tk|to|tv|uk|us

Applying this rule and using the "Check the filtering" query:

test.cn
*$denyallow=au|ca|cc|ch|co|de|eu|fm|fr|gg|gl|im|io|it|lt|ly|me|ms|nl|nz|sk|tk|to|tv|uk|us
Custom filtering rules
test.nz
Not found in your filter lists
C:\Users\strut>nslookup trademe.co.nz
Server:  UnKnown
Address:  192.168.1.3

Non-authoritative answer:
Name:    trademe.co.nz
Address:  0.0.0.0

It appears the above works but resolving just simply stops until the rule is removed.

C:\Users\strut>nslookup trademe.co.nz
Server:  AnsibleNAS.kiwilad.nz
Address:  192.168.1.3

Non-authoritative answer:
Name:    trademe.co.nz
Addresses:  151.101.194.137
          151.101.130.137
          151.101.66.137
          151.101.2.137

@ameshkov
Copy link
Member Author

Uh, I see the issue with it, nice bug.

The problem is that the rule is also applied to IP addresses in the responses and blocks them:
#3175

@kiwilad-nz
Copy link

kiwilad-nz commented May 24, 2021

Hi ameshkov,

I added your temporary fix which works but how come the server name now shows as unknown? Without the rule, the hostname then shows again.

Also, I can't have dual rules as this also appears to break dns resolution. Reason it would be nice is so I can add different lines for different TLD categories.

@@/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/
$denyallow=au|ca|cc|ch|co|de|eu|fm|fr|gg|gl|im|io|it|lt|ly|me|ms|nl|nz|sk|tk|to|tv|uk|us
$denyallow=com|net|org

C:\Users\strut>nslookup trademe.co.nz
Server:  UnKnown
Address:  192.168.1.3

Non-authoritative answer:
Name:    trademe.co.nz
Addresses:  151.101.66.137
          151.101.130.137
          151.101.2.137
          151.101.194.137
C:\Users\strut>nslookup trademe.co.cn
Server:  UnKnown
Address:  192.168.1.3

Non-authoritative answer:
Name:    trademe.co.cn
Address:  0.0.0.0

@ameshkov
Copy link
Member Author

Also, I can't have dual rules as this also appears to break dns resolution

Well, these are two different rules with their different scopes, that's how it works.

how come the server name now shows as unknown

Tbh, no idea, I always thought this is some kind of a Windows-specific issue with nslookup.

heyxkhoa pushed a commit to heyxkhoa/AdGuardHome that referenced this issue Mar 20, 2023
Merge in DNS/adguard-home from 2981-fix-dnsrewrite to master

Closes AdguardTeam#2981.
Updates AdguardTeam#2923.

Squashed commit of the following:

commit 578754d
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Apr 23 17:07:24 2021 +0300

    all: upd urlfilter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants