Missing recursive calls handling in OffchainDNSResolver CCIP-aware contract
The OffchainDNSResolver contract's resolveCallback function does not catch OffchainLookup errors from a nested CCIP-aware resolver, so a nested error with an incorrect sender field is passed to the client. This could cause the client to perform an off-chain lookup against the wrong contract, leading to incorrect resolution.
Originally disclosed on Code4rena
Submitted by MalfurionWhitehat
https://github.com/code-423n4/2023-04-ens/blob/main/contracts/dnsregistrar/OffchainDNSResolver.sol#L109-L113 https://github.com/code-423n4/2023-04-ens/blob/main/contracts/dnsregistrar/OffchainDNSResolver.sol#L119
The resolveCallback function from OffchainDNSResolver is used as part of the EIP-3668 standard to properly resolve DNS names using an off-chain gateway and validating RRsets against the DNSSEC oracle.
The issue is that the function lacks proper error handling, specifically, a try/catch block to properly bubble up OffchainLookup error from the dnsresolver extracted from the RRset. As the EIP specifies,
When a CCIP-aware contract wishes to make a call to another contract, and the possibility exists that the callee may implement CCIP read, the calling contract MUST catch all
OffchainLookuperrors thrown by the callee, and revert with a different error if thesenderfield of the error does not match the callee address. […] Where the possibility exists that a callee implements CCIP read, a CCIP-aware contract MUST NOT allow the default solidity behaviour of bubbling up reverts from nested calls.
Impact
As per the EIP, the result would be an OffchainLookup that looks valid to the client, as the sender field matches the address of the contract that was called, but does not execute correctly.
Proof of Concept
- Client calls
OffchainDNSResolver.resolve, which reverts withOffchainLookup, and prompts the client to executeresolveCallbackafter having fetched the necessary data from thegatewayURL - The RRset returned by the gateway contains a
dnsresolverthat is a CCIP-aware contract, and also supports theIExtendedDNSResolver.resolve.selectorinterface - Calling
IExtendedDNSResolver(dnsresolver).resolve(name,query,context);could trigger anotherOffchainLookuperror, but with asenderthat does not match thednsresolver, which would be just returned to the client without any modifications - As a result, the
senderfield would be incorrect as per the EIP
Recommended Mitigation Steps
Use the recommended example from the EIP in order to support nested lookups.
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
Impact
The client could receive an OffchainLookup error with an incorrect sender field, leading to a failed or incorrect resolution, though the text does not specify further consequences.
What the attacker needed
A CCIP-aware nested resolver in the RRset; client follows EIP-3668 flow
The fix
The resolveCallback function should be updated to catch OffchainLookup errors from nested calls and validate the sender field, as shown in the EIP-3668 example.
How it was found
- Client calls OffchainDNSResolver.resolve, which reverts with OffchainLookup and prompts the client to call resolveCallback after fetching data from the gateway.
- The RRset returned by the gateway contains a dnsresolver that is CCIP-aware and supports the IExtendedDNSResolver.resolve selector.
- Calling resolve on that dnsresolver could trigger another OffchainLookup error with a sender that does not match the dnsresolver.
- That error is returned to the client without modification, so the sender field is incorrect per the EIP.
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.
This is about a smart contract that helps resolve DNS names using off-chain data. When it calls another contract that also uses off-chain data, it should check for a special error and handle it properly, but it doesn't, so the client might get confused about which contract to ask for data.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.