DNSSEC: a response's status doesn't account for all of its parts, its question or its rcode
Description
Validating individual record sets did not always establish that the complete response answered the question. This could cause Blocky to mark a partially authenticated answer as authenticated, or serve data that should have been rejected. The validator settled the status of a response from some of its parts and compared neither the question nor the response code with what it had validated, so forged records, NXDOMAIN or "no data" answers for names in signed zones were passed on, several of them with the AD flag. Blocky v0.37.0 refuses these responses, and serves a CNAME chain that passes through a provably unsigned zone without the AD flag.
Impact
Exploiting this needs someone who can change the responses between Blocky and its upstream resolver, or a malicious upstream resolver. The name can be in any signed zone, and little of the zone’s signed data is needed. For each case of the Details:
| Case | Signed data needed | Served |
|---|---|---|
| 1 | none | as unsigned data, without the AD flag |
| 2 | at most the signed SOA of the zone, which is public | as unsigned data, without the AD flag |
| 3 | none | with the AD flag |
| 4 | a signed CNAME of the zone | with the AD flag |
| 7, 8 | a signed record set of the zone | with the AD flag |
Cases 5 and 6 put the AD flag on a response of which only a part was validated.
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. Case 5 of the Details starts with v0.28.1 (#1930); the other cases are in every one of these releases.
Remediation
Upgrade to Blocky v0.37.0 or later. The fix checks the response against the question, response code, and alias chain before assigning its validation status. 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).
A validator may treat data as unsigned only after proving that the name is below an insecure delegation (RFC 4033 §5); otherwise missing signatures or missing denial records make the response Bogus (RFC 4035 §4.3 and §5.4). And a response is Secure only when every record set in its answer and authority sections is authentic (§3.2.3).
Insecure where the response has to be Bogus. ValidateResponse asked whether the zone is signed only for a response without any RRSIG, the check that v0.32.0 added for GHSA-x845-2f78-7v36:
case !v.hasAnySignatures(response):
// ...
result = v.classifyUnsignedResponse(ctx, question)- Unsigned answer beside a signature.
validateRRsetsreturned Insecure for a section without RRSIGs, so an unsigned answer passed when an RRSIG sat in another section. The additional section is never verified, so that RRSIG could be random bytes. - Negative answer without NSEC or NSEC3.
validateNegativeResponsereturned Insecure when the authority section held no RRSIG, andvalidateDenialOfExistencereturned Insecure when that section was validly signed, by the zone’s own SOA for example, but held no NSEC or NSEC3 record.
Secure though not fully validated. For a response with an answer section, validateAnswer validated each record set of that section on its own. It checked neither the question, the response code nor the target of a CNAME, and it did not validate the authority section.
- Answer section with only an RRSIG.
validateRRsetsfell through to Secure when the section held no record set besides RRSIGs, so an RRSIG of random bytes gave an authenticated "no data" answer for any name:
``go // Shouldn't reach here, but return Secure as fallback return ValidationResultSecure ``
- CNAME whose target is not proven. A signed CNAME with NXDOMAIN, or with no data for its target, was Secure without any denial proof for the target.
- CNAME chain across a signed and an unsigned zone.
validateRRsetsreturned Secure when any record set was Secure and none was Bogus or Indeterminate:
``go // Per RFC 4035 §5.2: A mix of Secure and Insecure RRsets is acceptable // This happens with CNAME chains crossing from unsigned to signed zones (or vice versa) if hasSecure { // At least one RRset is validated with DNSSEC signatures return ValidationResultSecure } ``
DNSSECResolver.Resolve then set AD on the whole answer, the unsigned part included.
- Authority section of a positive answer. It was never validated, so unsigned or badly signed records there were passed on under AD.
- Answer that does not answer the question. A validly signed record set for another name or type, or a CNAME chain that does not lead to the answer, was Secure.
- NXDOMAIN with an answer. A response with the code NXDOMAIN and a signed answer for the name was Secure: an authenticated NXDOMAIN for a name that exists.
Unbound 1.26.2 requires every answer and authority record set to verify (validate_msg_signatures() in validator/validator.c), a denial proof for negative answers and for a CNAME chain that ends without data (validate_nameerror_response(), validate_nodata_response(), validate_cname_noanswer_response()), and keeps the lowest status across the steps of a CNAME chain as the result of the message (processFinished()).
Proof of concept
The test shows the eight cases in a synthetic zone example. that is a trust anchor; for case 5 the root is the anchor, with the signed example. and the unsigned test. below it.
To reproduce, save the test file below as resolver/dnssec/unproven_insecure_poc_test.go in a checkout of the version to test and run:
go test -run TestUnprovenInsecure -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:
negative answer without NSEC or NSEC3:
PASS control: NXDOMAIN for missing.example. A, signed SOA and NSEC
[2] FAIL NXDOMAIN for missing.example. A, signed SOA only
got Insecure, want Bogus
PASS control: NODATA for www.example. TXT, signed SOA and NSEC
[2] FAIL NODATA for www.example. TXT, signed SOA only
got Insecure, want Bogus
unsigned answer beside a signature elsewhere:
PASS control: answer signed
PASS control: no RRSIG anywhere
[1] FAIL signed SOA in the authority section
got Insecure, want Bogus
[1] FAIL RRSIG of random bytes in the additional section
got Insecure, want Bogus
CNAME chain across a signed and an unsigned zone:
PASS control: signed CNAME to a signed A in example.
PASS control: signed CNAME to an unsigned A in example.
[5] FAIL signed CNAME to an unsigned A in insecure test.
got Secure, want Insecure
[5] FAIL unsigned CNAME in insecure test. to a signed A in example.
got Secure, want Insecure
parts of the response that are never validated:
PASS control: signed answer, signed SOA in the authority section
[3] FAIL answer section with only an RRSIG of random bytes
got Secure, want Bogus
[6] FAIL signed answer, SOA with an RRSIG of random bytes in the authority section
got Secure, want Bogus
PASS control: signed CNAME to host.example., NXDOMAIN, signed SOA and NSEC
[4] FAIL signed CNAME to host.example., NXDOMAIN, signed SOA only
got Secure, want Bogus
[4] FAIL signed CNAME to host.example., NODATA, signed SOA only
got Secure, want Bogus
answers that do not answer the question:
PASS control: signed www.example. A
[7] FAIL signed other.example. A
got Secure, want Bogus
[7] FAIL signed www.example. TXT
got Secure, want Bogus
[7] FAIL signed CNAME to a.example., then signed b.example. A
got Secure, want Bogus
[8] FAIL NXDOMAIN with signed www.example. A
got Secure, want BogusOn v0.37.0 it exits with status 0: all 23 test cases pass.
<details> <summary><code>unproven_insecure_poc_test.go</code></summary>
package dnssec
// Unsigned and unproven answers for names under a trust anchor.
//
// RFC 4033 §5 and RFC 4035 §4.3: data under a trust anchor is Insecure only with signed proof that
// a delegation above it has no DS RRset; with signatures or proofs missing it is Bogus.
// RFC 4035 §5.4: a negative answer (NXDOMAIN or NODATA) is proven by authenticated NSEC or NSEC3
// RRs; a signed SOA alone proves nothing, so the answer is Bogus.
// RFC 4035 §3.1.1 and §5.3: an RRset in the answer section is authenticated by its RRSIGs, which
// are in the answer section; an RRSIG elsewhere in the message, valid or not, leaves it unsigned,
// so it is Bogus.
// RFC 4035 §3.2.3: AD is set only when every RRset in the answer and authority sections is
// authentic. A CNAME chain between a signed zone and a provably insecure one holds a Secure and an
// Insecure RRset, so the answer is Insecure.
// RFC 4035 §3.2.3 again: the authority section counts as much as the answer, so a signed answer
// beside an authority-section RRset whose RRSIG is random bytes is not authentic; it is Bogus, as
// in Unbound. An answer section holding only an RRSIG holds no A RRset and no NSEC or NSEC3 RRs
// proving there is none (§5.4), so it is Bogus too.
// RFC 4035 §3.1.3 and §5.4: a CNAME chain that ends in NXDOMAIN or NODATA is proven by NSEC or
// NSEC3 RRs for the CNAME's target; a signed CNAME and SOA alone prove nothing, so it is Bogus.
// RFC 4035 §5.4 requires a proof for every negative answer. An answer is the chain from the query
// name: the RRset of the query type at that name or at the end of its CNAMEs. A signed RRset of
// another name or type, or one that the CNAME before it does not lead to, answers nothing, and no
// NSEC or NSEC3 RRs prove that there is no answer; with NXDOMAIN, a signed RRset of the query name
// contradicts the rcode and nothing proves that the name does not exist. Each is Bogus.
//
// In every group but the third example. is a trust anchor without delegations, holding
// www.example. A; its SOA, its NSEC RRs and www.example. A are signed by its key. The CNAME cases of
// the fourth group hold www.example. CNAME host.example. instead, and host.example. does not
// exist. The other RRsets of the fifth group (other.example. A, www.example. TXT, www.example.
// CNAME a.example. and b.example. A) are signed by the same key. In the third the root is the
// trust anchor with two delegations: example., whose DS RRset the root signs, and test., an
// insecure delegation proven by the root's signed NSEC at test. with the NS bit set and no DS bit.
//
// go test -run TestUnprovenInsecure -v ./resolver/dnssec/
import (
"context"
"crypto"
"crypto/rand"
"encoding/base64"
"net"
"slices"
"testing"
"time"
"github.com/0xERR0R/blocky/log"
"github.com/0xERR0R/blocky/model"
"github.com/miekg/dns"
)
func TestUnprovenInsecure(t *testing.T) {
zone := newPocUnprovenZone(t, "example.")
dnskey := zone.sign(t, zone.key)
type testCase struct {
name string
reply *dns.Msg
want ValidationResult
}
secure, insecure, bogus := ValidationResultSecure, ValidationResultInsecure, ValidationResultBogus
// run validates each case's reply to the question qname qtype with the key of anchor as the
// trust anchor. upstream answers the validator's queries by "name TYPE"; any other query gets
// an empty NOERROR reply.
run := func(
t *testing.T, anchor pocUnprovenZone, upstream map[string]*dns.Msg, qname string, qtype uint16, cases ...testCase,
) {
anchors, err := NewTrustAnchorStore([]string{anchor.key.String()})
if err != nil {
t.Fatal(err)
}
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, 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.Copy()}, nil
}
return &model.Response{Res: new(dns.Msg)}, nil
},
}, 1, 10, 150, 30, 3600)
q := dns.Question{Name: qname, Qtype: qtype, Qclass: dns.ClassINET}
if got := v.ValidateResponse(t.Context(), c.reply, q); got != c.want {
t.Errorf("got %s, want %s", got, c.want)
}
})
}
}
exampleOnly := map[string]*dns.Msg{"example. DNSKEY": {Answer: dnskey}}
soa := zone.sign(t, pocUnprovenSOA("example."))
// canonical order: example. < *.example. < host.example. < missing.example. < www.example.
apex := zone.sign(t, pocUnprovenNSEC("example.", "www.example.",
dns.TypeNS, dns.TypeSOA, dns.TypeRRSIG, dns.TypeNSEC, dns.TypeDNSKEY))
t.Run("negative answer without NSEC or NSEC3", func(t *testing.T) {
www := zone.sign(t, pocUnprovenNSEC("www.example.", "example.", dns.TypeA, dns.TypeRRSIG, dns.TypeNSEC))
nxdomain := func(ns ...[]dns.RR) *dns.Msg {
return &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeNameError}, Ns: slices.Concat(ns...)}
}
nodata := func(ns ...[]dns.RR) *dns.Msg { return &dns.Msg{Ns: slices.Concat(ns...)} }
run(t, zone, exampleOnly, "missing.example.", dns.TypeA,
testCase{"control: NXDOMAIN for missing.example. A, signed SOA and NSEC", nxdomain(soa, apex), secure},
testCase{"NXDOMAIN for missing.example. A, signed SOA only", nxdomain(soa), bogus})
run(t, zone, exampleOnly, "www.example.", dns.TypeTXT,
testCase{"control: NODATA for www.example. TXT, signed SOA and NSEC", nodata(soa, www), secure},
testCase{"NODATA for www.example. TXT, signed SOA only", nodata(soa), bogus})
})
t.Run("unsigned answer beside a signature elsewhere", func(t *testing.T) {
a := pocUnprovenA("www.example.")
unsigned := []dns.RR{a}
junk := zone.signRandom(t, a)[1:]
run(t, zone, exampleOnly, "www.example.", dns.TypeA,
testCase{"control: answer signed", &dns.Msg{Answer: zone.sign(t, a)}, secure},
testCase{"control: no RRSIG anywhere", &dns.Msg{Answer: unsigned}, bogus},
testCase{"signed SOA in the authority section", &dns.Msg{Answer: unsigned, Ns: soa}, bogus},
testCase{"RRSIG of random bytes in the additional section", &dns.Msg{Answer: unsigned, Extra: junk}, bogus})
})
t.Run("CNAME chain across a signed and an unsigned zone", func(t *testing.T) {
root := newPocUnprovenZone(t, ".")
upstream := map[string]*dns.Msg{
". DNSKEY": {Answer: root.sign(t, root.key)},
"example. DNSKEY": {Answer: dnskey},
"example. DS": {Answer: root.sign(t, zone.key.ToDS(dns.SHA256))},
"test. DS": {Ns: slices.Concat(root.sign(t, pocUnprovenSOA(".")),
root.sign(t, pocUnprovenNSEC("test.", ".", dns.TypeNS, dns.TypeRRSIG, dns.TypeNSEC)))},
}
cnameToExample := zone.sign(t, pocUnprovenCNAME("www.example.", "host.example."))
cnameToTest := zone.sign(t, pocUnprovenCNAME("www.example.", "host.test."))
cnameFromTest := []dns.RR{pocUnprovenCNAME("www.test.", "host.example.")}
exampleA := zone.sign(t, pocUnprovenA("host.example."))
unsignedExampleA := []dns.RR{pocUnprovenA("host.example.")}
testA := []dns.RR{pocUnprovenA("host.test.")}
answer := func(rrsets ...[]dns.RR) *dns.Msg { return &dns.Msg{Answer: slices.Concat(rrsets...)} }
run(t, root, upstream, "www.example.", dns.TypeA,
testCase{"control: signed CNAME to a signed A in example.", answer(cnameToExample, exampleA), secure},
testCase{"control: signed CNAME to an unsigned A in example.", answer(cnameToExample, unsignedExampleA), bogus},
testCase{"signed CNAME to an unsigned A in insecure test.", answer(cnameToTest, testA), insecure})
run(t, root, upstream, "www.test.", dns.TypeA,
testCase{"unsigned CNAME in insecure test. to a signed A in example.", answer(cnameFromTest, exampleA), insecure})
})
t.Run("parts of the response that are never validated", func(t *testing.T) {
a := pocUnprovenA("www.example.")
signed := zone.sign(t, a)
rrsigOnly := zone.signRandom(t, a)[1:]
junkSOA := zone.signRandom(t, pocUnprovenSOA("example."))
run(t, zone, exampleOnly, "www.example.", dns.TypeA,
testCase{"control: signed answer, signed SOA in the authority section", &dns.Msg{Answer: signed, Ns: soa}, secure},
testCase{"answer section with only an RRSIG of random bytes", &dns.Msg{Answer: rrsigOnly}, bogus},
testCase{
"signed answer, SOA with an RRSIG of random bytes in the authority section",
&dns.Msg{Answer: signed, Ns: junkSOA}, bogus,
})
cname := zone.sign(t, pocUnprovenCNAME("www.example.", "host.example."))
nxdomain := func(ns ...[]dns.RR) *dns.Msg {
return &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeNameError}, Answer: cname, Ns: slices.Concat(ns...)}
}
nodata := func(ns ...[]dns.RR) *dns.Msg { return &dns.Msg{Answer: cname, Ns: slices.Concat(ns...)} }
run(t, zone, exampleOnly, "www.example.", dns.TypeA,
testCase{"control: signed CNAME to host.example., NXDOMAIN, signed SOA and NSEC", nxdomain(soa, apex), secure},
testCase{"signed CNAME to host.example., NXDOMAIN, signed SOA only", nxdomain(soa), bogus},
testCase{"signed CNAME to host.example., NODATA, signed SOA only", nodata(soa), bogus})
})
t.Run("answers that do not answer the question", func(t *testing.T) {
a := zone.sign(t, pocUnprovenA("www.example."))
otherName := zone.sign(t, pocUnprovenA("other.example."))
otherType := zone.sign(t, pocUnprovenTXT("www.example."))
brokenChain := slices.Concat(
zone.sign(t, pocUnprovenCNAME("www.example.", "a.example.")), zone.sign(t, pocUnprovenA("b.example.")))
nxdomain := &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeNameError}, Answer: a}
run(t, zone, exampleOnly, "www.example.", dns.TypeA,
testCase{"control: signed www.example. A", &dns.Msg{Answer: a}, secure},
testCase{"signed other.example. A", &dns.Msg{Answer: otherName}, bogus},
testCase{"signed www.example. TXT", &dns.Msg{Answer: otherType}, bogus},
testCase{"signed CNAME to a.example., then signed b.example. A", &dns.Msg{Answer: brokenChain}, bogus},
testCase{"NXDOMAIN with signed www.example. A", nxdomain, bogus})
})
}
type pocUnprovenZone struct {
key *dns.DNSKEY
priv crypto.Signer
}
// newPocUnprovenZone returns an ECDSA P-256 key-signing key for the zone name.
func newPocUnprovenZone(t *testing.T, name string) pocUnprovenZone {
t.Helper()
key := &dns.DNSKEY{
Hdr: dns.RR_Header{Name: name, 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 pocUnprovenZone{key, priv.(crypto.Signer)}
}
// sign returns rrset followed by its RRSIG, made by z with RRSIG.Sign.
func (z pocUnprovenZone) 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)
}
// signRandom returns rrset followed by an RRSIG of z over it whose 64-byte signature field is random.
func (z pocUnprovenZone) signRandom(t *testing.T, rrset ...dns.RR) []dns.RR {
t.Helper()
signed := z.sign(t, rrset...)
random := make([]byte, 64)
if _, err := rand.Read(random); err != nil {
t.Fatal(err)
}
signed[len(signed)-1].(*dns.RRSIG).Signature = base64.StdEncoding.EncodeToString(random)
return signed
}
func pocUnprovenSOA(zone string) *dns.SOA {
hdr := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Class: dns.ClassINET, Ttl: 300}
return &dns.SOA{
Hdr: hdr, Ns: "ns.example.", Mbox: "hostmaster.example.",
Serial: 1, Refresh: 3600, Retry: 600, Expire: 86400, Minttl: 300,
}
}
// pocUnprovenNSEC returns the NSEC at owner whose next name is next.
func pocUnprovenNSEC(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}
}
func pocUnprovenCNAME(owner, target string) *dns.CNAME {
hdr := dns.RR_Header{Name: owner, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 300}
return &dns.CNAME{Hdr: hdr, Target: target}
}
func pocUnprovenA(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)}
}
func pocUnprovenTXT(name string) *dns.TXT {
hdr := dns.RR_Header{Name: name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 300}
return &dns.TXT{Hdr: hdr, Txt: []string{"v=1"}}
}</details>
References
- RFC 4033 §5; RFC 4035 §3.2.3, §4.3 and §5.4
- GHSA-x845-2f78-7v36, the earlier advisory on unsigned answers
- 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-mv8x-2h8p-g3wh: DNSSEC: incomplete denial-of-existence proofs (wildcards, NSEC NXDOMAIN, CNAME bit, name order)
- GHSA-6fgw-qmpq-vwxp: DNSSEC: NSEC and NSEC3 denials are accepted from zones not authoritative for the queried name
- 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.