Net::DNS Cache Poisoning via Weak Query IDs (CVE-2026-101340)
Net::DNS through 1.57 generates DNS query IDs with Perl's rand(), so an observer can predict them and forge replies (Critical 9.1).
TL;DR
- Net::DNS generated the 16-bit DNS transaction ID with Perl's
rand(), so an attacker who observed a sequence could predict later IDs and inject forged responses. - Net::DNS 0.02 through 1.57 is affected, including the copy used by Apache SpamAssassin and other Perl tools.
- The CVE record scores it CVSS v4.0 9.1 Critical. No exploitation in the wild is known, and it is not in CISA KEV as of 2026-11-20.
- Upgrade to Net::DNS 1.58 or later and restart the resolver or tool that uses it.
Am I affected?
All of these conditions must hold for a deployment to be exposed:
- The installed Net::DNS is 1.57 or earlier, or a tool bundles that range.
- The application resolves DNS over a network where an attacker can observe a sequence of query IDs. An on-path attacker, a local process or a shared network position is enough.
- The attacker can send a forged response that reaches the resolver before the legitimate answer.
- The answer is not protected by a mechanism that rejects the forgery, such as DNSSEC validation for a signed zone.
| Branch | Affected versions | Fixed version |
|---|---|---|
| Net::DNS | 0.02 through 1.57 | 1.58 |
The fix shipped in 1.58 on 2026-11-20. The CVE record scores it CVSS v4.0 9.1. The vector is CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N, and the weakness is CWE-338.
The distribution had 120 dependent packages and 41 dependent repositories on libraries.io on 2026-11-20. Apache SpamAssassin requires Net::DNS 1.10 or later, so mail gateways that use SpamAssassin carry the library.
Check the installed version:
perl -MNet::DNS -e 'print $Net::DNS::VERSION, "\n"'
# Debian and Ubuntu package
dpkg -l libnet-dns-perl | tail -1
# RPM package
rpm -q perl-Net-DNS
For an application that vendors its dependencies, check the lock file or the bundle rather than the system Perl:
# cpanfile or Carton lock
grep -n 'Net::DNS' cpanfile cpanfile.snapshot 2>/dev/null
How do I fix it?
Upgrade to Net::DNS 1.58 or later and restart every process that loaded the old module.
- Install the fixed release with the CPAN client you use:
cpanm Net::DNS@1.58
# or
cpan Net::DNS
- For a distribution package, upgrade it and confirm the version is at least 1.58:
sudo apt install --only-upgrade libnet-dns-perl
perl -MNet::DNS -e 'print $Net::DNS::VERSION, "\n"'
- For a vendored application, update the pin to 1.58 and rebuild the bundle:
cpanm --installdeps .
- Restart the resolver, mail gateway or monitoring process that uses the library. A long-running process keeps the old module in memory after the files are replaced.
No patch-level workaround replaces the upgrade. DNSSEC validation rejects forged answers for signed zones, but it does not cover unsigned zones and does not fix the predictable ID. Source-port randomization and a restricted resolver path reduce the attacker's window but do not make the ID unpredictable.
What is the root cause?
A DNS query carries a 16-bit transaction ID. The resolver matches an incoming response to its outstanding query by that ID, together with the query name, type, class and the source address and port. The ID is the field an off-path attacker has to guess, and a predictable ID removes most of the guessing.
Net::DNS used Perl's built-in rand() to generate that ID. rand() is not a cryptographic generator, and its output sequence can be reconstructed from observed values.
The vulnerable _quid in lib/Net/DNS/Packet.pm in 1.57 was:
my ( $cache1, $cache2, $limit );
sub _quid { ## generate (short-term) unique query ID
my $self = shift;
my $id = $self->{id};
$cache1->{$id}++ if $id; # cache non-zero ID
return $id if defined $id;
( $cache2, $cache1, $limit ) = ( $cache1, {0 => 1}, 50 ) unless $limit--;
$id = int rand(0xffff); # two layer ID cache
$id = int rand(0xffff) while $cache1->{$id}++ + exists( $cache2->{$id} );
return $self->{id} = $id;
}
The two-layer cache only prevents an ID from repeating within a short window. It does not add entropy. The value still comes from rand(), so a sequence of observed IDs exposes the generator state that produced them. The cache also resets every 50 calls, which does not change the underlying generator.
Perl seeds rand() once per process unless the program calls srand(). A resolver that runs for days therefore produces a long sequence from one seed, and an observer who collects enough outputs can recover the state and compute the next IDs.
The CVE record describes the consequence: an attacker who can observe the sequence can expose the internal state of the PRNG and predict query IDs before they are transmitted. The resolver then accepts a forged response that carries the predicted ID.
How is it exploited?
An attacker who can see a run of DNS queries predicts the next transaction IDs and races the real answer with a forged one.
- The attacker observes a sequence of DNS queries and their 16-bit IDs from the victim resolver. An on-path position, a local process or a shared network is enough.
- The attacker reconstructs the PRNG state from the observed sequence and predicts the IDs the resolver will use next.
- The attacker sends a forged response with the predicted ID and the victim's query details before the legitimate server answers.
- The resolver matches the forged response to its outstanding query and caches the attacker's record.
- Later clients of that resolver receive the forged answer until the cache entry expires or is replaced.
No public proof of concept is linked in the advisory. The advisory states the prediction and the forged-response result but publishes no exploit code, so this article does not include one.
How does the attack flow?
An observed sequence of query IDs lets an attacker predict the next one and win the race with a forged answer.
query ID sequence"] --> B["Reconstructs PRNG state
from rand() output"] B --> C["Predicts next
16-bit query ID"] C --> D["Sends forged response
with predicted ID"] D --> E{"Arrives before
legitimate answer?"} E -->|"Yes"| F["Resolver accepts
and caches forged record"] F --> G["Clients receive
attacker answer"]
What can an attacker do?
An attacker who can observe the query sequence and win the response race can control the answer the resolver caches for a name. The advisory describes forged responses injected into the resolver; it does not describe a public exploit or in-the-wild use.
- Redirect a name to an address the attacker controls, for as long as the forged record stays cached.
- Deny resolution by returning a negative or unreachable answer.
- Reach clients that trust the resolver, including mail filters, monitoring checks and internal applications.
- Poison a name used by a security control, such as a blocklist or an update host, and change the control's decision.
The impact depends on the resolver's position and on what its clients trust. A stub resolver used by one process has a smaller blast radius than a shared recursive resolver. DNSSEC validation limits the impact to unsigned zones.
Why does the fix work?
The fix replaces rand() with a hash-based generator whose output does not reveal the state that produced it.
The 1.58 code in lib/Net/DNS/Packet.pm seeds a SHA-256 hash with a random value, the current time and the time since the previous call. It then takes the first 16 bits as the transaction ID:
{
use constant HASH => defined eval { require Digest::SHA };
my $hash = HASH ? Digest::SHA->new(256) : undef;
my $mark = time();
my $seed = int rand(0xffff);
my $prng = sub { ## PRNG using truncated hash
croak 'missing prerequisite: "Digest::SHA"' unless HASH;
my $time = time();
( my $delta_t, $mark ) = ( $time - $mark, $time );
$hash->add($seed);
$hash->add($time);
$hash->add($delta_t);
( my $random, $seed ) = unpack 'na*', $hash->digest;
return $random;
};
my ( $cache1, $cache2, $limit );
sub _quid { ## generate (short-term) "unique" query TxID
my $self = shift;
my $id = $self->{id};
$cache1->{$id}++ if $id; # cache non-zero TxID
return $id if defined $id;
$id = &$prng(); # two layer TxID cache
( $limit, $cache2, $cache1 ) = ( 50, $cache1, {0 => 1} ) unless $limit--;
$id = &$prng() while $cache1->{$id}++ + exists( $cache2->{$id} );
return $self->{id} = $id;
}
}
An observer sees only the 16-bit output. The output is a truncated SHA-256 digest of the seed, the time and the delta, so the observed value does not expose the seed or the next input. The time and delta mix change between calls, and the seed is replaced with the remaining 30 bytes of each digest. The two-layer cache still rejects IDs used within the last 50 calls, paying one extra digest only when a candidate collides.
The seed still starts from rand(0xffff), so the generator has at most 16 bits of initial entropy plus the time. The difference is that the output is one-way: seeing an ID no longer tells the attacker what the next input or output will be. The advisory's fix is a cryptographic generator, not an increase in the ID space, which remains 16 bits.
The fix is complete for the ID generator. The module now requires Digest::SHA, which is a core Perl module since 5.10. A process that loads 1.58 gets the new generator; a process that keeps the old module in memory does not.
How do I check if I was compromised?
The advisory publishes no indicators of compromise, and no exploitation in the wild is known.
A forged answer looks like a normal DNS response, so there is no reliable log signature. These checks are leads, not proof:
- Compare answers for sensitive names against the authoritative servers or a trusted resolver.
- Review resolver cache entries for names that changed address without an administrative change.
- Check for unexpected queries or answers around the time a name changed, especially from a host that can see the resolver's traffic.
- Enable DNSSEC validation where the zones are signed, and log validation failures.
A cache entry alone does not prove poisoning. The reliable control is the upgrade, because a predicted ID leaves no distinctive trace.
Timeline
- 2026-11-08: Xiang Li reports the issue.
- 2026-11-17: NLnet Labs shares the patch with the reporter.
- 2026-11-19: the reporter verifies the patch.
- 2026-11-20: Net::DNS 1.58 is released and CVE-2026-101340 is published.
FAQ
Is Net::DNS a resolver on its own?
No. Net::DNS is a Perl library that applications use to build queries and parse responses. The exposure depends on the application: a recursive resolver, a mail filter and a monitoring script use it differently.
Does this affect every program that uses Net::DNS?
No. The program must resolve names over a path where an attacker can observe the query IDs and inject a response. A program that uses a local trusted resolver, or a resolver with DNSSEC validation, has a smaller exposure.
Is there a public proof of concept?
No. The advisory describes the predictable-ID mechanism and the forged-response result but publishes no exploit code.
Does DNSSEC fix the problem?
No. DNSSEC validation rejects forged answers for signed zones, but it does not make the ID unpredictable and does not protect unsigned zones. Upgrade to 1.58 as well.
Do I need to restart my application after upgrading?
Yes. Perl loads the module into the process. Replacing the files on disk does not change a running resolver or mail filter, so restart every process that uses Net::DNS.
Does the fix change the DNS packet format?
No. The transaction ID is still 16 bits and the wire format is unchanged. Only the generator that chooses the ID changed.
Does the fix slow down query generation?
The fixed path computes a SHA-256 digest per query ID instead of calling rand(). The cost is small compared with the network round trip, and the two-layer cache still rejects IDs used within the last 50 calls, paying one extra digest only when a candidate collides.
What if Digest::SHA is not installed?
Digest::SHA is a core Perl module since 5.10. If a minimal Perl build omits it, the fixed _quid raises an error rather than falling back to rand(). Install the module or use a Perl build that includes it.
Are Net::DNS::SEC and DNSSEC validation affected?
The flaw is in the transaction ID generator in Net::DNS::Packet, not in the DNSSEC validation code. A resolver that validates DNSSEC still benefits from the upgrade, and validation rejects forged answers for signed zones.
Will my distribution package be updated?
That depends on the distribution. The upstream fix is 1.58, released on 2026-11-20. A distribution that backports the patch to an earlier version can be fixed without showing 1.58, so check the distribution's advisory as well as the version string.
Restart every process that loads Net::DNS
After the restart, run perl -MNet::DNS -e 'print $Net::DNS::VERSION, "\n"' again and confirm the output is 1.58 or later. The check confirms the module the new process loads.
References
- Net::DNS, advisory for CVE-2026-101340: https://www.net-dns.org/download/CVE-2026-101340.txt (checked November 20, 2026)
- CVE Program, CVE-2026-101340: https://www.cve.org/CVERecord?id=CVE-2026-101340 (checked November 20, 2026)
- Net::DNS, release 1.58: https://www.net-dns.org/download/Net-DNS-1.58.tar.gz (checked November 20, 2026)
- Net::DNS, vulnerable source at 1.57,
lib/Net/DNS/Packet.pm: https://metacpan.org/dist/Net-DNS/source/lib/Net/DNS/Packet.pm?version=1.57 (checked November 20, 2026) - Net::DNS, fixed source at 1.58,
lib/Net/DNS/Packet.pm: https://metacpan.org/dist/Net-DNS/source/lib/Net/DNS/Packet.pm?version=1.58 (checked November 20, 2026) - MetaCPAN, Net::DNS release 1.58: https://metacpan.org/release/NLNETLABS/Net-DNS-1.58 (checked November 20, 2026)
- Libraries.io, Net::DNS dependents: https://libraries.io/cpan/Net-DNS (checked November 20, 2026)
- Apache SpamAssassin,
Makefile.PLdependency on Net::DNS: https://github.com/apache/spamassassin/blob/trunk/Makefile.PL (checked November 20, 2026) - CISA Known Exploited Vulnerabilities catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked November 20, 2026)