InfernalRiftBelow.claimRoyalties no verification msg.sender
The claimRoyalties function on L2 trusted any caller that implemented the cross-domain messenger interface, so an attacker could deploy a contract returning the expected sender address and invoke it. This allowed anyone to transfer NFTs held by the ERC721Bridgable contract.
IronsideSec Follow with Thanos, X12 and 9 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/406
Found by
Ironsidesec, Thanos, X12, ZeroTrust, cnsdkc007, ctf_sec, gr8tree, rndquu, shaflow01, snapishere, t.aksoy, zzykxx
Summary
claimRoyalties used to accept the message on the L1, then execute ERC721Bridgable.claimRoyalties, but not the authentication callers, may result in the loss of the assets in the protocol.
Vulnerability Detail
claimRoyalties are used to accept cross-chain calls, but msg.sender is not validated:
if (ICrossDomainMessenger(msg.sender).xDomainMessageSender() != INFERNAL_RIFT_ABOVE) {
revert CrossChainSenderIsNotRiftAbove();
}
If msg.sender is a contract account implementing the ICrossDomainMessenger interface, the xDomainMessageSender function returns an address of INFERNAL_RIFT_ABOVE, which means that the claimRoyalties function can be invoked.
So anyone can call this function as long as he deploys a contract.
InfernalRiftBelow.claimRoyalties function will be called ERC721Bridgable.claimRoyalties, transfer NFTs from ERC721Bridgable contract, so any can transfer NFTs from ERC721Bridgable.
L1 Send message to L2:
function claimRoyalties(address _collectionAddress, address _recipient, address[] calldata _tokens, uint32 _gasLimit) external {
.....
ICrossDomainMessenger(L1_CROSS_DOMAIN_MESSENGER).sendMessage(
INFERNAL_RIFT_BELOW,
abi.encodeCall(
IInfernalRiftBelow.claimRoyalties,
(_collectionAddress, _recipient, _tokens)
),
_gasLimit
);
emit RoyaltyClaimStarted(address(INFERNAL_RIFT_BELOW), _collectionAddress, _recipient, _tokens);
}
Impact
Anyone can steal NFT from the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
+ if (msg.sender != L2_CROSS_DOMAIN_MESSENGER) {
+ revert NotCrossDomainMessenger();
+ }
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
The function authenticated the caller by calling xDomainMessageSender() on msg.sender without first verifying that msg.sender was the legitimate L2 cross-domain messenger.
Impact
Anyone could steal NFTs held by the protocol.
What the attacker needed
Ability to deploy a contract on L2; no special privileges needed
The fix
The function should check that msg.sender is the legitimate L2 cross-domain messenger before trusting xDomainMessageSender.
How it was found
- Deploy a contract that implements the ICrossDomainMessenger interface and returns INFERNAL_RIFT_ABOVE from xDomainMessageSender.
- Call InfernalRiftBelow.claimRoyalties from that contract with chosen collection, recipient and token arguments.
- The call passes the sender check and reaches ERC721Bridgable.claimRoyalties, transferring NFTs to the attacker's recipient.
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.
A smart contract can call another contract and claim to be someone else if the receiving contract only checks a function on the caller. Here the L2 contract asked the caller 'who sent this cross-chain message?' but never checked that the caller was the real cross-chain messenger. An attacker could write a fake messenger that always answers with the expected address, then call the royalty claim and move NFTs out.
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.