dig ad and cd flags: why +cd still shows ad, even on REFUSED
dig's ad flag marks a DNSSEC-validated answer; cd asks to skip validation. ad shows up with +cd and on REFUSED, vanishes with +noadflag: read status and EDE.
;; flags: qr rd ra ad cd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1;; flags: qr rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1The first line is an answer to a +cd (checking disabled) query that still carries ad (authentic data). The second is a refused query that also carries ad. Unbound 1.19.2 returned both. Read ad together with the status line: only on NOERROR or NXDOMAIN from a validating resolver you trust does it mean "signatures checked". The reverse does not hold: a missing ad on its own tells you neither whether validation ran nor whether it failed. A validation failure comes back as SERVFAIL, but SERVFAIL alone doesn't settle the cause either. Use an EDE: line as supporting evidence when one is present (the Unbound in this test had ede: yes; the manual's default is no), and when there is none, query again with +cd and compare ([4]).
To decode each flag in a full dig output, paste it into the dig output explainer.
[1] Check what dig sets on the query. With +qr, dig prints the query it sent first.
$ dig @127.0.0.2 www.lab.test +qr…;; Sending:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12207;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1dig 9.18 sets ad on queries by default (manual, +adflag: "This bit is set by default"). Under RFC 6840 §5.7, ad on a query signals "I understand the AD bit in responses". It says nothing about the answer.
[2] Compare a signed zone and an unsigned zone on the same resolver.
$ dig @127.0.0.3 www.lab.test…;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1…$ dig @127.0.0.3 www.plain.test…;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1lab.test is signed with an unbroken chain of trust, so it gets ad. plain.test is unsigned: NOERROR, no ad. In this sample ad is missing because an unsigned answer can't be a validated, secure one. That is not the only reason ad goes missing, though: in [3] a signed, validated answer loses ad depending on the query flags. So don't judge validation, or its failure, from an absent ad. On this resolver, answers that failed validation came back as SERVFAIL, not as answers without ad ([4]).
[3] Know that +noadflag removes ad. Same signed zone, different result:
$ dig @127.0.0.3 www.lab.test +noadflag…;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1…$ dig @127.0.0.3 www.lab.test +noadflag +dnssec…;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1RFC 6840 §5.8 says a validating resolver should set ad only when the answer meets the validation conditions and the query had DO or AD set. A query with both off (+noadflag alone) gets no ad, even for a validated answer. Stub resolvers and libraries that set neither AD nor DO get answers without ad for the same reason. Before a script decides anything from ad, check the query flags.
[4] Set cd to see whether DNSSEC is the cause. A zone with a deliberately broken signature, queried without and with +cd:
$ dig @127.0.0.3 www.broken.test…;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 50487;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1…; EDE: 6 (DNSSEC Bogus): (validation failure <www.broken.test. A IN>: signature crypto failed from 127.0.0.2)…$ dig @127.0.0.3 www.broken.test +cd…;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22881;; flags: qr rd ra cd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1…; EDE: 6 (DNSSEC Bogus): (validation failure <www.broken.test. A IN>: signature crypto failed from 127.0.0.2)…;; ANSWER SECTION:www.broken.test. 60 IN A 192.0.2.99The +cd answer is NOERROR but keeps EDE: 6, and has no ad. The TTL is 60, not the zone's 3600: that is Unbound's val-bogus-ttl (default 60 seconds; the manual says the TTL of bogus data cannot be trusted, so this value is used instead). Treat this answer as diagnostic only and don't leave +cd on in an application because the address looked right. For using +cd to split SERVFAIL causes, continue with dig status: SERVFAIL — split out DNSSEC with +cd.
[5] Expect ad on a good zone even with +cd. This is the first line at the top:
$ dig @127.0.0.3 www.lab.test +cd…;; flags: qr rd ra ad cd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1…www.lab.test. 3532 IN A 192.0.2.20TTL 3532 is time remaining in the cache, so this is an answer that had already been validated and cached. Unbound 1.19.2 set ad on it. Don't read +cd as "not validated, so no ad". With +cd, look for an EDE: line and for a status that differs from the query without +cd, not at ad.
[6] Ignore ad on REFUSED. The second line at the top came from an address blocked with access-control: refuse:
$ dig @127.0.0.3 www.lab.test -b 127.0.0.66…;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 60884;; flags: qr rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1;; WARNING: recursion requested but not available…; EDE: 18 (Prohibited)There is no answer at all, yet ad shows. That is how Unbound 1.19.2 responded: the ad sent on the query ([1]) stays in the response header. It has nothing to do with validation. The cause is EDE: 18; see dig status: REFUSED.
| Response | How to read it |
|---|---|
NOERROR + ad | Validated answer (if you trust the validating resolver) |
NOERROR, no ad | Unsigned zone, non-validating resolver, or AD and DO both off in the query |
SERVFAIL + EDE: 6–10 | Validation failure: check whether +cd returns data |
SERVFAIL, no EDE | Cause unknown: check whether the resolver sends EDE, compare with +cd |
+cd, NOERROR + EDE: 6, TTL 60 | Raw data that failed validation (diagnostic) |
+cd, NOERROR + ad | Validated answer from cache (Unbound 1.19.2) |
REFUSED + ad | ad means nothing here: look at EDE and access control |
Sources: RFC 6840 §5.7, §5.8, §5.9 · RFC 8914 · BIND 9.18 dig manual (+adflag, +cdflag) · Unbound unbound.conf (val-bogus-ttl, access-control)
Check it with the dig output explainer tool ↗ — calculated in your browser.