Repository navigation
Description
Summary
internal/dns/nsecwalk.go (new in v0.12.0) parses answers from the target's own name server, but its rejection branches never run in tests: malformed next names, over-long labels, dots inside labels, wrong reply IDs, missing NSEC, the truncated-answer TCP retry and cancellation.
Where
internal/dns/nsecwalk.go:228,:236,:240(nsecNextrejections)internal/dns/nsecwalk.go:175(h.ID != id || !h.Response),:191("no NSEC record covers")internal/dns/nsecwalk.go:158-161(TC=1 TCP retry),:75(context cancel)internal/dns/nsecwalk_test.go:74(TestWalkNSECStopscovers loop, repeat, outside, limit, deadline and REFUSED only)
Impact
The length and label checks keep a hostile zone from feeding over-long or dot-smuggling names into results and from looping the walk. If one is weakened in a refactor, nothing fails. For example, deleting the n > 63 || ... size > 254 check leaves go test ./internal/dns green.
Suggested fix
Table tests for nsecNext, plus walk-level cases:
-
nsecNext(nil)and[]byte{3,'a','b'}(truncated label) return the malformed errors. - A 64-byte label errors; a next name over 254 bytes errors.
- A label
"a.b"(raw dot inside a label) errors and no name is recorded. - A reply with the wrong ID or QR=0 stops the walk with "unexpected message",
Queries == 1. - A NOERROR reply with no NSEC in authority stops with "no NSEC record covers".
- TC=1 over UDP then a full TCP answer continues; TC=1 with TCP refused stops with the TCP error.
- A context cancelled before the first query gives
Stop= context.Canceled,Queries == 0.
See also the fuzzing issue filed alongside this one.
Getting started
- Relevant files:
internal/dns/nsecwalk.go,internal/dns/nsecwalk_test.go,internal/dns/axfr_hostile_test.go(existing hostile-server helpers) - How to run tests:
go test ./internal/dns -run NSEC
Filed by repo-audit/full-audit at a45b999. Severity: medium. Effort: S. audit-key: testing|internal/dns/nsecwalk.go|nsecNext
Activity
TMHSDigital commentedon Nov 29, 2026
Fixed in 4661072: new internal/dns/nsecwalk_reject_test.go covers nsecNext rejections (empty, unterminated, truncated label, 64-byte label, name over 254 bytes, dot inside a label, plus the 253-character limit accepted), readCoveringNSEC (wrong ID, QR=0, no NSEC, REFUSED, garbage), the TC=1 TCP retry (succeeds over TCP; stops after one query when TCP is unreachable) and a pre-canceled walk (Stop = context canceled, 0 queries). Mutation check: removing the n > 63 / size > 254 guard fails two cases. Gate (gofmt, vet, golangci-lint v2.15.0, full suite) passes. Wrong ID / QR=0 are tested at the parser rather than walk level, since the test server cannot send a mismatched reply.