MagnetarMintXChainModule.sol : mintBBLendXChainSGL can be used to manipulate user positions by abusing whitelist privileges
The Magnetar contract's sender check allows any whitelisted contract to act on behalf of any user, and the cross-chain mint function lets an attacker supply an arbitrary victim address in the composed message. A whitelisted contract such as USDO then executes market operations against the victim's account, moving their tokens and positions.
carrotsmuggler Follow with carrotsmuggler and GalloDaSballo
Originally disclosed on Code4rena
Submitted by carrotsmuggler, also found by carrotsmuggler, GalloDaSballo, and cccz (1, 2)
The Magnetar functions use _checkSender function to check if the caller should be allowed to perform operations on the account. The function allows operations if the caller is the owner, or if the caller is a whitelisted trusted address.
function _checkSender(address _from) internal view {
if (_from != msg.sender && !cluster.isWhitelisted(0, msg.sender)) {
revert Magnetar_NotAuthorized(msg.sender, _from);
}
}
However, this means that if a malicious user is able to make a whitelisted contract call magnetar functions with their own payload, they can steal tokens and wreak havoc on other user’s accounts!
The function depositYBLendSGLLockXchainTOLP in the MagnetarAssetXChainModule contract uses a similar check. This function deposits and lends into markets, for the account passed in as data.user. Crucially, it also extracts tokens from data.user for these operations. So if a malicious user was able to get this function called by a whitelisted contract and pass in a malicious data.user, they can cause the target user to lose tokens and manipulate their market positions. This is a high severity issue and the path to attack is demonstrated below.
Proof of Concept
The entry point is the MagnetarMintXChainModule contract’s mintBBLendXChainSGL function for the attacker. This is a special function, in the sense that this sets up the system for multiple cross chain calls. This function calls the USDO function which then does an lzcompose call on another chain to the Magnetar contract again. This is a complex function and the attacker can use this to manipulate the system.
The flow of control of this function is shown below:
flowchart LR
Caller --mintBBLendXChainSGL--> MA["Magnetar\n(chain A)"];
MA -- sendPacket() --> USDOA["USDO\n(chain A)"];
USDOA -- lzSend --> EA["Endpoint\n(chain A)"];
EB["Endpoint\n(chain B)"] -- lzReceive (1) --> USDOB["USDO\n(chain B)"];
USDOB -- sendCompose (2) --> EB;
EB -- lzcompose (3) --> USDOB;
USDOB --depositYBLendSGLLockXchainTOLP--> MB["Magnetar\n(chain B)"];
MB --> Markets["Markets\n(chain B)"];
As shown in the above diagram, the caller initiates the call to the Magnetar contract. The Magnetar contract then does a cross-chain call via the USDO contract. It also sends along a lzcompose message which will be executed on chainB. On chainB, the USDO contract receives the call and initiates the lzcompose execution. Due to how the system is designed, this lzcompose message being executed by the USDO contract is actually a call to the Magnetar contract on chainB, specifically the depositYBLendSGLLockXchainTOLP function.
This can be shown by the fact that on chainA, the Magnetar encodes the lzcompose message into a struct.
DepositAndSendForLockingData memory lendData = abi.decode(tapComposeMsg_, (DepositAndSendForLockingData));
lendData.lendAmount = data.mintData.mintAmount;
data.lendSendParams.lzParams.sendParam.composeMsg =
TapiocaOmnichainEngineCodec.encodeToeComposeMsg(abi.encode(lendData), msgType_, msgIndex_, nextMsg_);
Then this same DepositAndSendForLockingData struct is accepted as an input on chainB depositYBLendSGLLockXchainTOLP function.
function depositYBLendSGLLockXchainTOLP(DepositAndSendForLockingData memory data) public payable
On chainB, the data.user is the target of the operation. Since the caller is the USDO contract, which is not the data.user value, for this to work, the USDO contract must have been whitelisted by the system.
This means the malicious user can send in any data.user in their data.lendSendParams.lzParams.sendParam.composeMsg field, and the USDO contract will execute it on their behalf. No access checks will be performed, since the USDO contract is whitelisted. The target just needs to have given allowance to the Magnetar contract itself to perform market operations on their behalf. There are no checks on DepositAndSendForLockingData.user field in the mintBBLendXChainSGL function on chainA, so the malicious user can send in practically any address they want, and the whitelisted USDO contract will carry out the transaction.
This skips a crucial user check and manipulates other user positions; hence, it is a high severity issue.
Recommended Mitigation Steps
The architecture of this crosschain call is quite vulnerable. Due to the whitelist, any function call that can be done via USDO contract is risky since it can override the Magnetar checks. The mintBBLendXChainSGL function on chainA should make sure the lzcompose data.user is the same as the current data.user, but this only blocks a single attack vector. USDO contract is crosschain compatible and allows lzcompose message, so any other methods which can be used to trigger such a cross chain call can abuse the whitelist.
0xRektora (Tapioca) confirmed via duplicate Issue #124
cryptotechmaker (Tapioca) commented via duplicate Issue #124:
PR here.
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 sender check treats any whitelisted caller as authorised for any account, and the cross-chain mint function does not verify that the user in the composed message matches the original caller.
Impact
An attacker could move a victim's tokens and manipulate their market positions, provided the victim has already given the Magnetar contract an allowance.
What the attacker needed
Victim has given Magnetar a token allowance; attacker can trigger a cross-chain call; USDO is whitelisted on Magnetar
The fix
The cross-chain mint function should require the composed message's user to equal the original caller, and the broader whitelist-based authorisation for cross-chain calls should be reworked; the report notes a fix was submitted.
How it was found
- Call mintBBLendXChainSGL on Magnetar on chain A, setting the composed message's user field to the victim's address.
- Magnetar sends a cross-chain packet through USDO, which includes the composed message.
- On chain B, USDO receives the packet and executes the lzcompose call to Magnetar's depositYBLendSGLLockXchainTOLP.
- Because USDO is whitelisted, the sender check passes and the function operates on the victim's account, moving their tokens and market positions.
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 contract called Magnetar lets users deposit and borrow tokens. It trusts certain helper contracts, called whitelisted contracts, to act for any user without checking who that user is. An attacker can make one of those trusted helpers carry out actions on a victim's account, so the victim's tokens and positions can be moved without their consent.
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.