Skip to content

fix: keep absolute and relative names apart in the cache - #50

Draft
Frando wants to merge 2 commits into
mainfrom
fix/cache-fqdn-key
Draft

Frando wants to merge 2 commits into
mainfrom
fix/cache-fqdn-key

Conversation

@Frando

@Frando Frando commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

n0-dns-resolver keys the cache inconsistently around search domains:

  • foo and foo. share one entry. The cache key drops the trailing dot. But the search list expands only the relative foo, so the two names can resolve to different nodes:
    • A lookup of foo. caches its answer under foo. A later lookup of the relative foo gets that answer and never tries the search domains.
    • With negative caching on, a lookup of foo caches a negative answer under foo. The first negative in search order can come from a search domain such as foo.corp.example, a zone the local network can control through DHCP. A later lookup of foo. gets that answer instead of its own.
  • Positive answers are cached under the search name. An answer for foo that comes from foo.corp.example is stored under foo.corp.example, but lookups check the cache with foo. So a relative name answered through a search domain never hits the cache. Negative answers and serve-stale already use the caller's name.

This PR keys every cache entry on the name the caller asked for, lowercased, with the trailing dot kept. foo and foo. get separate entries, and a relative name answered through a search domain hits the cache on the next lookup. The two names stay apart even when no search domains are set. They resolve the same then, but a single rule is simpler than one that depends on the search config.

The hosts file still treats foo and foo. as one name. Its key moves to Hosts::key, and the cache and the hosts file now share the lowercase helper.

Three new end-to-end tests: two cover the shared entry in each direction, and one checks that a relative name hits the cache on its second lookup. Each fails without its fix.

Breaking changes

None in the API. foo and foo. no longer share a cache entry, so a lookup of one does not fill the cache for the other.

@Frando
Frando force-pushed the fix/cache-fqdn-key branch from f87027f to 2f21d81 Compare November 23, 2026 13:11
@Frando
Frando changed the base branch from main to Frando/hardening-fixes November 23, 2026 13:11
The cache key dropped a trailing dot, so `foo` and `foo.` shared one
entry. The search list expands only the relative `foo`, so the two names
can resolve to different nodes. An answer from a search domain, which
the local network can control, could then answer the absolute name, and
the reverse. The key now keeps the trailing dot.

The hosts file still drops it. Its key moves to Hosts::key, and the cache
and the hosts file share the lowercase helper.
A positive answer was cached under the search name that produced it, such as
foo.corp.example, while lookups probe the cache with the caller's foo. A
relative name answered through a search domain never hit the cache. Negative
answers and serve-stale already used the caller's name. Positive answers now
do too.
@Frando
Frando force-pushed the fix/cache-fqdn-key branch from 2f21d81 to 2f3d4bf Compare November 23, 2026 14:12
@Frando
Frando changed the base branch from Frando/hardening-fixes to main November 23, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant