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

Missing isHooked check when calling onQueueWithdrawal hook function #22

Closed
c4-bot-9 opened this issue Sep 18, 2024 · 6 comments
Closed
Labels
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 duplicate-11 🤖_primary AI based primary recommendation 🤖_00_group AI based duplicate group recommendation sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-9
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/AccessControlHooks.sol#L812
https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/FixedTermLoanHooks.sol#L848

Vulnerability details

Impact

Due to missing check of isHooked value in onQueueWithdrawal function, improper reverts could happen with withdrawal operations.

Proof of Concept

Hooks are utilized to oversee and intervene in market activities such as deposits, transfers, and withdrawals. Each hook instance maintains a state variable named isHooked for every market, ensuring it is properly registered and authorized to interact with market operations. This is clearly demonstrated in the implementation of the onDeposit and onTransfer hook functions.

  function onDeposit(
    address lender,
    uint scaledAmount,
    MarketState calldata state,
    bytes calldata hooksData
  ) external override {
    HookedMarket memory market = _hookedMarkets[msg.sender];
>>  if (!market.isHooked) revert NotHookedMarket();
    ...
  function onTransfer(
    address /* caller */,
    address /* from */,
    address to,
    uint /* scaledAmount */,
    MarketState calldata /* state */,
    bytes calldata extraData
  ) external override {
    HookedMarket memory market = _hookedMarkets[msg.sender];

>>  if (!market.isHooked) revert NotHookedMarket();
    ...

However, the onQueueWithdrawal function lacks this check, potentially leading to mishandling of hook actions by an unauthorized hook instance. Both AccessControlHooks and FixedTermLoanHooks contracts have this issue.

Tools Used

Manual Review

Recommended Mitigation Steps

Add the check in the onQueueWithdrawal function:

  function onQueueWithdrawal(
    address lender,
    uint32 /* expiry */,
    uint /* scaledAmount */,
    MarketState calldata /* state */,
    bytes calldata hooksData
  ) external override {
+   HookedMarket memory market = _hookedMarkets[msg.sender];
+   if (!market.isHooked) revert NotHookedMarket();

    LenderStatus memory status = _lenderStatus[lender];
    if (
      !isKnownLenderOnMarket[lender][msg.sender] && !_tryValidateAccess(status, lender, hooksData)
    ) {
      revert NotApprovedLender();
    }
  }

Assessed type

Invalid Validation

@c4-bot-9 c4-bot-9 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 Sep 18, 2024
c4-bot-9 added a commit that referenced this issue Sep 18, 2024
@c4-bot-13 c4-bot-13 added 🤖_00_group AI based duplicate group recommendation 🤖_primary AI based primary recommendation labels Sep 18, 2024
@howlbot-integration howlbot-integration bot added sufficient quality report This report is of sufficient quality duplicate-26 labels Sep 20, 2024
@d1ll0n
Copy link

d1ll0n commented Sep 20, 2024

The poking of a lender's account is not permissioned; anyone could do it through the transfer function. The only reason the other functions have the isHooked check is because they can modify more of the state than just bumping a user's credentials through provider queries: specifically, deposit and transfer can both change whether an account is recorded as being a known lender, so those functions must be gated. Other hooks may require this check for more than these functions, but for this template it's not needed.

@d1ll0n d1ll0n added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Sep 20, 2024
@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Oct 4, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec marked the issue as grade-b

@c4-judge
Copy link
Contributor

This previously downgraded issue has been upgraded by 3docSec

@c4-judge c4-judge reopened this Oct 10, 2024
@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value duplicate-11 and removed downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax duplicate-26 labels Oct 10, 2024
@3docSec
Copy link

3docSec commented Oct 10, 2024

See #83 (comment) on why this group has been marked as M.

This particular dupe however lacks any elaboration on how a legitimately "missing check" translates to "improper reverts could happen".

@c4-judge c4-judge added unsatisfactory does not satisfy C4 submission criteria; not eligible for awards and removed grade-b labels Oct 10, 2024
@c4-judge
Copy link
Contributor

3docSec marked the issue as unsatisfactory:
Insufficient proof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 duplicate-11 🤖_primary AI based primary recommendation 🤖_00_group AI based duplicate group recommendation sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants