# GHSA-583R-M4VV-Q43P: DNSSEC: NSEC3 Opt-Out proof can downgrade a signed zone to Insecure

- Database: GitHub
- Severity: CVSS 5.9 (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

Blocky could treat a signed delegation as unsigned when its parent used NSEC3 Opt-Out and the evidence for the absence of a DS record was incomplete. This could cause answers to be served rather than rejected. A forged answer for a name in such a zone reached clients without the AD flag instead of SERVFAIL, for any signed zone under an Opt-Out parent such as `com.`, `net.` or `org.`. Blocky v0.37.0 refuses the incomplete proof.

### Impact

Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver. The forged answer is served as unsigned data, so a client that itself requires the AD flag is not misled; a client that relies on Blocky to refuse it is.

### 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. All three cases of the Details are in every one of these releases.

### Remediation

Upgrade to [Blocky v0.37.0](https://github.com/0xERR0R/blocky/releases/tag/v0.37.0) or later. The fix requires the complete parent-zone proof before accepting an insecure delegation. 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).

To treat a child zone as unsigned, a validator needs an authenticated proof from the parent zone that the child has no DS record. Where the parent uses Opt-Out and no NSEC3 record matches the child’s name, [RFC 5155 §8.6](https://www.rfc-editor.org/rfc/rfc5155#section-8.6) asks for two things:

- the **closest provable encloser** (closest encloser for short): the nearest ancestor of the name that an NSEC3 record matches ([§8.3](https://www.rfc-editor.org/rfc/rfc5155#section-8.3));
- an NSEC3 record with the Opt-Out flag that **covers** the **next closer name**, the name one label longer than the closest encloser. A record covers a hash that falls between its owner hash and its next hash ([§1.3](https://www.rfc-editor.org/rfc/rfc5155#section-1.3)).

The proof in `resolver/dnssec/nsec3.go` was looser in three ways:

1. **Next closer name.** The proof tested the hash of the queried name, not of the next closer name, and asked for no closest encloser. [`checkWildcardNSEC3Match`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec3.go#L283-L347) falls back to this check both where it found no closest encloser and where it found one:

   ```go
   if qtype == dns.TypeDS && v.nsec3CoversWithOptOut(nsec3Records, qnameHash) {
   	v.logger.Debugf("DS query for %s covered by NSEC3 Opt-Out - unsigned delegation", qname)

   	return ValidationResultInsecure
   }
   ```

   The NXDOMAIN proof in the same file already used the next closer name.
2. **Cover.** [`nsec3HashInRange`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec3.go#L449-L473) accepted `cmpHashNext <= 0`, so a hash equal to the next hash counted as covered. That hash belongs to a name that exists ([§3.1.7](https://www.rfc-editor.org/rfc/rfc5155#section-3.1.7)).
3. **Closest encloser at a delegation.** [`findClosestEncloser`](https://github.com/0xERR0R/blocky/blob/v0.36.0/resolver/dnssec/nsec3.go#L350-L399) took the first ancestor that an NSEC3 record matched, whatever its type bits. The record of a delegation (NS bit without SOA bit) or of a DNAME must not serve as the closest encloser (§8.3, and [RFC 6840 §4.1](https://www.rfc-editor.org/rfc/rfc6840#section-4.1) for the delegation).

Unbound 1.26.2 (`nsec3_prove_nods()` in `validator/val_nsec3.c`) and Knot Resolver 6.5.1 (`kr_nsec3_no_data()` in `lib/dnssec/nsec3.c`) apply all three rules.

### Proof of concept

The test shows cases 1 and 2 on synthetic NSEC3 records of `example.`, which delegates the signed zone `signed.example.`: first in `nsec3HashInRange` and in `validateDSAbsenceProof`, the check of a DS denial, then for a whole response. Case 3 has no test.

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

```sh
go test -run TestGHSA583rOptOut -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
[2]  FAIL  an NSEC3 does not cover its next hashed owner name
           nsec3HashInRange(H, owner H-2, next H) = true, want false
           nsec3HashInRange(H, owner H+5, next H) = true, want false
[1]  FAIL  an Opt-Out DS proof must cover the next closer name
           with closest encloser proof: validateDSAbsenceProof = Insecure, want Bogus
           without: validateDSAbsenceProof = Insecure, want Bogus
     PASS  control: signed answer for www.signed.example. is Secure
[2]  FAIL  unsigned answer for signed.example., DS denied by the Opt-Out NSEC3 ending at its hash is Bogus
           got Insecure, want Bogus
[1]  FAIL  unsigned answer for www.signed.example., DS denied by an Opt-Out NSEC3 covering its hash is Bogus
           got Insecure, want Bogus
```

The whole-response line of case 2 has no closest encloser either, so it rests on case 1 as well.

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

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

```go
package dnssec

// GHSA-583r-m4vv-q43p: NSEC3 Opt-Out proofs.
//
// RFC 5155 §1.3: an NSEC3 RR covers a hash that sorts strictly between its owner's hash and its
// Next Hashed Owner Name; the next hashed owner name itself is not covered.
// RFC 5155 §8.6: an Opt-Out proof that a name has no DS RRset needs a closest encloser proof and
// an NSEC3 with the Opt-Out flag set that covers the next closer name, not the query name.
//
// example. is a trust anchor and signed.example. a secure delegation (a signed DS RRset). An
// unsigned answer for a name in signed.example. is Bogus unless its DS RRset is proven absent.
//
// go test -run TestGHSA583rOptOut -v ./resolver/dnssec/

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

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

func TestGHSA583rOptOut(t *testing.T) {
	ctx := t.Context()
	logger, _ := log.NewMockEntry()
	h := func(name string) string { return dns.HashName(name, dns.SHA1, 0, "") }

	t.Run("an NSEC3 does not cover its next hashed owner name", func(t *testing.T) {
		hash := h("signed.example.")
		if nsec3HashInRange(hash, poc583rHashAdd(t, hash, -2), hash) {
			t.Error("nsec3HashInRange(H, owner H-2, next H) = true, want false")
		}

		if nsec3HashInRange(hash, poc583rHashAdd(t, hash, 5), hash) { // owner > next: wraps around
			t.Error("nsec3HashInRange(H, owner H+5, next H) = true, want false")
		}
	})

	t.Run("an Opt-Out DS proof must cover the next closer name", func(t *testing.T) {
		// DS for a.b.example.: the closest encloser is example., the next closer name b.example.
		// The Opt-Out NSEC3 span covers H(a.b.example.) and no other hash.
		hApex, hQ := h("example."), h("a.b.example.")
		apex := poc583rNSEC3(t, hApex, 1, dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeDNSKEY, dns.TypeNSEC3PARAM)
		span := poc583rNSEC3(t, poc583rHashAdd(t, hQ, -1), 2, dns.TypeNS, dns.TypeDS, dns.TypeRRSIG)
		v := NewValidator(ctx, nil, logger, nil, 1, 10, 150, 30, 3600)

		for _, c := range []struct {
			name string
			ns   []dns.RR
		}{{"with closest encloser proof", []dns.RR{apex, span}}, {"without", []dns.RR{span}}} {
			if got := v.validateDSAbsenceProof("a.b.example.", &dns.Msg{Ns: c.ns}, false); got != ValidationResultBogus {
				t.Errorf("%s: validateDSAbsenceProof = %s, want Bogus", c.name, got)
			}
		}
	})

	example, signed := newPoc583rZone(t, "example."), newPoc583rZone(t, "signed.example.")
	anchors, err := NewTrustAnchorStore([]string{example.key.String()})
	if err != nil {
		t.Fatal(err)
	}

	answers := map[string]dns.Msg{
		"example. DNSKEY":        {Answer: example.sign(t, example.key)},
		"signed.example. DS":     {Answer: example.sign(t, signed.key.ToDS(dns.SHA256))},
		"signed.example. DNSKEY": {Answer: signed.sign(t, signed.key)},
	}
	validate := func(upstream map[string]dns.Msg, qname string, answer ...dns.RR) ValidationResult {
		v := NewValidator(ctx, anchors, logger, &mockResolver{
			ResolveFn: func(_ context.Context, req *model.Request) (*model.Response, error) {
				reply := upstream[req.Req.Question[0].Name+" "+dns.TypeToString[req.Req.Question[0].Qtype]]

				return &model.Response{Res: &reply}, nil
			},
		}, 1, 10, 150, 30, 3600)

		q := dns.Question{Name: qname, Qtype: dns.TypeA, Qclass: dns.ClassINET}

		return v.ValidateResponse(ctx, &dns.Msg{Answer: answer}, q)
	}

	t.Run("control: signed answer for www.signed.example. is Secure", func(t *testing.T) {
		answer := signed.sign(t, poc583rA("www.signed.example."))
		if got := validate(answers, "www.signed.example.", answer...); got != ValidationResultSecure {
			t.Errorf("got %s, want Secure", got)
		}
	})

	hSigned, hWWW := h("signed.example."), h("www.signed.example.")
	for _, c := range []struct {
		name, qname string
		nsec3       *dns.NSEC3
	}{
		{
			"unsigned answer for signed.example., DS denied by the Opt-Out NSEC3 ending at its hash",
			"signed.example.", poc583rNSEC3(t, poc583rHashAdd(t, hSigned, -1), 1, dns.TypeNS, dns.TypeDS, dns.TypeRRSIG),
		},
		{
			"unsigned answer for www.signed.example., DS denied by an Opt-Out NSEC3 covering its hash",
			"www.signed.example.", poc583rNSEC3(t, poc583rHashAdd(t, hWWW, -1), 2, dns.TypeNS, dns.TypeDS, dns.TypeRRSIG),
		},
	} {
		t.Run(c.name+" is Bogus", func(t *testing.T) {
			denied := maps.Clone(answers)
			denied[c.qname+" DS"] = dns.Msg{Ns: example.sign(t, c.nsec3)}

			if got := validate(denied, c.qname, poc583rA(c.qname)); got != ValidationResultBogus {
				t.Errorf("got %s, want Bogus", got)
			}
		})
	}
}

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

// newPoc583rZone returns an ECDSA P-256 key-signing key for zone.
func newPoc583rZone(t *testing.T, zone string) poc583rZone {
	t.Helper()

	key := &dns.DNSKEY{
		Hdr:   dns.RR_Header{Name: zone, 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 poc583rZone{key, priv.(crypto.Signer)}
}

// sign returns rrset followed by its RRSIG, made by z with RRSIG.Sign.
func (z poc583rZone) sign(t *testing.T, rrset ...dns.RR) []dns.RR {
	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 append(rrset, sig)
}

// poc583rNSEC3 returns an NSEC3 of example. with the Opt-Out flag set (SHA-1, no salt, no extra
// iterations) from the hash owner to owner+span.
func poc583rNSEC3(t *testing.T, owner string, span int64, types ...uint16) *dns.NSEC3 {
	t.Helper()

	name := strings.ToLower(owner) + ".example."

	return &dns.NSEC3{
		Hdr:  dns.RR_Header{Name: name, Rrtype: dns.TypeNSEC3, Class: dns.ClassINET, Ttl: 300},
		Hash: dns.SHA1, Flags: 1, HashLength: 20, NextDomain: poc583rHashAdd(t, owner, span), TypeBitMap: types,
	}
}

// poc583rHashAdd returns the NSEC3 hash h plus delta, modulo 2^160.
func poc583rHashAdd(t *testing.T, h string, delta int64) string {
	t.Helper()

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

	b, err := enc.DecodeString(h)
	if err != nil {
		t.Fatal(err)
	}

	x := new(big.Int).Add(new(big.Int).SetBytes(b), big.NewInt(delta))

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

func poc583rA(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 5155 [§1.3](https://www.rfc-editor.org/rfc/rfc5155#section-1.3), [§3.1.7](https://www.rfc-editor.org/rfc/rfc5155#section-3.1.7), [§8.3](https://www.rfc-editor.org/rfc/rfc5155#section-8.3) and [§8.6](https://www.rfc-editor.org/rfc/rfc5155#section-8.6); RFC 6840 [§4.1](https://www.rfc-editor.org/rfc/rfc6840#section-4.1)
- 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-mv8x-2h8p-g3wh](https://github.com/0xERR0R/blocky/security/advisories/GHSA-mv8x-2h8p-g3wh): DNSSEC: incomplete denial-of-existence proofs (wildcards, NSEC NXDOMAIN, CNAME bit, name order)
  - [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-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-583r-m4vv-q43p

Page: https://cve.now/GHSA-583R-M4VV-Q43P

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