Skip to content
Access control Audit finding Advanced

PARENT_CANNOT_CONTROL and CANNOT_CREATE_SUBDOMAIN fuses can be bypassed

The ENS NameWrapper contract allowed a parent node owner to bypass the PARENT_CANNOT_CONTROL and CANNOT_CREATE_SUBDOMAIN fuses by unwrapping and re-wrapping intermediate nodes, enabling them to reclaim ownership of a victim's subnode and create sub-subnodes despite the burnt fuses.

izhuer Follow

Originally disclosed on Code4rena

Submitted by izhuer

The fuse constraints can be violated by a malicious owner of the parent node (i.e., the hacker). There are two specific consequences the hacker can cause.

  • Suppose the subnode has been assigned to a victim user, the hacker can re-claim him as the owner of the subnode even if the PARENT_CANNOT_CONTROL of the subnode has been burnt.
  • Suppose the owner of the subnode remains to be the hacker, he can create sub-subnode even if the CANNOT_CREATE_SUBDOMAIN of the subnode has been burnt.

Basically, ENS NameWrapper uses the following rules to prevent all previous C4 hacks (note that I will assume the audience has some background regarding the ENS codebase).

  • The PARENT_CANNOT_CONTROL fuse of a subnode can be burnt if and only if the CANNOT_UNWRAP fuse of its parent has already been burnt.
  • The CANNOT_UNWRAP fuse of a subnode can be burnt if and only if its PARENT_CANNOT_CONTROL fuse has already been burnt.

However, such guarantees would only get effective when the CANNOT_UNWRAP fuse of the subject node is burnt.

Considering the following scenario.

  1. sub1.eth (the ETH2LD node) is registered and wrapped to the hacker - the ENS registry owner, i.e., ens.owner, of sub1.eth is the NameWrapper contract.
  2. sub2.sub1.eth is created with no fuses burnt, where the wrapper owner is still the hacker - the ENS registry owner of sub2.sub1.eth is the NameWrapper contract.
  3. sub3.sub2.sub1.eth is created with no fuses burnt and owned by a victim user - the ENS registry owner of sub3.sub2.sub1.eth is the NameWrapper contract.
  4. the hacker unwraps sub2.sub1.eth - the ENS registry owner of sub2.sub1.eth becomes the hacker.
  5. via ENS registry, the hacker claims himself as the ENS registry owner of sub3.sub2.sub1.eth. Note that the sub3.sub2.sub1.eth in the NameWrapper contract remains valid till now - the ENS registry owner of sub3.sub2.sub1.eth is the hacker.
  6. the hacker wraps sub2.sub1.eth - the ENS registry owner of sub2.sub1.eth becomes the NameWrapper contract.
  7. the hacker burns the PARENT_CANNOT_CONTROL and CANNOT_UNWRAP fuses of sub2.sub1.eth.
  8. the hacker burns the PARENT_CANNOT_CONTROL, CANNOT_UNWRAP, and CANNOT_CREATE_SUBDOMAIN fuses of sub3.sub2.sub1.eth. Note that the current ENS registry owner of sub3.sub2.sub1.eth remains to be the hacker

At this stage, things went wrong.

Again, currently the sub3.sub2.sub1.eth is valid in NameWrapper w/ PARENT_CANNOT_CONTROL | CANNOT_UNWRAP | CANNOT_CREATE_SUBDOMAIN burnt, but the ENS registry owner of sub3.sub2.sub1.eth is the hacker.

The hacker can:

  • invoke NameWrapper::wrap to wrap sub3.sub2.sub1.eth, and re-claim himself as the owner of sub3.sub2.sub1.eth in NameWrapper.
  • invoke ENSRegistry::setSubnodeRecord to create sub4.sub3.sub2.sub1.eth and wrap it accordingly, violating CANNOT_CREATE_SUBDOMAIN

Proof of Concept

The poc_ens.js file (included in warden’s original submission) demonstrates the above hack, via 6 different attack paths.

To validate the PoC, put the file in ./test/wrapper and run npx hardhat test test/wrapper/poc_ens.js

Recommended Mitigation Steps

The NameWrapper.sol file (included in warden’s original submission) demonstrates the patch.

In short, we try to guarantee only fuses of wrapped nodes can be burnt.

Alex the Entreprenerd (judge) commented:

Will need to test POC but looks valid.

jefflau (ENS) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how to sidestep fuses burned to effectively steal nodes. Via wrapping, by leveraging a lack of checks, the warden was able to gain access to nodes which belong to other accounts.

Because this finding:

  • Shows broken invariants (sidestepped fuses)
  • Was shown to allow stealing of child-nodes

I agree with High Severity.

izhuer (warden) commented:

Specifically, the PR proposed here looks good to me. It ensures that, if a given node has some fuses to burn, ens.owner(node) == address(NameWrapper) must be sanctified.

However, I also observe that there is a new PR proposing a refactoring regarding SetSubnodeOwner. I may need to check this further since the logic seems to change quite a bit.

izhuer (warden) commented:

With regard to the test, maybe we can integrate the PoC (w/ slight modification) into test cases? So that it makes sure that any future refactoring would not break the security guarantee.

izhuer (warden) commented:

Made some comments in the refactoring RP. It seems not 100% safe and I may still need more time to review it.

csanuragjain (warden) commented:

It is now ensured that child fuses can only be burned if node is wrapped ie ens.owner(node) == address(NameWrapper).

if (!isWrapped(node)) {
            ens.setSubnodeOwner(parentNode, labelhash, address(this));
            _wrap(node, name, owner, fuses, expiry);
        } else {
            _updateName(parentNode, node, label, owner, fuses, expiry);
        }

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 NameWrapper contract did not verify that a node was wrapped (i.e., owned by the NameWrapper contract) before allowing fuses to be burned, so an attacker could manipulate the ENS registry ownership to bypass fuse restrictions.

Impact

A malicious parent owner could steal a victim's subnode and create sub-subnodes even when the CANNOT_CREATE_SUBDOMAIN fuse was burnt, violating the intended security guarantees.

What the attacker needed

Attacker owns a parent domain; victim owns a subdomain; attacker can unwrap and re-wrap domains

The fix

The fix ensures that fuses can only be burned if the node is wrapped, i.e., its ENS registry owner is the NameWrapper contract.

How it was found

  1. Register and wrap sub1.eth to the hacker.
  2. Create sub2.sub1.eth with no fuses burnt, owned by the hacker.
  3. Create sub3.sub2.sub1.eth with no fuses burnt, owned by a victim.
  4. Unwrap sub2.sub1.eth so the hacker becomes its ENS registry owner.
  5. Via ENS registry, claim ownership of sub3.sub2.sub1.eth as the hacker.
  6. Re-wrap sub2.sub1.eth and burn fuses on sub2 and sub3, then wrap sub3 to reclaim ownership and create sub4 despite CANNOT_CREATE_SUBDOMAIN.

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 have 'fuses' that lock certain actions, like preventing a parent from taking back control of a subdomain. This report shows that by unwrapping and re-wrapping a middle domain, an attacker could bypass those locks and steal a victim's subdomain or create new ones when they shouldn't. The fix ensures fuses can only be burned when the domain is properly wrapped.

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.