DNSSEC: NSEC and NSEC3 denials are accepted from zones not authoritative for the queried name
Description
Blocky could accept a signed denial from a zone that was not authoritative for the queried name. This could cause a name to be incorrectly reported as nonexistent or a signed delegation to be treated as unsigned. The validator checked that NSEC and NSEC3 records were validly signed by some zone, but not that this zone holds the name, so the records of an unrelated signed zone, or of the parent at a zone cut, passed as proof. Blocky v0.37.0 refuses such a denial, and a DS record set that the child zone itself signed.
Impact
Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver. For each case of the Details:
| Case | Also needed | Effect |
|---|---|---|
| 1 | a DNSSEC-signed zone of their own, which any domain registrant can have | any signed zone looks unsigned: forged answers for it are served without the AD flag |
| 2 | the same | NXDOMAIN for any name, marked authenticated (AD flag) |
| 3 | nothing: the parent’s NSEC record at the zone cut is public | an authenticated "no data" answer for the delegated name, or NXDOMAIN for a name below it |
| 4 | the private key of the child zone | the AD flag on a DS record set that the parent never published |
| 5 | a deployment with a trust anchor below another one | unsigned answers and NXDOMAIN under the lower anchor are served as unsigned data |
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. Cases 1 to 4 of the Details are in every one of these releases. Case 5 needs a trust anchor configured below another one (dnssec.trustAnchors), which the default configuration does not have; the test shows it from v0.28.2 on, and for the unsigned answer in v0.28.0 and v0.28.1 too. Before v0.36.0 a signed answer under the lower anchor, the control of the case, fails as well.
Remediation
Upgrade to Blocky v0.37.0 or later. The fix checks the authority of the zone providing the evidence and respects delegation and trust-anchor boundaries. It is commit 1c4c01b.
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).
NSEC and NSEC3 records describe only names of the zone that holds them: the owner of an NSEC3 record is a hash prepended to the name of that zone (RFC 5155 §3), and the signer of a record must be that zone (RFC 4035 §5.3.1). At a zone cut the parent is authoritative for the delegation only, so its NSEC or NSEC3 record there (NS bit set, SOA bit clear) proves nothing about the child’s records or the names below the cut, except that the DS record is absent (RFC 6840 §4.1).
Blocky checked that denial records were validly signed by some zone, but not by which one:
- NSEC3 from another zone.
validateNSEC3DenialOfExistencetook the zone from the owner of the first NSEC3 record and never checked that it encloses the queried name, and records were matched by their first label, the hash, alone:
``go ownerName := nsec3Records[0].Hdr.Name labels := dns.SplitDomainName(ownerName) if len(labels) > 1 { zoneName = dns.Fqdn(strings.Join(labels[1:], ".")) } ``
So <hash of signed.example.>.other., signed by other., was proof that signed.example. has no DS record.
- NSEC from another zone.
validateNSECNXDOMAINaccepted any NSEC record that covers the name. The apex NSEC record of an unrelated zone whose next name is that apex itself covers every other name. - The parent’s NSEC at a zone cut.
validateNSECNODATAaccepted the parent’s NSEC record forsigned.example.as proof that the child has no A record, and the NXDOMAIN check accepted it for names below the cut.
Both validateDenialOfExistence and isAuthenticatedDSDenial only called validateRRsets, which requires the signer to be an ancestor of each record’s owner, not of the queried name. Unbound 1.26.2 drops signers that are not a parent of the queried name and uses only the NSEC3 records of the closest enclosing zone (processInit() in validator/validator.c, filter_init() in validator/val_nsec3.c), and rejects delegation records at and below the cut (nsec_proves_nodata() and val_nsec_proves_name_error() in validator/val_nsec.c, nsec3_do_prove_nodata() in validator/val_nsec3.c).
Two more cases follow from the same missing check of who may speak for a name:
- A DS answer signed by the child. DS records belong to the parent zone, so the parent must sign them (RFC 4035 §5.3.1). For an answer of type DS,
tryVerifyWithRRSIGonly required the signer to be the owner or an ancestor of it, sosigned.example. DSsigned bysigned.example.was Secure. The walk down the chain of trust itself rejects such a DS record set. - A proof from above a trust anchor. With trust anchors for the root and for
corp.example.com., the Opt-Out proof ofcom.for the unsignedexample.com.made unsigned answers and NXDOMAIN undercorp.example.com.Insecure. Which anchor decides is an implementation choice (RFC 6840 §5.10); under the policy that the RFC suggests as a default ("Accept Any Success", Appendix C.2) a result is Insecure only if every applicable anchor gives Insecure, and the lower anchor gives Bogus here.
Proof of concept
The test shows the five cases on synthetic zones: example. and other. are trust anchors, and signed.example. is a signed delegation of example.; case 5 has anchors for the root and for corp.example.com..
To reproduce, save the test file below as resolver/dnssec/ghsa_6fgw_qmpq_vwxp_poc_test.go in a checkout of the version to test and run:
go test -run TestGHSA6fgwDenialFromAnotherZone -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:
PASS control: signed answer for www.signed.example. is Secure
PASS control: in other., the NSEC3 proves that x.other. has no DS RRset
[1] FAIL an NSEC3 of other. does not prove that signed.example. has no DS RRset
validateDSAbsenceProof = Secure, want no proof (neither Secure nor Insecure)
unsigned answer for signed.example.: got Insecure, want Bogus
[2] FAIL an NSEC of other. proves only that names of other. do not exist
NXDOMAIN for www.signed.example.: got Secure, want Bogus
[3] FAIL the NSEC of example. at the zone cut proves nothing in signed.example.
NOERROR for signed.example. A: got Secure, want Bogus
NXDOMAIN for www.signed.example. A: got Secure, want Bogus
[4] FAIL a DS RRset is signed by the parent zone, not by the zone it names
signed.example. DS signed by signed.example.: got Secure, want Bogus
[5] FAIL the Opt-Out proof of com. proves nothing under the trust anchor corp.example.com.
NXDOMAIN with the proof of com. for nx.corp.example.com. A: got Insecure, want Bogus
unsigned answer (DS reply: NXDOMAIN with the proof of com.) for www.corp.example.com. A: got Insecure, want BogusOn v0.37.0 it exits with status 0: all 7 test cases pass.
<details> <summary><code>ghsa_6fgw_qmpq_vwxp_poc_test.go</code></summary>
package dnssec
// GHSA-6fgw-qmpq-vwxp: NSEC and NSEC3 records from another zone.
//
// RFC 5155 §1.3 and §3: an NSEC3 RR is owned by the hash of a name prepended as a single label to
// the name of the zone that contains it, and matches only names of that zone. A proof that a
// delegation has no DS RRset must therefore come from the zone above the delegation. RFC 4035
// §5.3.1 and §5.4: an NSEC RR is signed by the zone that contains it and proves only that names of
// that zone do not exist.
//
// example. and other. are separate trust anchors; signed.example. is a secure delegation (a
// signed DS RRset). The NSEC3 <H(signed.example.)>.other., signed by other., is not in example.
// and proves nothing about signed.example.: an unsigned answer for signed.example. stays Bogus.
// The NSEC of the apex of other. whose next name is its own covers every other name, but proves
// only that names of other. do not exist. RFC 6840 §4.1: the NSEC of example. at the delegation
// signed.example. (NS set, SOA clear) is from the parent side of the zone cut and proves nothing
// at or below it but the absence of DS.
//
// RFC 4035 §5.3.1: the signer of an RRSIG is the zone that contains the RRset. RFC 4035 §2.4: a
// DS RRset is never at a zone's apex; it is in the parent zone (RFC 4034 §5). The DS RRset of
// signed.example. with an RRSIG by signed.example. itself is Bogus.
//
// RFC 6840 §5.10 and Appendix C: where more than one trust anchor applies, the suggested policy
// gives Insecure only if every one of them gives Insecure. In the last group the root and corp.example.com. are trust anchors;
// com. is a secure delegation signed with NSEC3 Opt-Out and delegates example.com. without a DS
// RRset. The proof of com. that example.com. has no DS RRset (RFC 5155 §8.6) gives Insecure
// through the root. Under corp.example.com. it proves nothing: an NXDOMAIN for
// nx.corp.example.com. that holds it, and an unsigned answer for www.corp.example.com. whose DS
// query is answered with it, are Bogus (RFC 4035 §4.3).
//
// go test -run TestGHSA6fgwDenialFromAnotherZone -v ./resolver/dnssec/
import (
"context"
"crypto"
"maps"
"net"
"strings"
"testing"
"time"
"github.com/0xERR0R/blocky/log"
"github.com/0xERR0R/blocky/model"
"github.com/miekg/dns"
)
func TestGHSA6fgwDenialFromAnotherZone(t *testing.T) {
ctx := t.Context()
logger, _ := log.NewMockEntry()
example, other := newPoc6fgwZone(t, "example."), newPoc6fgwZone(t, "other.")
signed := newPoc6fgwZone(t, "signed.example.")
anchors, err := NewTrustAnchorStore([]string{example.key.String(), other.key.String()})
if err != nil {
t.Fatal(err)
}
// dsDenial is a DS NODATA reply for name made of one NSEC3 of other. (NS bit set, DS and SOA
// bits clear) owned by the hash of name, signed by other.
dsDenial := func(name string) *dns.Msg {
hash := func(name string) string { return dns.HashName(name, dns.SHA1, 0, "") }
owner := strings.ToLower(hash(name)) + ".other."
nsec3 := &dns.NSEC3{
Hdr: dns.RR_Header{Name: owner, Rrtype: dns.TypeNSEC3, Class: dns.ClassINET, Ttl: 300},
Hash: dns.SHA1, HashLength: 20, NextDomain: hash("other."), TypeBitMap: []uint16{dns.TypeNS, dns.TypeRRSIG},
}
return &dns.Msg{Ns: other.sign(t, nsec3)}
}
answers := map[string]*dns.Msg{
"example. DNSKEY": {Answer: example.sign(t, example.key)},
"other. DNSKEY": {Answer: other.sign(t, other.key)},
"signed.example. DS": {Answer: example.sign(t, signed.key.ToDS(dns.SHA256))},
"signed.example. DNSKEY": {Answer: signed.sign(t, signed.key)},
"x.other. DS": dsDenial("x.other."),
}
validatorFor := func(store *TrustAnchorStore, upstream map[string]*dns.Msg) *Validator {
return NewValidator(ctx, store, logger, &mockResolver{
ResolveFn: func(_ context.Context, req *model.Request) (*model.Response, error) {
q := req.Req.Question[0]
if m, ok := upstream[q.Name+" "+dns.TypeToString[q.Qtype]]; ok {
return &model.Response{Res: m}, nil
}
return &model.Response{Res: new(dns.Msg)}, nil
},
}, 1, 10, 150, 30, 3600)
}
newValidator := func(upstream map[string]*dns.Msg) *Validator { return validatorFor(anchors, upstream) }
questionA := func(name string) dns.Question {
return dns.Question{Name: name, Qtype: dns.TypeA, Qclass: dns.ClassINET}
}
t.Run("control: signed answer for www.signed.example. is Secure", func(t *testing.T) {
answer := &dns.Msg{Answer: signed.sign(t, poc6fgwA("www.signed.example."))}
got := newValidator(answers).ValidateResponse(ctx, answer, questionA("www.signed.example."))
if got != ValidationResultSecure {
t.Errorf("got %s, want Secure", got)
}
})
t.Run("control: in other., the NSEC3 proves that x.other. has no DS RRset", func(t *testing.T) {
v := newValidator(answers)
if got := v.validateDSAbsenceProof("x.other.", dsDenial("x.other."), false); got != ValidationResultSecure {
t.Errorf("validateDSAbsenceProof = %s, want Secure", got)
}
answer := &dns.Msg{Answer: []dns.RR{poc6fgwA("x.other.")}}
if got := v.ValidateResponse(ctx, answer, questionA("x.other.")); got != ValidationResultInsecure {
t.Errorf("unsigned answer for x.other.: got %s, want Insecure", got)
}
})
t.Run("an NSEC3 of other. does not prove that signed.example. has no DS RRset", func(t *testing.T) {
denied := maps.Clone(answers)
denied["signed.example. DS"] = dsDenial("signed.example.")
v := newValidator(denied)
got := v.validateDSAbsenceProof("signed.example.", denied["signed.example. DS"], false)
if got == ValidationResultSecure || got == ValidationResultInsecure {
t.Errorf("validateDSAbsenceProof = %s, want no proof (neither Secure nor Insecure)", got)
}
answer := &dns.Msg{Answer: []dns.RR{poc6fgwA("signed.example.")}}
if got := v.ValidateResponse(ctx, answer, questionA("signed.example.")); got != ValidationResultBogus {
t.Errorf("unsigned answer for signed.example.: got %s, want Bogus", got)
}
})
t.Run("an NSEC of other. proves only that names of other. do not exist", func(t *testing.T) {
apex := &dns.NSEC{
Hdr: dns.RR_Header{Name: "other.", Rrtype: dns.TypeNSEC, Class: dns.ClassINET, Ttl: 300},
NextDomain: "other.",
TypeBitMap: []uint16{dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeNSEC, dns.TypeDNSKEY},
}
nxdomain := &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeNameError}, Ns: other.sign(t, apex)}
for _, c := range []struct {
name string
want ValidationResult
}{{"x.other.", ValidationResultSecure}, {"www.signed.example.", ValidationResultBogus}} {
if got := newValidator(answers).ValidateResponse(ctx, nxdomain, questionA(c.name)); got != c.want {
t.Errorf("NXDOMAIN for %s: got %s, want %s", c.name, got, c.want)
}
}
})
t.Run("the NSEC of example. at the zone cut proves nothing in signed.example.", func(t *testing.T) {
cut := &dns.NSEC{
Hdr: dns.RR_Header{Name: "signed.example.", Rrtype: dns.TypeNSEC, Class: dns.ClassINET, Ttl: 300},
NextDomain: "z.example.",
TypeBitMap: []uint16{dns.TypeNS, dns.TypeDS, dns.TypeRRSIG, dns.TypeNSEC},
}
for _, c := range []struct {
rcode int
name string
}{{dns.RcodeSuccess, "signed.example."}, {dns.RcodeNameError, "www.signed.example."}} {
reply := &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: c.rcode}, Ns: example.sign(t, cut)}
if got := newValidator(answers).ValidateResponse(ctx, reply, questionA(c.name)); got != ValidationResultBogus {
t.Errorf("%s for %s A: got %s, want Bogus", dns.RcodeToString[c.rcode], c.name, got)
}
}
})
t.Run("a DS RRset is signed by the parent zone, not by the zone it names", func(t *testing.T) {
ds := signed.key.ToDS(dns.SHA256)
question := dns.Question{Name: "signed.example.", Qtype: dns.TypeDS, Qclass: dns.ClassINET}
for _, c := range []struct {
signer poc6fgwZone
want ValidationResult
}{{example, ValidationResultSecure}, {signed, ValidationResultBogus}} {
answer := &dns.Msg{Answer: c.signer.sign(t, ds)}
if got := newValidator(answers).ValidateResponse(ctx, answer, question); got != c.want {
t.Errorf("signed.example. DS signed by %s: got %s, want %s", c.signer.key.Hdr.Name, got, c.want)
}
}
})
t.Run("the Opt-Out proof of com. proves nothing under the trust anchor corp.example.com.", func(t *testing.T) {
root, com, corp := newPoc6fgwZone(t, "."), newPoc6fgwZone(t, "com."), newPoc6fgwZone(t, "corp.example.com.")
nested, err := NewTrustAnchorStore([]string{root.key.String(), corp.key.String()})
if err != nil {
t.Fatal(err)
}
// The NSEC3 chain of com., with Opt-Out, holds its apex and the secure delegation
// secure.com. Its two NSEC3s prove that example.com. has no DS RRset: one matches com., the
// closest encloser, and one of the two covers the hash of example.com.
hash := func(name string) string { return dns.HashName(name, dns.SHA1, 0, "") }
nsec3 := func(name, next string, types ...uint16) []dns.RR {
owner := strings.ToLower(hash(name)) + ".com."
return com.sign(t, &dns.NSEC3{
Hdr: dns.RR_Header{Name: owner, Rrtype: dns.TypeNSEC3, Class: dns.ClassINET, Ttl: 300},
Hash: dns.SHA1, Flags: 1, HashLength: 20, NextDomain: hash(next), TypeBitMap: types,
})
}
proof := append(
nsec3("com.", "secure.com.", dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeDNSKEY, dns.TypeNSEC3PARAM),
nsec3("secure.com.", "com.", dns.TypeNS, dns.TypeDS, dns.TypeRRSIG)...)
nxdomain := &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeNameError}, Ns: proof}
const www, nx = "www.corp.example.com.", "nx.corp.example.com."
upstream := map[string]*dns.Msg{
". DNSKEY": {Answer: root.sign(t, root.key)},
"com. DS": {Answer: root.sign(t, com.key.ToDS(dns.SHA256))},
"com. DNSKEY": {Answer: com.sign(t, com.key)},
"corp.example.com. DNSKEY": {Answer: corp.sign(t, corp.key)},
www + " DS": nxdomain,
}
signedA, unsignedA := &dns.Msg{Answer: corp.sign(t, poc6fgwA(www))}, &dns.Msg{Answer: []dns.RR{poc6fgwA(www)}}
for _, c := range []struct {
reply, qname string
msg *dns.Msg
want ValidationResult
}{
{"control: answer signed by corp.example.com.", www, signedA, ValidationResultSecure},
{"control: NXDOMAIN with the proof of com.", "nx.example.com.", nxdomain, ValidationResultInsecure},
{"NXDOMAIN with the proof of com.", nx, nxdomain, ValidationResultBogus},
{"unsigned answer (DS reply: NXDOMAIN with the proof of com.)", www, unsignedA, ValidationResultBogus},
} {
if got := validatorFor(nested, upstream).ValidateResponse(ctx, c.msg, questionA(c.qname)); got != c.want {
t.Errorf("%s for %s A: got %s, want %s", c.reply, c.qname, got, c.want)
}
}
})
}
type poc6fgwZone struct {
key *dns.DNSKEY
priv crypto.Signer
}
// newPoc6fgwZone returns an ECDSA P-256 key-signing key for zone.
func newPoc6fgwZone(t *testing.T, zone string) poc6fgwZone {
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 poc6fgwZone{key, priv.(crypto.Signer)}
}
// sign returns rrset followed by its RRSIG, made by z with RRSIG.Sign.
func (z poc6fgwZone) 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)
}
func poc6fgwA(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 4035 §5.3.1; RFC 5155 §3; RFC 6840 §4.1, §5.10 and Appendix C.2
- Fix: Blocky v0.37.0, commit
1c4c01b - Related advisories from the same review:
- GHSA-rfc7-q64c-hj2f: DNSSEC: DS and DNSKEY lookups that fail, are unsigned or are for another zone are trusted
- 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: DNSSEC: incomplete denial-of-existence proofs (wildcards, NSEC NXDOMAIN, CNAME bit, name order)
- GHSA-g35c-mff8-4w2w: DNSSEC: a failed signature by a large-exponent RSA key gives Insecure instead of Bogus
- GHSA-583r-m4vv-q43p: DNSSEC: NSEC3 Opt-Out proof can downgrade a signed zone to Insecure
- GHSA-vgm3-vqcv-4hv6: DNSSEC: RSA keys with very large exponents make validation expensive
Credits
Reported by @kevinpark1217.