AdGuardHome icon indicating copy to clipboard operation
AdGuardHome copied to clipboard

0 byte (\000) seems to cause domain matchig error

Open xLoge opened this issue 8 months ago • 2 comments

Prerequisites

Platform (OS and CPU architecture)

Linux, AMD64 (aka x86_64)

Installation

Docker

Setup

On one machine

AdGuard Home version

v0.107.72

Action

So I just saw in my logs that iahwpf-dnsotls-ds.metric.gstatic.com got blocked by the rule ||metric.gstatic.com^. But then it requested q\000enhk-dnsotls-ds.metric.gstatic.com and no block no nothing, resolved ip, maybe this is a bug caused by the \000 (0 byte) or the backslash in general.

Expected result

It should have blocked q\000enhk-dnsotls-ds.metric.gstatic.com like normal.

Actual result

q\000enhk-dnsotls-ds.metric.gstatic.com was not blocked.

Additional information and/or screenshots

Image

xLoge avatar Mar 13 '26 08:03 xLoge

I can reproduce this. I’ll forward it to the dev team.

VsevolodNaumov avatar Jun 11 '26 11:06 VsevolodNaumov

I can reproduce this on current master (a308a743) with a focused test through filtering.DNSFilter.CheckHost:

  • x.metric.gstatic.com -> blocked by ||metric.gstatic.com^ (control)
  • q\000enhk-dnsotls-ds.metric.gstatic.com (the escaped form miekg/dns produces from the wire) -> not filtered
  • same miss for a raw 0x00 byte, and for labels containing \, space, or %; _ still matches.

Root cause: urlfilter compiles ||domain^ into a regex anchored with ^(http|https|ws|wss)://([a-z0-9-_.]+\.)? (rules/regexp.go, RegexStartURL). The subdomain group only accepts [a-z0-9-_.], so a label containing any other byte fails the anchored match and the engine fails open. Since DNS labels on the wire can carry arbitrary bytes, any client can bypass every ||domain^ block rule this way, not just this one list.

I'd like to work on a fix. Two directions I see:

  1. In urlfilter: make hostname matching tolerant of arbitrary label bytes - match the domain suffix per label instead of relying on the anchored ([a-z0-9-_.]+\.)? prefix, keeping current behavior for ordinary names.
  2. In AdGuard Home: validate or normalize the qname in dnsforward.filterDNSRequest before CheckHost. Rewriting names risks changing lookup semantics, and rejecting them outright would drop weird-but-real client traffic like the one in this report.

My inclination is (1), since the rules express domain-suffix semantics and the library is shared with other AdGuard products. Happy to hear which layer you'd prefer before any code gets written, per the contributing guide.

davidscottpope-gif avatar Sep 29 '26 23:09 davidscottpope-gif