Anyone can upgrade Well's implementation #18
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-52
🤖_04_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-basin/blob/7d5aacbb144d0ba0bc358dfde6e0cc913d25310e/src/WellUpgradeable.sol#L64-L85
https://github.com/code-423n4/2024-07-basin/blob/7d5aacbb144d0ba0bc358dfde6e0cc913d25310e/src/WellUpgradeable.sol#L92-L95
Vulnerability details
Impact
Anyone can upgrade the contract to a malicious implementation that they control, allowing them to exploit the contract, and its users.
Proof of Concept
WellUpgradeable.sol is designed to be an upgradeable version of Well.sol, for which a new implementation can be easily and seamlessly upgraded to. As thus, the contract inherits UUPSUprageable and other upgradeable counterparts and also exposes the
_authorizeUpgrade
,upgradeTo
andupgradeToAndCall
functions. This ensures that the contracts can be updated.As would be expected from a sensitive contract's implementation, these functions should be limited to the admins alone. This however isn't the case as the functions lacks an
onlyOwner
modifier (despite inheriting openzeppelin's OwnableUpgradeable.sol).Looking at the functions, It can be observed that there's no form of access control.
Particularly the
_authorizeUpgrade
function, which according to OpenZeppelin's implementation will normally be protected by an access control.The possibilities are endless as anyone can easily upgrade the contract to an implementation of their choice, tailoring the new upgrade to their desires.
The gist link below holds a test case that shows a user can upgrade the contract to any implementation of his choice.
https://gist.github.com/ZanyBonzy/c982fad6a5a83759e98cf3f9860224c3
The test can be run using
forge test --mt testAnyoneCanUpgradeToNewImplementation -vvvv
and should pass.Tools Used
Manual code review
Recommended Mitigation Steps
Recommend adding the
onlyOwner
modifier to the_authorizeUpgrade
function.Assessed type
Access Control
The text was updated successfully, but these errors were encountered: