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.
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.
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.
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.
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.
the hacker unwraps sub2.sub1.eth - the ENS registry owner of sub2.sub1.eth becomes the hacker.
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.
the hacker wraps sub2.sub1.eth - the ENS registry owner of sub2.sub1.eth becomes the NameWrapper contract.
the hacker burns the PARENT_CANNOT_CONTROL and CANNOT_UNWRAP fuses of sub2.sub1.eth.
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
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.
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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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
Register and wrap sub1.eth to the hacker.
Create sub2.sub1.eth with no fuses burnt, owned by the hacker.
Create sub3.sub2.sub1.eth with no fuses burnt, owned by a victim.
Unwrap sub2.sub1.eth so the hacker becomes its ENS registry owner.
Via ENS registry, claim ownership of sub3.sub2.sub1.eth as the hacker.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
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.