Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_cancelAndRefund is not protected from re-entrancy #223

Open
code423n4 opened this issue Nov 24, 2021 · 2 comments
Open

_cancelAndRefund is not protected from re-entrancy #223

code423n4 opened this issue Nov 24, 2021 · 2 comments
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working

Comments

@code423n4
Copy link
Contributor

Handle

pauliax

Vulnerability details

Impact

function _cancelAndRefund is not protected from re-entrancy. _cancelAndRefund uses an unsafe _transfer that performs a low-level call which is susceptible to re-entrancy attack. These calls should be the last step or you may receive unexpected guests. Even the comment says that but it is actually not the last step:

    if (refund > 0) {
      // Security: doing this last to avoid re-entrancy concerns
      _transfer(tokenAddress, _keyOwner, refund);
    }
    // inform the hook if there is one registered
    if(address(onKeyCancelHook) != address(0))
    {
      onKeyCancelHook.onKeyCancel(msg.sender, _keyOwner, refund);
    }

Recommended Mitigation Steps

Consider either making this _transfer the last step or adding re-entrancy protection: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Nov 24, 2021
code423n4 added a commit that referenced this issue Nov 24, 2021
@julien51
Copy link
Collaborator

Interesting. Considering here that the hook itself can only be set by a lock manager, I would assume that it would not trigger a re-entrency call to canceling a key again. Additionally the function _cancelAndRefund can only be called if the the key owner has a valid key (hasValidKey) and the key is expired before the refund.

so all in all, i think we should clarify the comment but I would think we are actually safe here.

@julien51 julien51 added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Dec 11, 2021
@0xleastwood
Copy link
Collaborator

Agree with sponsor. Doesn't seem like its exploitable but will keep as low.

@0xleastwood 0xleastwood added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 16, 2022
@0xleastwood 0xleastwood removed the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants