Skip to content
Business logic Audit finding Intermediate

Unintentionally register a non-relevant DNS name owner

The DNS name claim function accepted an owner address of the wrong length and silently truncated it to the last 20 bytes, so the ENS name was transferred to an unintended address. An attacker who controls that truncated address could take over the ENS name.

SaharAP Follow with chaduke, nobody2018 and 1 other

Originally disclosed on Code4rena

Submitted by SaharAP, also found by chaduke, nobody2018, and Lilyjjo

If a user proves and claims a DNS name using a wrong address format, it executes successfully without getting any error and the DNS name owner will be changed to a new unknown address.

I considered this as medium severity, as it is high impact finding with low likelihood. Cause the person who owns the new address can take control of the ENS name and transfer its ownership to another account. But because if a person finds out, she can immediately replace the correct address, the probability of such an event is low.

Proof of Concept

In the following scenario, I provided a value called arbitrarybytes which is 22 bytes and set it as the ‘foo.test’ DNS owner address. proveAndClaim() function will execute successfully. Finally, the owner of the ENS name would be the value set as newOwner which is the last 20 bytes (from the right) of the provided value in arbitrarybytes.

    const arbitrarybytes= '0x9fD6E51AaD88f6f4CE6aB8827279CFFFb92266332265'
    const newOwner= '0xe51Aad88f6F4CE6aB8827279cFFFB92266332265'
    const proof = [
      hexEncodeSignedSet(rootKeys(expiration, inception)),
      hexEncodeSignedSet(testRrset('foo.test', arbitrarybytes)),
    ]

    await registrar.proveAndClaim(utils.hexEncodeName('foo.test'), proof, {
      from: accounts[0],
    })

    assert.equal(await ens.owner(namehash.hash('foo.test')), newOwner)

Tools Used

vscode

Recommended Mitigation Steps

To check the validity of the owner address, the code first checks for the prefix which must be a=0x, and second for the length of the address which should not be less than 20 bytes or 40 characters through hexToAddress() function. The length of the address can also be checked to not be larger than 40 characters.

 function hexToAddress(
        bytes memory str,
        uint256 idx,
        uint256 lastIdx
    ) internal pure returns (address, bool) {
        if (lastIdx - idx < 40) return (address(0x0), false);
        (bytes32 r, bool valid) = hexStringToBytes32(str, idx, lastIdx);
        return (address(uint160(uint256(r))), valid);
    }

Arachnid (ENS) confirmed, but disagreed with severity and commented:

I think this warrants a severity of ‘note’, as it requires the user to already supply an invalid-length address. It should revert rather than silently truncating.

LSDan (judge) commented:

Medium risk is appropriate in this case. It is very easy to guard against the user making the mistake described.

ref: https://github.com/code-423n4/org/issues/53#issuecomment-1340685618


The original report as published on Code4rena, by SaharAP. 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

Likely the address parsing function only checked a minimum length and did not reject values longer than 20 bytes, causing silent truncation.

Impact

The person who owns the truncated address could take control of the ENS name and transfer its ownership, though the mistake can be corrected immediately if noticed.

What the attacker needed

User supplies an invalid-length address

How it was found

  1. Provide a DNS proof where the owner address is 22 bytes instead of 20.
  2. Call the proveAndClaim function with that proof.
  3. Observe that the call succeeds and the ENS name owner becomes the last 20 bytes of the provided value.

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.

When you claim a DNS name in ENS, you provide a proof that includes the owner address. The code did not check that the address was exactly the right length, so it cut off extra characters and used a different address than the one intended. That meant the name could end up owned by someone else.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from ENS

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.