Unverified `_srcChainSender` parameter allows to impersonate the sender
The cross-chain message receiver function does not verify the `_srcChainSender` parameter for certain message types, allowing an attacker to execute modules on behalf of any user. This could let the attacker perform actions such as removing collateral and exiting positions for a victim.
ComposableSecurity Follow with bin2chen, cccz and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/14
The protocol has acknowledged this issue.
Found by
ComposableSecurity, bin2chen, cccz, cergyk
Summary
The _toeComposeReceiver function accepts the _srcChainSender parameter that represents the sender of cross-chain message (via LayerZero's OFT) on the source chain. The function executes modules depending on the _msgType parameter and some of them do not accept the _srcChainSender parameter. Lack of verification for _srcChainSender means that the attacker can execute those modules on behalf of different users.
Vulnerability Detail
The _toeComposeReceiver function is called by the LayerZero endpoint (indirectly) when there is a compose message to be executed. It gets three parameters:
The first patameter (_msgType) represents the type of message that should be executed on the destination chain. The second (_srcChainSender) is the sender of the message on the source chain and last one (_toeComposeMsg) contains the parameters for the executed operation.
In case of MSG_TAP_EXERCISE the _srcChainSender parameter is forwarded to the UsdoOptionReceiver module:
https://github.com/sherlock-audit/2024-02-tapioca/blob/main/Tapioca-bar/contracts/usdo/modules/UsdoReceiver.sol#L68-L75
In case of other types (MSG_MARKET_REMOVE_ASSET, MSG_YB_SEND_SGL_LEND_OR_REPAY and MSG_DEPOSIT_LEND_AND_SEND_FOR_LOCK) the _srcChainSender parameter is not forwarder and the attacker fully control the contents of _toeComposeMsg.
Let's take the MSG_MARKET_REMOVE_ASSET message as an example.
- The
removeAssetReceiverfunction fromUsdoMarketReceiverModuleis executed with_toeComposeMsgparameter.
- The
_toeComposeMsgbytes (called_datain this function) are decoded and some values are extracted. The most important are:
msg_.externalData.magnetaron which theburstfunction is later called with specific magnetar calls (it is legitimate and whitelisted magnetar),msg_.useron whose behalf the further operation is called,msg_.externalDatawhich is forwarder to further call,msg_.removeAndRepayDatawhich is forwarder to further call.
Those parameters are used to prepare a call to exitPositionAndRemoveCollateral function from OptionModule module (defined in action's id param).
- Next, the
burstfunction from magnetar contract is called and it executes the specific module depending on the_action.id:
- The modules validates the sender passing the user address as the parameter.
- The
_checkSenderfunction does not revert if the user is the sender or the sender is whitelisted.
- In this case the sender is USDO contract which is whitelisted. This allows to continue operations from
exitPositionAndRemoveCollateralfunction on behalf of the user (who is the victim).
Note: This is only one of possible attack scenarios that exploits lack of _srcChainSender parameter validation.
Impact
HIGH - The attacker can execute functions from UsdoMarketReceiverModule module on behalf of any user.
Code Snippet
Tool used
Manual Review
Recommendation
Validate whether the user whose assets are being managed is the same address as the _srcChainSender parameter.
Discussion
nevillehuang
@0xRektora @maarcweiss
Do you guys thinks this is a dupe of #111?
cryptotechmaker
@nevillehuang I think it's a dupe of https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/109 for which I submitted a fix already
It doesn't seem to be duplicate of #111
nevillehuang
@cryptotechmaker Yes agree.
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 attacker can execute functions from `UsdoMarketReceiverModule` on behalf of any user, potentially leading to loss of funds or unauthorized actions.
What the attacker needed
Ability to send cross-chain messages; knowledge of victim's address
The fix
Validate that the user whose assets are being managed is the same address as the `_srcChainSender` parameter.
How it was found
- Attacker sends a cross-chain message of type `MSG_MARKET_REMOVE_ASSET` with a crafted `_toeComposeMsg` containing the victim's address.
- The `_toeComposeReceiver` function calls `removeAssetReceiver` with the attacker-controlled `_toeComposeMsg`.
- The `removeAssetReceiver` decodes the message and prepares a call to `exitPositionAndRemoveCollateral` on behalf of the victim.
- The `burst` function on the magnetar contract is called, which executes the module specified in the action's `id`.
- The module checks the sender (USDO contract) which is whitelisted, so the operation proceeds on behalf of the victim.
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.
When a message arrives from another blockchain, the contract should check who sent it. Here, for some message types, it does not check, so an attacker can pretend to be any user and make the contract act as if that user requested an action.
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.