# GHSA-MV8X-2H8P-G3WH: DNSSEC: incomplete denial-of-existence proofs (wildcards, NSEC NXDOMAIN, CNAME bit, name order)

- Database: GitHub
- Severity: CVSS 4.8 (Medium)
- Published: 2026-11-21
- Modified: 2026-11-22

## Affected versions

- github.com/0xERR0R/blocky (Go): from v0.28.0, fixed in v0.37.0

## Description

### Summary

Incomplete wildcard and denial-of-existence checks could cause Blocky to authenticate an incorrect answer or incorrectly report that a name or record did not exist. Some legitimate wildcard answers could also fail. The proofs concerned are those of wildcard answers, of wildcard "no data" answers, of NXDOMAIN in NSEC-signed zones and of "no data" for a name that owns a CNAME; with them one of a zone’s signed answers could be passed off for another, or a name that exists denied, with the AD flag set. Blocky v0.37.0 refuses these responses, serves wildcard answers and wildcard "no data" answers proven by an Opt-Out record without the AD flag, and accepts the valid answers that failed.

### Impact

Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver; cases 2 and 8 also fail valid answers without any attacker. The attacker cannot invent data: every case reuses records that the zone itself signed. For each case of the Details:

| Case | Zone concerned | Effect |
|---|---|---|
| 1 | has a signed wildcard | the wildcard’s records, marked authenticated, in place of the records of a name that exists |
| 2 | NSEC3-signed, with a wildcard | valid wildcard answers for names more than one label below the wildcard’s parent fail with SERVFAIL |
| 3 | NSEC3-signed, with a wildcard that lacks the queried type | an authenticated "no data" answer hides the records of a name that exists |
| 4 | NSEC-signed, with a wildcard | an authenticated NXDOMAIN in place of the wildcard’s answer |
| 5 | NSEC-signed, with a wildcard | an authenticated NXDOMAIN or "no data" answer for a name that exists |
| 6 | NSEC3 with Opt-Out, with a wildcard | the wildcard’s records, marked authenticated, for a name under an unsigned delegation |
| 7 | any, for a name that owns a CNAME | an authenticated "no data" answer in place of the CNAME |
| 8 | NSEC-signed, with a name that has an escaped character | valid NXDOMAIN answers near that name fail with SERVFAIL; with an attacker, an authenticated NXDOMAIN for a name that exists |

### Affected deployments

This issue concerns deployments using Blocky’s built-in DNSSEC validator (`dnssec.validate: true`). Affected releases: v0.28.0 through v0.36.0. For each case of the Details:

| Case | Affected |
|---|---|
| 1, 3, 5 | v0.28.2 through v0.36.0 ([#1935](https://github.com/0xERR0R/blocky/pull/1935)) |
| 2, 4 | v0.28.0 through v0.36.0 |
| 6 | wildcard answers v0.28.0 through v0.36.0, wildcard "no data" answers v0.28.2 through v0.36.0 |
| 7 | NSEC and a matching NSEC3 record v0.28.0 through v0.36.0, the wildcard’s NSEC3 record v0.28.2 through v0.36.0 |
| 8 | v0.28.0 through v0.36.0; whole names compared as text before v0.30.0, label by label since ([#2017](https://github.com/0xERR0R/blocky/pull/2017)) |

v0.28.0 and v0.28.1 refused wildcard "no data" answers, valid ones included.

### Remediation

Upgrade to [Blocky v0.37.0](https://github.com/0xERR0R/blocky/releases/tag/v0.37.0) or later. The fix checks the required evidence for wildcard, NXDOMAIN, and NODATA responses. It is commit [`1c4c01b`](https://github.com/0xERR0R/blocky/commit/1c4c01b35ecbc26df7fb09f015f4912e8c6a7bbb).

### Details

Blocky’s validator rates a response **Secure** (served with the AD flag), **Insecure** (served without it, like data of an unsigned zone) or **Bogus** (refused with SERVFAIL).

A wildcard such as `*.example.` answers only for names that do not exist. A validator may therefore accept an answer made from a wildcard, or a wildcard "no data" answer, only with a proof that the queried name does not exist. With NSEC3 that proof needs the **closest encloser**, the nearest ancestor that exists, and an NSEC3 record that covers the **next closer name**, the name one label longer than it ([RFC 4035 §5.3.4](https://www.rfc-editor.org/rfc/rfc4035#section-5.3.4), RFC 5155 [§8.7](https://www.rfc-editor.org/rfc/rfc5155#section-8.7) and [§8.8](https://www.rfc-editor.org/rfc/rfc5155#section-8.8)). Cases 1 to 6 are about wildcards; 7 and 8 concern "no data" and NXDOMAIN proofs in general.

1. **Wildcard answer without a proof.** When a response carried no NSEC or NSEC3 record, [`validateWildcardProof`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/wildcard.go#L84-L125) accepted the expansion, with this comment:

   ```go
   // Major validators (Unbound, BIND) accept wildcards in positive responses without NSEC/NSEC3 proof
   ```

   Neither does: Unbound 1.26.2 marks such an answer bogus and BIND 9.20.31 fails it with "noqname proof not found". [RFC 4035 §5.3.3](https://www.rfc-editor.org/rfc/rfc4035#section-5.3.3) says that a resolver "MUST verify that wildcard expansion was applied properly before considering the RRset to be authentic".
2. **NSEC3 proof for the wrong name.** [`validateWildcardNSEC3`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/wildcard.go#L146-L190) wanted an NSEC3 record that covers the queried name, not the next closer name:

   ```go
   if v.nsec3Covers(nsec3Records, qnameHash) {
   ```

   For `a.b.example.` answered by `*.example.` it wanted `a.b.example.` covered where `b.example.` has to be. A correct proof was rejected and an incomplete one passed.
3. **Wildcard "no data" without a closest encloser proof.** [`checkWildcardNSEC3Match`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec3.go#L283-L347) accepted the NSEC3 record of the wildcard at the nearest ancestor that has an NSEC3 record, if it lacks the queried type, without checking that the next closer name is covered.
4. **NSEC NXDOMAIN without the wildcard’s denial.** [`validateNSECNXDOMAIN`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec.go#L34-L50) accepted an NXDOMAIN as soon as one NSEC record covered the name, without the second one that proves that no wildcard could have matched ([RFC 4035 §5.4](https://www.rfc-editor.org/rfc/rfc4035#section-5.4)). The NSEC3 proof of NXDOMAIN did check the wildcard.
5. **A wildcard’s NSEC record under another name.** The Labels field in the signature of the NSEC record of `*.example.` marks it as a wildcard’s. Renamed to another owner it still verifies, because verification puts `*.example.` back, and Blocky then used it as a denial at the new name (RFC 4035 §5.4, [RFC 4592 §4.7](https://www.rfc-editor.org/rfc/rfc4592#section-4.7)). The zone-cut check in `chain.go` already refused an NSEC record that verifies only as a wildcard expansion; the denial path did not. [`nsecCoversName`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec.go#L111-L124) also let any NSEC record whose next name sorts before its owner cover every name after the owner and every name before the next name, though only the last NSEC record of a zone may wrap around. Unbound restores the wildcard owner before use (its fix for CVE-2017-15105).
6. **Opt-Out cover with the AD flag.** When the NSEC3 record that covers the next closer name of a wildcard answer or wildcard "no data" answer has the Opt-Out flag, the response must not get the AD flag, because names in that span may be unsigned delegations ([RFC 5155 §9.2](https://www.rfc-editor.org/rfc/rfc5155#section-9.2)). Blocky returned Secure; Unbound returns insecure (`nsec3_prove_wildcard()`, `nsec3_do_prove_nodata()`).
7. **"No data" proofs and the CNAME bit.** A name that owns a CNAME has no other data, so a "no data" proof must show that the name has neither the queried type nor a CNAME ([RFC 6840 §4.3](https://www.rfc-editor.org/rfc/rfc6840#section-4.3)). [`validateNSECNODATA`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec.go#L53-L76), [`checkDirectNSEC3Match`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec3.go#L221-L261) and the wildcard branch of `checkWildcardNSEC3Match` looked for the queried type only, so with the CNAME dropped from a response the rest was an authenticated "no data" answer.
8. **NSEC names ordered as text.** [`canonicalNameCompare`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec.go#L84-L106) compared labels in presentation form, where a space is written `\ ` and an unprintable octet `\DDD`. [RFC 4034 §6.1](https://www.rfc-editor.org/rfc/rfc4034#section-6.1) orders them as raw octets. With such a name in an NSEC record a valid NXDOMAIN proof was rejected, and an NSEC record that does not cover a name could be taken to cover it.

Unbound checks all of these (`validator/val_nsec3.c`; `val_nsec_proves_no_wc()` in `validator/val_nsec.c`; `rrset_canonical()` in `validator/val_sigcrypt.c` for case 5; `nsec_proves_nodata()` and `nsec3_do_prove_nodata()` for case 7; `dname_canonical_compare()` in `util/data/dname.c` for case 8), and BIND rejects cases 1 to 3 (`lib/dns/validator.c`).

### Proof of concept

The test shows the eight cases in a synthetic zone `example.` that is a trust anchor and holds `*.example.`; each group of the test is one case.

To reproduce, save the test file below as `resolver/dnssec/ghsa_mv8x_2h8p_g3wh_poc_test.go` in a checkout of the version to test and run:

```sh
go test -run TestGHSAmv8xWildcardProofs -v ./resolver/dnssec/
```

On `v0.36.0` it exits with status 1. Its output follows, condensed to one line per test case; the number in brackets is the case in the Details, and a line without one is a control:

```text
wildcard answer for www.example.:
       PASS  control: NSEC3 covering H(www.example.)
       PASS  control: NSEC3 covering only H(x.example.)
  [1]  FAIL  no NSEC or NSEC3
             got Secure, want Bogus

wildcard answer for a.b.example., next closer name b.example.:
  [2]  FAIL  NSEC3 covering H(b.example.)
             got Bogus, want Secure
  [2]  FAIL  NSEC3 covering only H(a.b.example.)
             got Secure, want Bogus

wildcard NODATA for www.example. A:
       PASS  control: closest encloser proof, wildcard NSEC3 without A
       PASS  control: closest encloser proof, wildcard NSEC3 with A
  [3]  FAIL  wildcard NSEC3 without A, next closer name not covered
             got Secure, want Bogus

next closer name www.example. in an Opt-Out span:
       PASS  control: wildcard answer, NSEC3 covering H(www.example.)
  [6]  FAIL  wildcard answer, Opt-Out NSEC3 covering H(www.example.)
             got Secure, want Insecure
       PASS  control: wildcard NODATA, NSEC3 covering H(www.example.)
  [6]  FAIL  wildcard NODATA, Opt-Out NSEC3 covering H(www.example.)
             got Secure, want Insecure

NSEC NXDOMAIN for www.example.:
       PASS  control: NSECs covering www.example. and *.example.
       PASS  control: NSEC covering only *.example.
  [4]  FAIL  NSEC covering www.example., none covering *.example.
             got Secure, want Bogus

wildcard NSEC re-owned to another name:
       PASS  control: NODATA for mail.example., NSEC of mail.example.
       PASS  control: NXDOMAIN for www.example., re-owned to n.example., RRSIG Labels 2
  [5]  FAIL  NXDOMAIN for www.example., re-owned to n.example.
             got Secure, want Bogus
  [5]  FAIL  NODATA for www.example., re-owned to n.example. and www.example.
             got Secure, want Bogus

NODATA proofs and the CNAME bit:
       PASS  control: NSEC of www.example. with TXT
  [7]  FAIL  NSEC of www.example. with CNAME
             got Secure, want Bogus
       PASS  control: NSEC3 matching www.example. with TXT
  [7]  FAIL  NSEC3 matching www.example. with CNAME
             got Secure, want Bogus
       PASS  control: closest encloser proof, wildcard NSEC3 with TXT
  [7]  FAIL  closest encloser proof, wildcard NSEC3 with CNAME
             got Secure, want Bogus

NSEC order of names with escaped octets:
  [8]  FAIL  lab-2.example. absent, NSEC from the name with a space to the apex
             got Bogus, want Secure
  [8]  FAIL  lab-2.example. exists, NSEC from lab.example. to the name with a space
             got Secure, want Bogus
```

On `v0.37.0` it exits with status 0: all 27 test cases pass.

<details>
<summary><code>ghsa_mv8x_2h8p_g3wh_poc_test.go</code></summary>

```go
package dnssec

// GHSA-mv8x-2h8p-g3wh: wildcard proofs, the CNAME bit of NODATA proofs and the order of NSEC names.
//
// RFC 4035 §5.3.4 and RFC 5155 §8.8: an answer synthesized from a wildcard (its RRSIG Labels field
// is less than the owner's label count) is authentic only with a proof that the query name does
// not exist. With NSEC3 that is an NSEC3 covering the next closer name: the name one label longer
// than the closest encloser, the wildcard's parent.
// RFC 5155 §8.7: a wildcard NODATA answer needs the closest encloser proof (§7.2.1: an NSEC3
// matching the closest encloser and one covering the next closer name) and the NSEC3 matching the
// wildcard at the closest encloser, without the query type.
// RFC 4035 §3.1.3.2 and §5.4: an NSEC NXDOMAIN proof needs an NSEC covering the query name and
// one covering the wildcard at the closest encloser, proving that no wildcard could have matched.
// RFC 4035 §5.4 and RFC 4592 §4.7: an NSEC RR whose RRSIG Labels field is less than its owner's
// label count, not counting a leading "*", was synthesized and never proves a negative answer. The NSEC of
// *.example. renamed to another owner still verifies, as the Labels field restores the signed name
// (RFC 4035 §5.3.2), but proves nothing at that owner.
// RFC 5155 §9.2: when the NSEC3 covering the next closer name has the Opt-Out flag set, names in
// its span may be unsigned delegations, so a wildcard answer or wildcard NODATA proven with it is
// not authenticated: Insecure, not Secure.
// RFC 6840 §4.3, and RFC 5155 §8.7 for the wildcard: a NODATA proof shows that neither the query
// type nor CNAME exists at the name, so the NSEC or NSEC3 matching the name, or the wildcard, has
// neither bit set. With the CNAME bit set the answer is the CNAME, and a NODATA answer is Bogus.
// RFC 4034 §6.1: names are ordered by their labels as octet strings, upper case US-ASCII letters
// as lower case, and an NSEC covers the names between its owner and its next name in that order
// (RFC 4035 §5.4). The octets decide, not their spelling in presentation format, where miekg/dns
// writes a space (0x20) as "\ ".
//
// example. is a trust anchor; the RRset *.example. A and every NSEC and NSEC3 are signed by its key.
//
// go test -run TestGHSAmv8xWildcardProofs -v ./resolver/dnssec/

import (
	"context"
	"crypto"
	"encoding/base32"
	"math/big"
	"net"
	"slices"
	"strings"
	"testing"
	"time"

	"github.com/0xERR0R/blocky/log"
	"github.com/0xERR0R/blocky/model"
	"github.com/miekg/dns"
)

func TestGHSAmv8xWildcardProofs(t *testing.T) {
	zone := newPocWildcardZone(t)
	anchors, err := NewTrustAnchorStore([]string{zone.key.String()})
	if err != nil {
		t.Fatal(err)
	}

	dnskey := []dns.RR{zone.key, zone.sign(t, zone.key)}

	type testCase struct {
		name string
		ns   []dns.RR
		want ValidationResult
	}
	secure, insecure, bogus := ValidationResultSecure, ValidationResultInsecure, ValidationResultBogus
	// run validates the reply to qname A with rcode, made of answer (none for NODATA and NXDOMAIN)
	// and each case's authority section.
	run := func(t *testing.T, qname string, rcode int, answer []dns.RR, cases ...testCase) {
		for _, c := range cases {
			t.Run(c.name, func(t *testing.T) {
				logger, _ := log.NewMockEntry()
				v := NewValidator(t.Context(), anchors, logger, &mockResolver{
					ResolveFn: func(_ context.Context, _ *model.Request) (*model.Response, error) {
						return &model.Response{Res: &dns.Msg{Answer: dnskey}}, nil // the only query is example. DNSKEY
					},
				}, 1, 10, 150, 30, 3600)

				q := dns.Question{Name: qname, Qtype: dns.TypeA, Qclass: dns.ClassINET}
				msg := &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: rcode}, Answer: answer, Ns: c.ns}
				if got := v.ValidateResponse(t.Context(), msg, q); got != c.want {
					t.Errorf("got %s, want %s", got, c.want)
				}
			})
		}
	}

	// wildcardAnswer is the signed RRset *.example. A as the answer for qname (RRSIG Labels 1).
	wildcardAnswer := func(qname string) []dns.RR {
		sig := zone.sign(t, pocWildcardA("*.example."))
		sig.Hdr.Name = qname

		return []dns.RR{pocWildcardA(qname), sig}
	}
	// signed returns each NSEC or NSEC3 followed by its RRSIG.
	signed := func(denials ...dns.RR) []dns.RR {
		var rrs []dns.RR
		for _, n := range denials {
			rrs = append(rrs, n, zone.sign(t, n))
		}

		return rrs
	}
	covering := func(name string) *dns.NSEC3 { return pocWildcardNSEC3(t, name, -1, 1, dns.TypeTXT, dns.TypeRRSIG) }
	matching := func(name string, types ...uint16) *dns.NSEC3 { return pocWildcardNSEC3(t, name, 0, 1, types...) }

	t.Run("wildcard answer for www.example.", func(t *testing.T) {
		run(t, "www.example.", dns.RcodeSuccess, wildcardAnswer("www.example."),
			testCase{"control: NSEC3 covering H(www.example.)", signed(covering("www.example.")), secure},
			testCase{"control: NSEC3 covering only H(x.example.)", signed(covering("x.example.")), bogus},
			testCase{"no NSEC or NSEC3", nil, bogus})
	})

	t.Run("wildcard answer for a.b.example., next closer name b.example.", func(t *testing.T) {
		run(t, "a.b.example.", dns.RcodeSuccess, wildcardAnswer("a.b.example."),
			testCase{"NSEC3 covering H(b.example.)", signed(covering("b.example.")), secure},
			testCase{"NSEC3 covering only H(a.b.example.)", signed(covering("a.b.example.")), bogus})
	})

	t.Run("wildcard NODATA for www.example. A", func(t *testing.T) {
		apex := matching("example.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeDNSKEY, dns.TypeNSEC3PARAM)
		nextCloser := covering("www.example.")
		noA, withA := matching("*.example.", dns.TypeTXT, dns.TypeRRSIG), matching("*.example.", dns.TypeA, dns.TypeRRSIG)
		run(t, "www.example.", dns.RcodeSuccess, nil,
			testCase{"control: closest encloser proof, wildcard NSEC3 without A", signed(apex, nextCloser, noA), secure},
			testCase{"control: closest encloser proof, wildcard NSEC3 with A", signed(apex, nextCloser, withA), bogus},
			testCase{"wildcard NSEC3 without A, next closer name not covered", signed(apex, noA), bogus})
	})

	t.Run("next closer name www.example. in an Opt-Out span", func(t *testing.T) {
		optOut := covering("www.example.")
		optOut.Flags = 1 // Opt-Out
		apex := matching("example.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeDNSKEY, dns.TypeNSEC3PARAM)
		noA := matching("*.example.", dns.TypeTXT, dns.TypeRRSIG)
		run(t, "www.example.", dns.RcodeSuccess, wildcardAnswer("www.example."),
			testCase{"control: wildcard answer, NSEC3 covering H(www.example.)", signed(covering("www.example.")), secure},
			testCase{"wildcard answer, Opt-Out NSEC3 covering H(www.example.)", signed(optOut), insecure})
		run(t, "www.example.", dns.RcodeSuccess, nil,
			testCase{"control: wildcard NODATA, NSEC3 covering H(www.example.)", signed(apex, covering("www.example."), noA), secure},
			testCase{"wildcard NODATA, Opt-Out NSEC3 covering H(www.example.)", signed(apex, optOut, noA), insecure})
	})

	t.Run("NSEC NXDOMAIN for www.example.", func(t *testing.T) {
		// canonical order: example. < *.example. < a.example. < www.example. < z.example.
		noWildcard := pocWildcardNSEC("example.", "a.example.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeNSEC, dns.TypeDNSKEY)
		noWWW := pocWildcardNSEC("a.example.", "z.example.", dns.TypeA, dns.TypeRRSIG, dns.TypeNSEC)
		run(t, "www.example.", dns.RcodeNameError, nil,
			testCase{"control: NSECs covering www.example. and *.example.", signed(noWWW, noWildcard), secure},
			testCase{"control: NSEC covering only *.example.", signed(noWildcard), bogus},
			testCase{"NSEC covering www.example., none covering *.example.", signed(noWWW), bogus})
	})

	t.Run("wildcard NSEC re-owned to another name", func(t *testing.T) {
		// example. holds *.example. TXT, mail.example. MX and www.example. A; canonical order:
		// example. < *.example. < mail.example. < n.example. < www.example.
		wildcard := pocWildcardNSEC("*.example.", "mail.example.", dns.TypeTXT, dns.TypeRRSIG, dns.TypeNSEC)
		mail := signed(pocWildcardNSEC("mail.example.", "www.example.", dns.TypeMX, dns.TypeRRSIG, dns.TypeNSEC))
		// reowned returns the NSEC of mail.example. and, renamed to each owner, the *.example. NSEC
		// and its RRSIG with the Labels field set to labels (1 as signed).
		reowned := func(labels uint8, owners ...string) []dns.RR {
			rrs := slices.Clone(mail)
			for _, owner := range owners {
				nsec, sig := dns.Copy(wildcard), zone.sign(t, wildcard)
				nsec.Header().Name, sig.Hdr.Name, sig.Labels = owner, owner, labels
				rrs = append(rrs, nsec, sig)
			}

			return rrs
		}

		run(t, "mail.example.", dns.RcodeSuccess, nil,
			testCase{"control: NODATA for mail.example., NSEC of mail.example.", mail, secure})
		run(t, "www.example.", dns.RcodeNameError, nil,
			testCase{"control: NXDOMAIN for www.example., re-owned to n.example., RRSIG Labels 2", reowned(2, "n.example."), bogus},
			testCase{"NXDOMAIN for www.example., re-owned to n.example.", reowned(1, "n.example."), bogus})
		run(t, "www.example.", dns.RcodeSuccess, nil,
			testCase{"NODATA for www.example., re-owned to n.example. and www.example.", reowned(1, "n.example.", "www.example."), bogus})
	})

	t.Run("NODATA proofs and the CNAME bit", func(t *testing.T) {
		// Three proofs of NODATA for www.example. A. typ is the type that the NSEC or NSEC3 of
		// www.example., or of *.example. in the wildcard proof, has in its bitmap besides RRSIG and NSEC.
		nsec := func(typ uint16) []dns.RR {
			return signed(pocWildcardNSEC("www.example.", "example.", typ, dns.TypeRRSIG, dns.TypeNSEC))
		}
		nsec3 := func(typ uint16) []dns.RR { return signed(matching("www.example.", typ, dns.TypeRRSIG)) }
		apex := matching("example.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeDNSKEY, dns.TypeNSEC3PARAM)
		wildcard := func(typ uint16) []dns.RR {
			return signed(apex, covering("www.example."), matching("*.example.", typ, dns.TypeRRSIG))
		}
		run(t, "www.example.", dns.RcodeSuccess, nil,
			testCase{"control: NSEC of www.example. with TXT", nsec(dns.TypeTXT), secure},
			testCase{"NSEC of www.example. with CNAME", nsec(dns.TypeCNAME), bogus},
			testCase{"control: NSEC3 matching www.example. with TXT", nsec3(dns.TypeTXT), secure},
			testCase{"NSEC3 matching www.example. with CNAME", nsec3(dns.TypeCNAME), bogus},
			testCase{"control: closest encloser proof, wildcard NSEC3 with TXT", wildcard(dns.TypeTXT), secure},
			testCase{"closest encloser proof, wildcard NSEC3 with CNAME", wildcard(dns.TypeCNAME), bogus})
	})

	t.Run("NSEC order of names with escaped octets", func(t *testing.T) {
		// lab\ printer is the label "lab printer"; canonical order (0x20 < 0x2d):
		// example. < *.example. < lab.example. < lab\ printer.example. < lab-2.example.
		apex := pocWildcardNSEC("example.", "lab.example.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeNSEC, dns.TypeDNSKEY)
		// the last NSEC of a zone without lab-2.example., which it covers
		last := pocWildcardNSEC(`lab\ printer.example.`, "example.", dns.TypeA, dns.TypeRRSIG, dns.TypeNSEC)
		// the NSEC of lab.example. in a zone with lab-2.example., which lies after its next name
		lab := pocWildcardNSEC("lab.example.", `lab\ printer.example.`, dns.TypeA, dns.TypeRRSIG, dns.TypeNSEC)
		run(t, "lab-2.example.", dns.RcodeNameError, nil,
			testCase{"lab-2.example. absent, NSEC from the name with a space to the apex", signed(last, apex), secure},
			testCase{"lab-2.example. exists, NSEC from lab.example. to the name with a space", signed(lab, apex), bogus})
	})
}

type pocWildcardZone struct {
	key  *dns.DNSKEY
	priv crypto.Signer
}

// newPocWildcardZone returns an ECDSA P-256 key-signing key for example.
func newPocWildcardZone(t *testing.T) pocWildcardZone {
	t.Helper()

	key := &dns.DNSKEY{
		Hdr:   dns.RR_Header{Name: "example.", Rrtype: dns.TypeDNSKEY, Class: dns.ClassINET, Ttl: 3600},
		Flags: 257, Protocol: 3, Algorithm: dns.ECDSAP256SHA256,
	}

	priv, err := key.Generate(256)
	for err == nil && key.KeyTag() == 0 { // RRSIG.Sign refuses key tag 0
		priv, err = key.Generate(256)
	}

	if err != nil {
		t.Fatal(err)
	}

	return pocWildcardZone{key, priv.(crypto.Signer)}
}

// sign returns the RRSIG over rrset made by z with RRSIG.Sign, which leaves a leading "*" label
// out of the Labels field.
func (z pocWildcardZone) sign(t *testing.T, rrset ...dns.RR) *dns.RRSIG {
	t.Helper()

	sig := &dns.RRSIG{
		Algorithm: z.key.Algorithm, KeyTag: z.key.KeyTag(), SignerName: z.key.Hdr.Name,
		Inception: uint32(time.Now().Add(-time.Hour).Unix()), Expiration: uint32(time.Now().Add(time.Hour).Unix()),
	}
	if err := sig.Sign(z.priv, rrset); err != nil {
		t.Fatal(err)
	}

	return sig
}

// pocWildcardNSEC returns the NSEC of example. at owner whose next name is next.
func pocWildcardNSEC(owner, next string, types ...uint16) *dns.NSEC {
	hdr := dns.RR_Header{Name: owner, Rrtype: dns.TypeNSEC, Class: dns.ClassINET, Ttl: 300}

	return &dns.NSEC{Hdr: hdr, NextDomain: next, TypeBitMap: types}
}

// pocWildcardNSEC3 returns an NSEC3 of example. (SHA-1, no salt, no extra iterations) from H(name)
// plus from to H(name) plus to, modulo 2^160: (-1, 1) covers H(name) only, (0, 1) matches name.
func pocWildcardNSEC3(t *testing.T, name string, from, to int64, types ...uint16) *dns.NSEC3 {
	t.Helper()

	enc := base32.HexEncoding.WithPadding(base32.NoPadding)

	h, err := enc.DecodeString(dns.HashName(name, dns.SHA1, 0, ""))
	if err != nil {
		t.Fatal(err)
	}

	add := func(delta int64) string {
		x := new(big.Int).Add(new(big.Int).SetBytes(h), big.NewInt(delta))

		return enc.EncodeToString(x.Mod(x, new(big.Int).Lsh(big.NewInt(1), 160)).FillBytes(make([]byte, 20)))
	}

	owner := strings.ToLower(add(from)) + ".example."

	return &dns.NSEC3{
		Hdr:  dns.RR_Header{Name: owner, Rrtype: dns.TypeNSEC3, Class: dns.ClassINET, Ttl: 300},
		Hash: dns.SHA1, HashLength: 20, NextDomain: add(to), TypeBitMap: types,
	}
}

func pocWildcardA(name string) *dns.A {
	hdr := dns.RR_Header{Name: name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300}

	return &dns.A{Hdr: hdr, A: net.IPv4(192, 0, 2, 1)}
}
```

</details>

### References

- RFC 4034 [§6.1](https://www.rfc-editor.org/rfc/rfc4034#section-6.1); RFC 4035 [§5.3.3](https://www.rfc-editor.org/rfc/rfc4035#section-5.3.3), [§5.3.4](https://www.rfc-editor.org/rfc/rfc4035#section-5.3.4) and [§5.4](https://www.rfc-editor.org/rfc/rfc4035#section-5.4); RFC 4592 [§4.7](https://www.rfc-editor.org/rfc/rfc4592#section-4.7); RFC 5155 [§8.7](https://www.rfc-editor.org/rfc/rfc5155#section-8.7), [§8.8](https://www.rfc-editor.org/rfc/rfc5155#section-8.8) and [§9.2](https://www.rfc-editor.org/rfc/rfc5155#section-9.2); RFC 6840 [§4.3](https://www.rfc-editor.org/rfc/rfc6840#section-4.3)
- Fix: [Blocky v0.37.0](https://github.com/0xERR0R/blocky/releases/tag/v0.37.0), commit [`1c4c01b`](https://github.com/0xERR0R/blocky/commit/1c4c01b35ecbc26df7fb09f015f4912e8c6a7bbb)
- Related advisories from the same review:
  - [GHSA-rfc7-q64c-hj2f](https://github.com/0xERR0R/blocky/security/advisories/GHSA-rfc7-q64c-hj2f): DNSSEC: DS and DNSKEY lookups that fail, are unsigned or are for another zone are trusted
  - [GHSA-8mfq-h5hh-mqf2](https://github.com/0xERR0R/blocky/security/advisories/GHSA-8mfq-h5hh-mqf2): DNSSEC: a response's status doesn't account for all of its parts, its question or its rcode
  - [GHSA-6fgw-qmpq-vwxp](https://github.com/0xERR0R/blocky/security/advisories/GHSA-6fgw-qmpq-vwxp): DNSSEC: NSEC and NSEC3 denials are accepted from zones not authoritative for the queried name
  - [GHSA-g35c-mff8-4w2w](https://github.com/0xERR0R/blocky/security/advisories/GHSA-g35c-mff8-4w2w): DNSSEC: a failed signature by a large-exponent RSA key gives Insecure instead of Bogus
  - [GHSA-583r-m4vv-q43p](https://github.com/0xERR0R/blocky/security/advisories/GHSA-583r-m4vv-q43p): DNSSEC: NSEC3 Opt-Out proof can downgrade a signed zone to Insecure
  - [GHSA-vgm3-vqcv-4hv6](https://github.com/0xERR0R/blocky/security/advisories/GHSA-vgm3-vqcv-4hv6): DNSSEC: RSA keys with very large exponents make validation expensive

### Credits

Reported by @kevinpark1217.

## References

- https://github.com/0xERR0R/blocky/security/advisories/GHSA-mv8x-2h8p-g3wh

Page: https://cve.now/GHSA-MV8X-2H8P-G3WH

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
