Skip to content

feat: resolve /dnsaddr before filtering - #174

Merged
lidel merged 1 commit into
mainfrom
feat/resolve-dnsaddr
Jul 29, 2026
Merged

feat: resolve /dnsaddr before filtering#174
lidel merged 1 commit into
mainfrom
feat/resolve-dnsaddr

Conversation

@lidel

@lidel lidel commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem

A /dnsaddr carries no transport component, so filter-addrs can neither match nor exclude it: a ws-speaking peer behind one vanishes from ?filter-addrs=ws, and a quic-only peer survives ?filter-addrs=!quic-v1. The client can't detect either case.1

Credit to @achingbrain for flagging this gap

Fix

  • resolve /dnsaddr before boxo filters: a filtered request gets it replaced (except filter-addrs=dnsaddr, the one filter that matches it), an unfiltered one keeps it alongside the resolved addresses
  • SOMEGUY_DNSADDR_RESOLUTION names what an unfiltered response does with the /dnsaddr: append (default), replace, filtered, or never
  • hostnames in records are attacker-chosen, so resolution is bounded per lookup, per record, per request, and per response, cached, and detached from request cancellation; docs/dnsaddr-resolution.md carries the rationale
  • addresses come out ordered by how directly they dial: IP, DNS, /dnsaddr, relays last

This turned out to not be trivial due to the way things work, and increased surface for abuse, but with enough code/tests should be good to go now.

Footnotes

  1. delegated routing: resolve DNSADDR addresses before filtering specs#542 proposes this behavior for every Delegated Routing implementation. I think there is more nuance, thus this PR provides SOMEGUY_DNSADDR_RESOLUTION configuration flag.

@lidel
lidel force-pushed the feat/resolve-dnsaddr branch from dde90ff to b730f13 Compare July 29, 2026 12:06
A /dnsaddr carries no transport component, so filter-addrs can neither
match it nor exclude it: a ws-speaking peer was dropped by
?filter-addrs=ws, and a quic-only peer survived ?filter-addrs=!quic-v1.
Neither is detectable by the client. someguy now resolves before boxo
filters, which fixes both directions. See ipfs/specs#542.

A filtered request has its /dnsaddr replaced, since keeping it would let
a record survive a filter meant to exclude it. The exception is a
positive filter naming dnsaddr, the one filter a /dnsaddr matches; the
client is asking for indirections, so the /dnsaddr is kept alongside
what it resolves to. An unfiltered request gets the resolved addresses
added and keeps the /dnsaddr, so it can dial now and re-resolve later.
SOMEGUY_DNSADDR_RESOLUTION names what an unfiltered response does with
the /dnsaddr: append (default), replace, filtered, or never.

Hostnames in provider records are attacker-chosen, and resolution runs
inline while the response streams, so it is bounded on four axes: DNS
lookups per request, resolved addresses per record, recursion depth,
and a per-lookup timeout, which together also cap the delay resolution
can add to one response. The per-record limit is threaded through the
recursion rather than applied to the finished result: a TXT record that
lists itself expands as fan^depth, and re-entering a cached name costs
no lookup, so a limit checked at the end still let one request build
millions of addresses.

- resolve detached from the request context behind a singleflight, so a
  disconnect cannot cache its own cancellation as a 15 minute failure
- shed load once the request is gone rather than spend the rest of its
  budget on queries nothing will read
- keep the original whenever an expansion is not whole, so a failed or
  throttled lookup does not drop the indirection the rest lives behind
- drop a /dnsaddr naming a different peer: nothing it yields can belong
  to the record carrying it
- normalize only the hostname in cache keys, over ASCII: lowering a whole
  multiaddr folds case-sensitive components together, and Unicode case
  mapping folds U+0130 and U+212A onto ASCII, which let one record cache
  a failure under another name's key
- skip lookups madns can never satisfy, such as a /p2p-circuit suffix
- order addresses by how directly they dial: IP, DNS, dnsaddr, relay last
- require go 1.26
@lidel
lidel force-pushed the feat/resolve-dnsaddr branch from b730f13 to 841c42a Compare July 29, 2026 13:00
@lidel
lidel marked this pull request as ready for review July 29, 2026 14:51
@lidel
lidel merged commit ae0de70 into main Jul 29, 2026
7 checks passed
@lidel lidel mentioned this pull request Jul 29, 2026
lidel added a commit that referenced this pull request Jul 29, 2026
Minor rather than patch: #174 adds SOMEGUY_DNSADDR_RESOLUTION and changes
what /routing/v1 returns by default (dnsaddr resolution, address order),
and Go 1.26 is now the minimum.
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