Skip to content

dns: add unblock detection diagnostics - #173

Merged
Cd1s merged 2 commits into
mainfrom
feat/dns-unblock-detect
Oct 25, 2026
Merged

Cd1s merged 2 commits into
mainfrom
feat/dns-unblock-detect

Conversation

@Cd1s

@Cd1s Cd1s commented Oct 25, 2026

Copy link
Copy Markdown
Owner

What

  • Add read-only mr dns unblock detect [--json] [DOMAIN ...] diagnostics.
  • Compare every current ISP resolver with the configured trusted resolver and plain 1.1.1.1:53, using UDP, DoT, or DoH through the standard library.
  • Detect repeated block-page addresses, private sinkholes, empty answers, and UDP/53 interception; return latency and a reviewed recommendation.
  • Expose the same report through dns.unblock.detect API and add the DNS page detection button plus “Fill from detection” form action.
  • Add the lab scenario 12-dns-unblock-detect.sh, mock API data, tests, and documentation.

Why

Operators use different DNS blocking addresses and techniques by region. Detection must discover likely block-page addresses and whether plaintext DNS is intercepted without changing router configuration. The panel only fills the form; applying the recommendation still uses the existing plan/apply/confirm flow.

This PR depends on #171 (built-in DNS unblock core).

Verification

  • go test ./...
  • go vet ./...
  • sh tools/ci.sh — ALL CHECKS PASSED
  • lab 8 12-dns-unblock-detect.sh: repeated block-page address, single-CDN false-positive guard, and UDP/53 interception all pass.

Cd1s added a commit that referenced this pull request Oct 25, 2026
Fixes found in the QA review of PR #173:

- DoT: connect, TLS handshake and exchange share one 2 s deadline (a server
  that accepts TCP and stays silent no longer hangs the run); DoH refuses
  redirects and keeps no connections; certificates are always verified.
- Whole run: 8 queries in flight, 11 s hard deadline with a partial result
  (truncated/probed/total), a resolver that never answers its first 4 queries
  is not asked again, one detection at a time (409), at most 20 custom
  domains that must be plain domain names (400 otherwise, never dropped).
- API: POST only, token scope operate; CLI shares the same limits.
- Judging: rows whose trusted query failed are not judged; below 50% working
  trusted queries the report is "cannot tell" with no enable / block_ips
  recommendation. An ISP timeout/error is an error, not a block. A block page
  address needs >= 2 registered domains (eTLD+1 subset), never returned by
  the trusted resolver for any name, and not in the same /16 as the trusted
  answer (regional CDNs). The built-in list has one name per company.
- The trusted resolver is always asked encrypted (also with protocol: udp);
  plain 1.1.1.1 only tells whether port 53 is hijacked, including NXDOMAIN
  style blocks. udp is recommended only when that probe works and is clean.
- ISP servers are asked in configured order (the helper's order), each
  server's answer is in the report; the report says how every name is
  blocked, shows latency (answered queries only) and the errors.
- Panel: compact list that fits 360 px, loud "cannot tell" banner, the
  button is disabled while running, "fill from detection" only merges
  (never turns the switch off, never drops addresses, never goes plaintext).
- Tests: DoT/DoH against local TLS servers, limits, judging, API, a node
  driven UI test; lab scenario 12 now parses the JSON with python (the old
  negative grep could never match) and covers trusted-down; lab gets
  --plain-cf and tools/lab/dot-standin.py. Docs list the probe names and
  the privacy impact.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Cd1s

Cd1s commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Pushed 112724b — fixes from the QA review of this PR. Not merging; #171 still has to land first (this branch also needs a rebase / base change after it does).

Blocking

  1. DoT had no handshake deadline (a server that accepts TCP and stays silent hung mr dns unblock detect for 100 s+). Connect + handshake + exchange now share one 2 s deadline; DoH refuses redirects and keeps no connections. Certificates are always verified (no skip switch).
  2. Whole run: 8 queries in flight, 11 s hard deadline with a partial result (truncated, probed/total), a resolver that never answers its first 4 queries is not asked again, one detection at a time (409), at most 20 custom domains that must be plain domain names (400 otherwise).
  3. Rows whose trusted query failed are not judged. Below 50 % working encrypted queries the report is cannot tell (status: inconclusive) with no enable / block_ips recommendation, and the panel shows a red banner.

Should-fix

  • Block-page address = same address for ≥ 2 registered domains (eTLD+1, built-in subset of ~100 common two-label suffixes), never returned by the trusted resolver for any name, and not in the same /16 as the trusted answer (regional CDNs). The built-in list has one name per company (instagram.com replaced by wikipedia.org).
  • ISP timeout/error is an error, not "blocked". One odd answer no longer recommends enabling (needs ≥ 2 blocked names or a blocked custom name).
  • The trusted resolver is always asked encrypted, also with protocol: udp; plain 1.1.1.1 only tells whether port 53 is hijacked (NXDOMAIN-style blocking included → recommends tls). udp is recommended only when that probe works and is clean.
  • ISP servers are asked in configured order; every server's answer is in the report; each name says how it is blocked; latency counts answered queries only; errors are listed.
  • API is POST-only, token scope operate.
  • "Fill from detection" only merges: never turns the switch off, never drops addresses, never moves to plaintext.
  • Docs list the probe names and the privacy impact.

Tests / evidence

  • New unit tests: DoT/DoH against local TLS servers (good cert, wrong name, untrusted cert, silent server, redirects, HTTP errors), limits and deadline, judging, API (405 / 400 / 409, no secrets), a node-driven UI test (also asserts no null/undefined text). The reproductions from the review were written first and failed on the old code (18 failures).
  • Lab scenario 12 (lab 7): 16/16 — block page, private sinkhole, NXDOMAIN block, regional-CDN names not flagged, interception with tls and with udp configured, no interception → udp, stalled and closed trusted DoT → nothing recommended within 16 s, router.yaml byte-identical. The old "not blocked" assertion could never match (pretty-printed JSON); it is replaced by python checks. lab isp --plain-cf and tools/lab/dot-standin.py make it independent of the internet; mr's TLS check stays on (SSL_CERT_FILE).
  • sh tools/ci.sh: ALL CHECKS PASSED.

Known limits (documented): A records only; eTLD+1 is a subset, same-company names typed by the user can still share edge addresses (the /16 guard covers most regional-CDN cases, not all); a trusted server without DoT/DoH (or without a certificate valid for its address) yields "cannot tell". A CGI cannot see the browser giving up; the run is bounded by the 11 s deadline and the 409 single-flight guard instead (the panel waits 15 s).

🤖 Generated with Claude Code

Cd1s and others added 2 commits October 26, 2026 01:53
Fixes found in the QA review of PR #173:

- DoT: connect, TLS handshake and exchange share one 2 s deadline (a server
  that accepts TCP and stays silent no longer hangs the run); DoH refuses
  redirects and keeps no connections; certificates are always verified.
- Whole run: 8 queries in flight, 11 s hard deadline with a partial result
  (truncated/probed/total), a resolver that never answers its first 4 queries
  is not asked again, one detection at a time (409), at most 20 custom
  domains that must be plain domain names (400 otherwise, never dropped).
- API: POST only, token scope operate; CLI shares the same limits.
- Judging: rows whose trusted query failed are not judged; below 50% working
  trusted queries the report is "cannot tell" with no enable / block_ips
  recommendation. An ISP timeout/error is an error, not a block. A block page
  address needs >= 2 registered domains (eTLD+1 subset), never returned by
  the trusted resolver for any name, and not in the same /16 as the trusted
  answer (regional CDNs). The built-in list has one name per company.
- The trusted resolver is always asked encrypted (also with protocol: udp);
  plain 1.1.1.1 only tells whether port 53 is hijacked, including NXDOMAIN
  style blocks. udp is recommended only when that probe works and is clean.
- ISP servers are asked in configured order (the helper's order), each
  server's answer is in the report; the report says how every name is
  blocked, shows latency (answered queries only) and the errors.
- Panel: compact list that fits 360 px, loud "cannot tell" banner, the
  button is disabled while running, "fill from detection" only merges
  (never turns the switch off, never drops addresses, never goes plaintext).
- Tests: DoT/DoH against local TLS servers, limits, judging, API, a node
  driven UI test; lab scenario 12 now parses the JSON with python (the old
  negative grep could never match) and covers trusted-down; lab gets
  --plain-cf and tools/lab/dot-standin.py. Docs list the probe names and
  the privacy impact.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Cd1s
Cd1s force-pushed the feat/dns-unblock-detect branch from 112724b to 2521a7c Compare October 25, 2026 18:06
@Cd1s
Cd1s merged commit 322b59a into main Oct 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the feat/dns-unblock-detect branch October 25, 2026 19:04
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