The expiry of the parent node can be smaller than the one of a child node, violating the guarantee policy
The expiry of a parent node can become smaller than that of its child node because unwrapping a node sets its expiry to zero, removing the constraint that normally limits a child's expiry to the parent's. An attacker could create a sub-sub-domain with a long expiry, unwrap the intermediate sub-domain, then re-wrap it with a shorter expiry, violating the guarantee that a child's expiry never exceeds its parent's.
Originally disclosed on Code4rena
Submitted by PwnedNoMore
NameWrapper.sol#L504 NameWrapper.sol#L356
By design, the child node’s expiry can only be extended up to the parent’s current one. Adding these restrictions means that the ENS users only have to look at the name itself’s fuses and expiry (without traversing the hierarchy) to understand what guarantees the users have.
When a parent node tries to setSubnodeOwner / setSubnodeRecord, the following code is used to guarantee that the new expiry can only be extended up to the current one.
function _getDataAndNormaliseExpiry(
bytes32 parentNode,
bytes32 node,
uint64 expiry
)
internal
view
returns (
address owner,
uint32 fuses,
uint64
)
{
uint64 oldExpiry;
(owner, fuses, oldExpiry) = getData(uint256(node));
(, , uint64 maxExpiry) = getData(uint256(parentNode));
expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
return (owner, fuses, expiry);
}
However, the problem shows when
- The sub-domain (e.g.,
sub1.base.eth) has its own sub-sub-domain (e.g.,sub2.sub1.base.eth) - The sub-domain is unwrapped later, and thus its
oldExpirybecomes zero. - When
base.ethcallsNameWrapper.setSubnodeOwner, there is not constraint ofsub1.base.eth’s expiry, sinceoldExpiry == 0. As a result, the new expiry ofsub1.base.ethcan be arbitrary and smaller than the one ofsub2.sub1.base.eth
The point here is that the oldExpiry will be set as 0 when unwrapping the node even it holds child nodes, relaxing the constraint.
Specifically, considering the following scenario
-
The hacker owns a domain (or a 2LD), e.g.,
base.eth -
The hacker assigns a sub-domain to himself, e.g.,
sub1.base.eth- The expiry should be as large as possible
-
Hacker assigns a sub-sub-domain, e.g.,
sub2.sub1.base.eth- The expiry should be as large as possible
-
The hacker unwraps his sub-domain, i.e.,
sub1.base.eth -
The hacker re-wraps his sub-domain via
NameWrapper.setSubnodeOwner- The expiry can be small than the one of sub2.sub1.base.eth
The root cause seems that we should not zero out the expiry when burning a node if the node holds any subnode.
Suggested Fix
- Potential fix 1: auto-burn
CANNOT_UNWRAPwhich thus letsexpirydecide whether a node can be unwrapped. - Potential fix 2: force the parent to have
CANNOT_UNWRAPburnt if they want to set expiries on a child viasetSubnodeOwner/setSubnodeRecord/setChildFuses
Proof of Concept / Attack Scenario
For full details, please see original warden submission.
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 expiry is zeroed when a node is unwrapped even if it still has child nodes, so the parent's expiry no longer constrains the child's expiry.
What the attacker needed
Attacker owns a domain or 2LD; attacker can create subdomains; attacker can unwrap and re-wrap
The fix
The expiry should not be zeroed when burning a node if the node holds any subnode, or alternatively auto-burn CANNOT_UNWRAP or force the parent to have CANNOT_UNWRAP burnt when setting child expiries.
How it was found
- The attacker owns a domain (or a 2LD), e.g., base.eth
- The attacker assigns a sub-domain to himself, e.g., sub1.base.eth, with the expiry as large as possible
- The attacker assigns a sub-sub-domain, e.g., sub2.sub1.base.eth, with the expiry as large as possible
- The attacker unwraps his sub-domain, i.e., sub1.base.eth
- The attacker re-wraps his sub-domain via NameWrapper.setSubnodeOwner with a smaller expiry
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.
In ENS, names can have subnames, and a subname's expiry should never be later than its parent's. This report shows that by unwrapping and re-wrapping a middle name, someone can make a subname expire after its parent, breaking that rule.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.