Attacker can use MagnetarAction.OFT action of the Magnet to perform operations as any user including directly stealing user tokens
The Magnetar contract's OFT action did not verify the function selector in the calldata against the target address, and because Magnetar itself was whitelisted, an attacker could make it call itself and bypass the sender check. This allowed the attacker to impersonate any user and withdraw their collateral to an attacker-controlled address on another chain.
ronnyx2017 Follow with immeas, rvierdiiev and 3 others
Originally disclosed on Code4rena
Submitted by ronnyx2017, also found by immeas, carrotsmuggler (1, 2), GalloDaSballo (1, 2, 3), rvierdiiev, deadrxsezzz, cccz, and ladboy233
This issue requires the combination of two vulnerabilities to achieve the impact described in the title. The first vulnerability is that the Magnetar._processOFTOperation function doesn’t check the function sigs in the action calldata with the the target addresses. It only ensures the calling target addresses are in the Whitelist of the Cluster. So an attacker can use this vuln to call any whitelist target address from the Magnetar.
The second vulnerability is that the Magnetar contract address itself will also be added to the Cluster whitelist. It can be found in the following integration test here. If the attacker can let the Magnetar call itself, the msg.sender in the sub-call will be in the whitelist. It will bypass the _checkSender check:
function _checkSender(address _from) internal view {
if (_from != msg.sender && !cluster.isWhitelisted(0, msg.sender)) {
revert Magnetar_NotAuthorized(msg.sender, _from);
}
}
Impact
Combining the two issues mentioned above, we can carry out the following exploitation.
- Call
Magnetar.burstfunction with_action.id == MagnetarAction.OFT, which will call_processOFTOperationfunction. The_targetis the Magnetar contract itself, and the_actionCalldatais still an encoded calldata to call theMagnetar.burstfunction with_action.id == MagnetarAction.OFTagain. - In the second call, the
msg.senderwill be the Magnetar itself, so the from address check in the_checkSenderfunction will be skipped directly because themsg.senderis in the whitelist. - Now the attacker can pretend to be anyone and call any contract through the Magnetar. Please note that users approved their tokens to Magnetar if they used it.
Proof of Concept
Taking MagnetarAssetModule as an example, it demonstrates how an attacker could steal users’ collateral in the market.
Firstly the _checkSender(data.user); can be bypassed directly.
And make data.withdrawCollateralParams.withdraw = true, so the collateralWithdrawReceiver will be the Magnetar contract itself:
address collateralWithdrawReceiver = data.withdrawCollateralParams.withdraw ? address(this) : data.user;
Then if collateralShare > 0, the function will call _withdrawToChain(data.withdrawCollateralParams); to withdraw the collateral to the another chain by sending LZ message.
There is no check for withdrawCollateralParams in the _withdrawToChain function. The attacker can set the receiver address to his address and finally receive the tokens on the target chain.
Recommendation
Check the target function sig in the _processOFTOperation function.
Medium, the same happens if you approve the attacker for an ERC20. However, this is worth fixing in my opinion. I think we can add specific selectors instead of allowing any call to be executed.
Fixed 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
Likely the missing validation of the function selector in the OFT action calldata combined with the Magnetar contract being whitelisted, allowing a self-call that bypasses the sender check.
Impact
An attacker could impersonate any user and withdraw their collateral to an attacker-controlled address on another chain, potentially stealing user tokens.
What the attacker needed
Users have approved tokens to Magnetar; Magnetar is whitelisted in the Cluster
The fix
The issue was fixed by adding specific selectors instead of allowing any call to be executed.
How it was found
- Call Magnetar.burst with action id OFT, setting the target to Magnetar itself and the calldata to another burst call with OFT action.
- In the second call, msg.sender is Magnetar, which is whitelisted, so the _checkSender check is skipped.
- Set withdrawCollateralParams.withdraw to true so the collateral withdraw receiver becomes the Magnetar contract.
- Call _withdrawToChain with the attacker's address as receiver to receive the tokens on the target chain.
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 called Magnetar lets users perform actions like withdrawing collateral. It checked who was asking but not what function they were calling. Because the contract was allowed to call itself, an attacker could trick it into thinking the request came from a trusted source, then act as any user and steal their funds.
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.