Skip to content

NSEC walk parser rejection branches are untested #467

Done

Description

@TMHSDigital

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 (nsecNext rejections)
  • 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 (TestWalkNSECStops covers 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

  1. added
    good first issue
    area: dns
    testing
    severity: medium
    on Nov 29, 2026
  2. TMHSDigital commented on Nov 29, 2026

    @TMHSDigital
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: dnsgood first issueseverity: mediumtesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions