Skip to content
Crypto Audit finding Advanced

DNSSECImpl.verifySignature compares strings incorrectly, allowing malicious zones to forge DNSSEC trust chain

The DNSSEC signature verification in ENS compared the signer's name to the covered name as a raw string suffix rather than by DNS labels, so a signer name that is merely a substring of the covered name could pass. An attacker could potentially forge a DNSSEC trust chain and authenticate domains outside the signer's zone.

GimelSec Follow

Originally disclosed on Code4rena

Submitted by GimelSec, also found by csanuragjain

DNSSECImpl.sol#L186-L190

DNSSEC allows parent zones to sign for its child zones. To check validity of a signature, RFC4034 3.1.7 requires the Signer's Name in any RRSIG RDATA to contain the zone of covered RRset. This requirement is reasonable since any child zone should be covered by its parent zone.

ENS tries to implement the concept of name coverage in DNSSECImpl.verifySignature, but unfortuantely does it wrong, resulting in possibiliy of coverage between two unrelated domains. In the worst case, an attacker can utilize this bug to forge malicious trust chains and authenticate invalid domains.

Proof of Concept

In DNSSECImpl.verifySignature, ENS tries to verify the name of RRSet zone (name) is contained by Signer’s Name (rrset.signerName).

    if(rrset.signerName.length > name.length
            || !rrset.signerName.equals(0, name, name.length - rrset.signerName.length))    //## This allows matches such as name="SubString.com" signerName="String.com", which is clearly incorrect, use label counts instead
        {
            revert InvalidSignerName(name, rrset.signerName);
        }

In DNS, for a parent zone to contain another child zone, we generally require the child zone to be a subdomain of the parent. For instance, example.eth. in considered to cover sub.example.eth., while xample.eth. should not be cover example.eth..

Unfortunately in the implementation shown above, both cases will path the check, and ample.eth. will be considered appropriate to sign for example.eth.. This is against the original design of DNS, and would result in breach of zone hierarchy.

In practice, the requirement to exploit this is a bit more complex. Since names are stored as a sequence of packed labels, example.eth. should be stored as \x06example\x03eth\x00, while xample.eth. is stored as \x05xample\x03eth\x00. Thus to successfully pull off the attack ,we have to make sure that the packed signer’s name is actually a substring of child zone.

A simple (yet unrealistic) example can be like this xample.eth. can sign for e\x05xample.eth., since packed format of those two names are \x05xample\x03eth\x00 and \x07e\x05ample\x03eth\x00.

In general, it would require some effort for an attacker to find attackable zones, nevertheless, this should still be considered as a potential threat to the integrity of ENS.

Recommended Mitigation Steps

Check label by label instead of comparing the entire name. To actually meet all requirements specified in RFC4034 and RFC4035, there are still a lot to do, but we will discuss that in a separate issue for clarity.

Arachnid (ENS) disagreed with severity and commented:

This is a valid issue, but unexploitable in the wild; RFC 1035 specifies labels are limited to 63 octets or less, and the ASCII code of lowercase ‘a’ is 97. As a result, no vulnerable names should exist.

Recommend that this be triaged as severity 2 as a result.

LSDan (judge) decreased severity to Medium and commented:

I agree with @Arachnid on this. The lack of real world likelihood makes this a Medium severity.


The original report as published on Code4rena, by GimelSec. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code compared the signer's name to the covered name as a raw string suffix instead of comparing DNS labels, so a signer name that is a substring of the covered name passed the check.

Impact

An attacker could potentially forge a DNSSEC trust chain and authenticate invalid domains, though the ENS developer argued this is unexploitable in practice because DNS label length limits prevent vulnerable names from existing.

What the attacker needed

Ability to craft a malicious DNS zone; a vulnerable name that fits DNS label limits

The fix

The code should check label by label instead of comparing the entire name as a string.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

DNSSEC is a system that lets a parent domain vouch for a child domain, like a passport office confirming your address. The code checked whether the parent's name appeared at the end of the child's name as plain text, not as whole dot-separated parts, so a name like 'xample.eth' could wrongly be accepted as covering 'example.eth'. This could let someone fake a trusted domain.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by GimelSec

View all

18 more disclosed reports, best first.

More from ENS

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.