<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="rfc7991bis.rnc"?> <!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc
  xmlns:xi="http://www.w3.org/2001/XInclude"
  category="bcp"
  docName="draft-qiu-dnsop-rd-flag-clarification-02"
  ipr="trust200902"
  obsoletes=""
  updates=""
  submissionType="IETF"
  consensus="true"
  xml:lang="en"
  version="3">

  <front>
    <title abbrev="RD Flag Clarification">Clarifying DNS Resolver Behavior for the Recursion Desired (RD) Flag</title>

    <seriesInfo name="Internet-Draft" value="draft-qiu-dnsop-rd-flag-clarification-02"/>

    <author fullname="Yuqi Qiu" initials="Y.Q." surname="Qiu">
      <organization>Nankai University</organization>
      <address>
        <postal>
          <street>38 Tongyan Road</street>
          <city>Tianjin</city>
          <region>Tianjin</region>
          <code>300355</code>
          <country>China</country>
        </postal>
        <email>norahqiu@163.com</email>
      </address>
    </author>

     <author fullname="Xiang Li" initials="X.L." surname="Li">
      <organization>Nankai University</organization>
      <address>
        <postal>
          <street>38 Tongyan Road</street>
          <city>Tianjin</city>
          <region>Tianjin</region>
          <code>300355</code>
          <country>China</country>
        </postal>
        <email>lixiang@nankai.edu.cn</email>
      </address>
    </author>

    <date year="2026" month="February" day="28"/>

    <area>Internet</area>
    <workgroup>DNS Operations (dnsop)</workgroup>
    <keyword>DNS</keyword>
    <keyword>RD Flag</keyword>
    <keyword>Recursion Desired</keyword>
    <keyword>Resolver</keyword>
    <keyword>Forwarder</keyword>
    <keyword>Security</keyword>
    <keyword>Amplification Attack</keyword>

    <abstract>
      <t>This document addresses inconsistencies observed in the handling of the
      Recursion Desired (RD) flag in DNS queries by various DNS resolver
      implementations, particularly when the RD flag is cleared (set to 0).
      Such inconsistencies have been shown to be exploitable, leading to
      potent Denial of Service (DoS) amplification attacks. This document
      provides clear guidance and recommendations for DNS resolver (including
      forwarding and recursive resolvers) behavior when processing queries
      with different RD flag settings. The goal is to enhance DNS security,
      mitigate specific amplification attack vectors, and ensure more
      predictable and robust DNS operations.</t>
    </abstract>

  </front>

  <middle>
    <section anchor="Introduction">
      <name>Introduction</name>
      <section anchor="RDFlagIntro">
        <name>The Recursion Desired (RD) Flag</name>
        <t>The Domain Name System (DNS) is a hierarchical and distributed naming
        system for computers, services, or other resources connected to the
        Internet or a private network. DNS queries contain a one-bit field
        known as the Recursion Desired (RD) flag. As defined in <xref target="RFC1034"/>
        and <xref target="RFC1035"/>, this flag directs the name server receiving the query:</t>
        <ul>
          <li><t>If RD is set (1), and the queried name server supports recursive
          queries, it is directed to pursue the query recursively. That is,
          the name server should take responsibility for resolving the query
          and returning the final answer.</t></li>
          <li><t>If RD is cleared (0), and the name server does not support
          recursive queries, or recursion is not desired for this specific
          query, the name server should return an answer based on its own
          data (e.g., from its cache or authoritative zones) without
          contacting other name servers. If the name server does not have
          the information locally, it should return a response indicating
          that, which might include referrals to other name servers.</t></li>
        </ul>
        <t>As explicitly noted long ago in RFC 1034, "the name server should never perform recursive service unless asked via RD, since this interferes with trouble shooting of name servers and their databases." Consequently, this document does not intend to create a new Standard, but rather to reinforce this fundamental rule as a precise Best Current Practice due to significant contemporary operational deviations.</t>
      </section>
      <section anchor="ObservedVulnerabilities">
        <name>Observed Vulnerabilities</name>
        <t>Recent research, such as the "TsuKing" attack <xref target="XU2023"/>, has
        highlighted that a significant number of DNS resolvers, including
        open resolvers and forwarding devices, do not strictly adhere to the
        intended semantics of the RD flag, particularly when it is cleared
        (RD=0). Specific problematic behaviors include:</t>
        <ul>
          <li><t>Resolvers performing recursive lookups or forwarding queries
          upstream even when the incoming query has RD=0.</t></li>
          <li><t>DNS forwarders modifying the RD flag, for example, by changing an
          incoming RD=0 to RD=1 in the query forwarded upstream.</t></li>
        </ul>
        <t>These deviations from standard behavior create vulnerabilities that
        can be exploited for various purposes, most notably for constructing
        Denial of Service (DoS) amplification attacks as broadly categorized in
        <xref target="ROSSOW2014"/>. In such attacks, like the DNSCHAIN and
        DNSLOOP variants described in <xref target="XU2023"/>, attackers
        leverage these incorrect RD flag handling behaviors to coordinate
        multiple resolvers into amplifying query traffic towards a victim.
        Related work such as NXNSAttack <xref target="AFEK2020"/> and TsuNAME
        <xref target="MOURA2021"/> has also demonstrated how resolver inefficiencies
        and looping behaviors can be weaponized. The vulnerability of performing
        recursion when RD=0 was identified as a key factor (termed "V1" in
        <xref target="XU2023"/>) enabling these attacks.</t>
      </section>
      <section anchor="Purpose">
        <name>Purpose of this Document</name>
        <t>The purpose of this document is to:</t>
        <ul>
          <li><t>Reiterate and clarify the expected behavior of DNS resolvers
          (including recursive resolvers and DNS forwarders) concerning the
          RD flag.</t></li>
          <li><t>Provide explicit operational guidance to promote consistent
          implementation and deployment of RD flag handling.</t></li>
          <li><t>Mitigate the security risks associated with incorrect RD flag
          processing, thereby reducing the attack surface for certain types
          of DNS amplification attacks.</t></li>
        </ul>
        <t>This document aims to update or clarify existing guidance in
        <xref target="RFC1034"/>, <xref target="RFC1035"/>, and <xref target="RFC2181"/>
        by providing more explicit behavioral requirements for resolvers.</t>
      </section>
    </section>

    <section anchor="Definitions">
      <name>Conventions and Definitions</name>
      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
        "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT
        RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
        interpreted as described in BCP 14 <xref target="RFC2119"/>
        <xref target="RFC8174"/> when, and only when, they appear in
        all capitals, as shown here.</t>
      <t>This document uses the following terms:</t>
      <dl newline="true">
        <dt>DNS Resolver:</dt>
        <dd><t>A program that acts as a client to the DNS system,
        issuing queries and processing responses. Resolvers can be stub
        resolvers, recursive resolvers, or forwarders.</t></dd>
        <dt>Recursive Resolver:</dt>
        <dd><t>A resolver that, upon receiving a query for
        which it does not have an answer, will itself query other name
        servers to find the answer.</t></dd>
        <dt>DNS Forwarder:</dt>
        <dd><t>A resolver that, upon receiving a query it cannot
        answer from its cache, forwards the query to a configured upstream
        recursive resolver.</t></dd>
        <dt>Stub Resolver:</dt>
        <dd><t>A minimal resolver that relies on an upstream
        recursive resolver to perform the bulk of the resolution work.</t></dd>
        <dt>Authoritative Server:</dt>
        <dd><t>A name server that holds the definitive data
        for a particular zone.</t></dd>
        <dt>Iterative Query:</dt>
        <dd><t>A query mode where a name server, if it does not
        have the answer, returns a referral to other name servers that are
        more authoritative for the queried name. The querier then issues
        queries to these referred servers.</t></dd>
        <dt>Recursive Query:</dt>
        <dd><t>A query mode where the querier requests the name
        server to perform the full resolution process and return the final
        answer.</t></dd>
        <dt>RD Flag:</dt>
        <dd><t>The "Recursion Desired" bit in the DNS query header.</t></dd>
      </dl>
    </section>

    <section anchor="ProblemDescription">
      <name>Problem Description: Inconsistent RD Flag Handling</name>
      <t>The core issue addressed by this document is the inconsistent and
      often incorrect handling of the RD flag by DNS resolvers, especially
      when RD=0. This inconsistency deviates from the original intent of
      the DNS protocol and introduces security vulnerabilities.</t>
      <section anchor="RecursiveBehaviorRD0">
        <name>Recursive Behavior for RD=0 Queries</name>
        <t>As highlighted in <xref target="XU2023"/>, a notable number of DNS resolvers,
        including both recursive resolvers and forwarders, exhibit recursive
        behavior even when presented with a query where the RD flag is
        cleared (RD=0). Instead of responding solely from local data (cache
        or authoritative zones), these resolvers proceed to query other name
        servers or forward the query upstream, effectively ignoring the RD=0
        directive. This behavior is problematic because:</t>
        <ul>
          <li><t>It violates the expectation of the querying client, which may have
          cleared the RD flag specifically to prevent recursion (e.g., for
          diagnostic purposes or to query a local cache).</t></li>
          <li><t>It allows these resolvers to be unwillingly drafted into attack
          architectures, as demonstrated by the DNSCHAIN and DNSLOOP attacks
          <xref target="XU2023"/>, where chains or loops of resolvers are formed by
          exploiting this RD=0 recursion.</t></li>
        </ul>
      </section>
      <section anchor="RDFlagModification">
        <name>RD Flag Modification by Forwarders</name>
        <t>Another problematic behavior observed, particularly in some DNS
        forwarding devices <xref target="XU2023"/> (e.g., certain configurations of
        RouterOS), is the modification of the RD flag. Similar issues in
        forwarding devices have been discussed in <xref target="ZHENG2020"/>.
        Specifically, a forwarder might receive a query with RD=0, but when
        it forwards this query to its upstream recursive resolver, it sets
        the RD flag to 1. This action fundamentally changes the nature of the
        query as perceived by the upstream resolver and contributes to the
        vulnerabilities described above. It forces recursion where none was
        requested by the original querier.</t>
      </section>
    </section>

    <section anchor="RecommendedBehavior">
      <name>Recommended Behavior for RD Flag Processing</name>
      <section anchor="GeneralPrinciples">
        <name>General Principles</name>
        <t>All DNS resolvers (recursive resolvers, forwarders, and stub
        resolvers that might implement caching or forwarding logic) MUST
        inspect the RD flag in incoming queries. The decision to perform
        recursion, forward a query, or perform iterative queries MUST be
        influenced by the state of the RD flag in the incoming query and the
        resolver's configured role and policy.</t>
      </section>
      <section anchor="RD1Queries">
        <name>Queries with RD=1 (Recursion Desired)</name>
        <t>This section describes behavior for queries where the RD flag is set
        (RD=1).</t>
        <ul>
          <li><t>Recursive Resolvers: If a resolver is configured to provide
          recursive service and receives a query with RD=1, it SHOULD
          attempt to resolve the query fully. This typically involves
          performing iterative queries to authoritative name servers as
          needed, or consulting its cache. If the resolver is not configured
          to provide recursive service to the querier, or if a local policy
          prevents recursion for the specific query or querier, it MAY
          return a response with RCODE=REFUSED.</t></li>
          <li><t>DNS Forwarders: If a DNS forwarder receives a query with RD=1 that
          it cannot answer from its local cache, it SHOULD forward the query
          to one of its configured upstream recursive resolvers. The
          forwarded query MUST also have the RD flag set to 1.</t></li>
          <li><t>Authoritative Servers: An authoritative server receiving a query
          with RD=1 MAY ignore the RD flag and respond based on its
          authoritative data for the zone. It is not obligated to perform
          recursion. If it is not authoritative for the queried name and
          does not support recursion, it typically returns a referral or an
          error.</t></li>
        </ul>
      </section>
      <section anchor="RD0Queries">
        <name>Queries with RD=0 (Recursion Not Desired)</name>
        <t>This section describes the REQUIRED behavior for queries where the RD
        flag is cleared (RD=0). This is the critical area for mitigating the
        vulnerabilities discussed.</t>
        <section anchor="RD0Recursive">
          <name>Recursive Resolvers</name>
          <t>When a recursive resolver (i.e., a resolver configured and capable of
          performing recursion, but not acting as a simple forwarder for this
          specific query) receives a query with RD=0:</t>
          <ol type="1">
            <li>
              <t>The resolver MUST attempt to answer the query using only locally
              available information. Locally available information includes:</t>
              <ul>
                <li><t>Its cache.</t></li>
                <li><t>Local zone data if the resolver is also authoritative for the
                queried name or has been configured with local zone data.</t></li>
              </ul>
            </li>
            <li><t>The resolver MUST NOT forward the query to other recursive
            resolvers (unless it is acting as a designated forwarder as per
            Section 4.3.2, and even then, specific rules apply).</t></li>
            <li><t>The resolver MUST NOT perform iterative queries to external
            authoritative name servers for this query.</t></li>
            <li>
              <t>If the answer is not available from locally available information:</t>
              <ul>
                <li><t>If the name is known to not exist (e.g., from a cached
                NXDOMAIN or a negative cache entry compliant with <xref target="RFC2308"/>),
                the resolver SHOULD return a response with RCODE=NXDOMAIN.</t></li>
                <li><t>Otherwise, the resolver SHOULD return a response with RCODE=0
                (NoError) and an empty answer section.</t></li>
                <li><t>Under certain policy conditions, it MAY return RCODE=REFUSED.</t></li>
              </ul>
            </li>
          </ol>
          <t>The intent is that an RD=0 query to a recursive resolver probes its
          local knowledge without causing external network activity for resolution.</t>
        </section>
        <section anchor="RD0Forwarders">
          <name>DNS Forwarders</name>
          <t>When a DNS forwarder receives a query with RD=0:</t>
          <ol type="1">
            <li><t>The forwarder SHOULD first attempt to answer the query from its
            local cache, if one exists and is consulted. If a satisfactory
            answer is found in the cache, it SHOULD be returned to the
            querier.</t></li>
            <li>
              <t>If the query cannot be answered from its local cache:</t>
              <ul>
                <li><t>The forwarder MUST NOT forward the query to its configured
                upstream recursive resolver(s) with the RD flag set to 1.
                This directly addresses the problematic behavior of some
                forwarders modifying the RD flag from 0 to 1.</t></li>
                <li><t>Ideally, a forwarder receiving an RD=0 query that misses its
                cache SHOULD behave like a recursive resolver as described in
                Section 4.3.1 (i.e., return an answer based purely on its
                local state, typically an empty NoError response or NXDOMAIN
                if known, and not forward the query at all). This is the
                RECOMMENDED behavior.</t></li>
                <li><t>If, due to a specific and explicit local configuration policy
                (e.g., a transparent proxying setup where the forwarder's role
                is strictly to pass queries to a specific upstream without
                local resolution capabilities beyond caching), a forwarder
                *does* forward a query that it originally received with RD=0,
                the forwarded query sent to the upstream resolver MUST also
                have the RD flag set to 0. The forwarder MUST NOT change the
                RD flag from 0 to 1.</t></li>
              </ul>
            </li>
          </ol>
          <t>The primary goal for forwarders handling RD=0 queries is to prevent
          them from initiating or propagating recursion that was not requested
          by the original querier.</t>
        </section>
        <section anchor="RD0Authoritative">
          <name>Authoritative Servers</name>
          <t>Authoritative name servers typically answer queries based on their
          zone data, regardless of the RD flag's setting. An authoritative
          server receiving a query with RD=0 SHOULD respond with data from its
          authoritative zones if the queried name falls within them. It MAY
          ignore the RD=0 flag in the sense that its primary function is to
          provide authoritative answers, not to perform recursion. If it is not
          authoritative for the queried name, it should respond as it normally
          would (e.g., with a referral or an error like NXDOMAIN if the domain
          exists but the name does not).</t>
        </section>
      </section>
    </section>

    <section anchor="Security">
      <name>Security Considerations</name>
      <t>The recommendations in this document are crucial for mitigating
      certain DNS-based amplification attacks, such as those described in
      <xref target="XU2023"/> (DNSCHAIN and DNSLOOP). Strict adherence to the specified
      handling of RD=0 queries by recursive resolvers and forwarders breaks
      the chains or loops that these attacks rely on, as resolvers will no
      longer perform or request recursion when explicitly told not to.</t>
      <t>Incorrect handling of the RD=0 flag, specifically:</t>
      <ul>
        <li><t>Recursive resolvers performing iterative queries or forwarding
        when RD=0.</t></li>
        <li><t>Forwarders forwarding RD=0 queries as RD=1 queries.</t></li>
      </ul>
      <t>can lead to resolvers being unwillingly co-opted into distributed
      amplification attacks. By following the normative requirements in
      Section 4.3, implementers and operators can significantly reduce the
      attack surface of the DNS infrastructure related to these vectors.</t>
      <t>These operational guidelines are complementary to other DNS security
      measures, such as those defined in <xref target="RFC5452"/> regarding
      forgery resilience and DNSSEC <xref target="RFC4033"/>. Furthermore,
      while this document focuses on the RD flag, correct state handling is
      equally important when supporting extensions such as EDNS(0)
      <xref target="RFC6891"/>, DNS Cookies <xref target="RFC7873"/>, and
      DNS over HTTPS <xref target="RFC8484"/>.</t>
      <t>Failure to implement negative caching (<xref target="RFC2308"/>) appropriately can
      exacerbate issues when RD=0 queries are mishandled, as resolvers
      might repeatedly attempt to resolve unresolvable names. While not
      directly about RD flag handling, robust negative caching is a
      complementary mechanism for overall DNS health and can indirectly
      limit the impact of some misbehaviors. The TsuKing paper <xref target="XU2023"/>
      also identified "no negative caching" (V2) as a contributing factor
      in the effectiveness of their attacks.</t>
      <t>Operators of DNS resolvers should ensure their software is compliant
      with the behaviors described herein and configure their resolvers
      according to these best practices.</t>
    </section>

    <section anchor="IANA">
      <name>IANA Considerations</name>
      <t>This document makes no requests of IANA.</t>
    </section>
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1034.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1035.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
      </references>

      <references>
        <name>Informative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2181.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2308.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.4033.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.5452.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6891.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7873.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8484.xml"/>

        <reference anchor="AFEK2020" target="https://www.usenix.org/conference/usenixsecurity20/presentation/afek">
          <front>
            <title>NXNSAttack: Recursive DNS Inefficiencies and Vulnerabilities</title>
            <author initials="Y." surname="Afek"><organization/></author>
            <author initials="A." surname="Bremler-Barr"><organization/></author>
            <author initials="L." surname="Shafir"><organization/></author>
            <date year="2020" month="August"/>
          </front>
          <seriesInfo name="In Proceedings of USENIX Security" value="2020"/>
        </reference>

        <reference anchor="MOURA2021" target="https://doi.org/10.1145/3487552.3487824">
          <front>
            <title>TsuNAME: Exploiting Misconfiguration and Vulnerability to DDoS DNS</title>
            <author initials="G. C. M." surname="Moura"><organization/></author>
            <author initials="S." surname="Castro"><organization/></author>
            <author initials="J. S." surname="Heidemann"><organization/></author>
            <author initials="W." surname="Hardaker"><organization/></author>
            <date year="2021" month="November"/>
          </front>
          <seriesInfo name="In Proceedings of the ACM Internet Measurement Conference (IMC '21)" value=""/>
        </reference>

        <reference anchor="ROSSOW2014" target="https://www.ndss-symposium.org/ndss2014/programme/amplification-hell-revisiting-network-protocols-ddos-abuse/">
          <front>
            <title>Amplification Hell: Revisiting Network Protocols for DDoS Abuse</title>
            <author initials="C." surname="Rossow"><organization/></author>
            <date year="2014" month="February"/>
          </front>
          <seriesInfo name="In Proceedings of the Network and Distributed System Security Symposium (NDSS '14)" value=""/>
        </reference>

        <reference anchor="XU2023" target="https://doi.org/10.1145/3576915.3616668">
          <front>
            <title>TsuKing: Coordinating DNS Resolvers and Queries into Potent DoS Amplifiers</title>
            <author initials="W." surname="Xu"><organization/></author>
            <author initials="X." surname="Li"><organization/></author>
            <author initials="C." surname="Lu"><organization/></author>
            <author initials="B." surname="Liu"><organization/></author>
            <author initials="H." surname="Duan"><organization/></author>
            <author initials="J." surname="Zhang"><organization/></author>
            <author initials="J." surname="Chen"><organization/></author>
            <author initials="T." surname="Wan"><organization/></author>
            <date year="2023" month="November"/>
          </front>
          <seriesInfo name="In Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security (CCS '23)" value=""/>
        </reference>

        <reference anchor="ZHENG2020" target="https://www.usenix.org/conference/usenixsecurity20/presentation/zheng-xiaofeng">
          <front>
            <title>Poison Over Troubled Forwarders: A Cache Poisoning Attack Targeting DNS Forwarding Devices</title>
            <author initials="X." surname="Zheng"><organization/></author>
            <author initials="C." surname="Lu"><organization/></author>
            <author initials="J." surname="Peng"><organization/></author>
            <author initials="Q." surname="Yang"><organization/></author>
            <author initials="D." surname="Zhou"><organization/></author>
            <author initials="B." surname="Liu"><organization/></author>
            <author initials="K." surname="Man"><organization/></author>
            <author initials="S." surname="Hao"><organization/></author>
            <author initials="H." surname="Duan"><organization/></author>
            <author initials="Z." surname="Qian"><organization/></author>
            <date year="2020" month="August"/>
          </front>
          <seriesInfo name="In Proceedings of USENIX Security" value="2020"/>
        </reference>

      </references>
    </references>

    </back>
</rfc>