HardhatDeFi
15,000 USDC
View results
Submission Details
Severity: high
Invalid

Lack of Access Control on approveCollateralTokenForAave & batchApproveCollateralTokenForAave

Summary

The contract AaveDIVAWrapper contains functions approveCollateralTokenForAave and batchApproveCollateralTokenForAave that allow anyone to approve collateral tokens for the Aave protocol. This lack of proper access control poses a significant risk, as any user can call these functions and potentially manipulate collateral approval without authorization.


Vulnerability Details

  • Vulnerable Functions:

    • approveCollateralTokenForAave(address _collateralToken)

    • batchApproveCollateralTokenForAave(address[] calldata _collateralTokens)

  • Vulnerability:
    These functions currently do not include any access control mechanisms such as onlyOwner or any privileged role checks. As a result, any external address (including malicious actors) can call these functions and approve tokens for Aave. This could potentially lead to unauthorized token approvals, allowing users to interact with the Aave protocol in unintended ways.


Root Cause

  • The root cause of this issue is the absence of access control restrictions on critical functions that interact with external protocols. Functions like approveCollateralTokenForAave should only be callable by trusted addresses (e.g., the owner or a designated privileged role) to avoid abuse.


https://github.com/Cyfrin/2025-01-diva/blob/main/contracts/src/AaveDIVAWrapper.sol#L92

https://github.com/Cyfrin/2025-01-diva/blob/main/contracts/src/AaveDIVAWrapper.sol#L202


Impact

  • Token Manipulation Risk:
    Any attacker could call the approveCollateralTokenForAave or batchApproveCollateralTokenForAave functions, potentially approving tokens for Aave and allowing them to use these tokens in the system maliciously.

  • Unauthorized Access to Aave Protocol:
    Unauthorized users could approve tokens for use in liquidity pools, leading to the possibility of financial exploits and loss of funds by the legitimate contract owner or users.

  • Loss of Reputation:
    If this vulnerability is exploited, the reputation of the project could be severely damaged. Trust from users and investors could be undermined.


Tools Used

  • Static Analysis Tools:

    • MythX

    • Slither

    • Securify

  • Manual Review:

    • Code inspection to identify logical flaws and access control issues.


Proof of Concept

  1. Scenario:
    Suppose an attacker knows the contract's address and the collateral token's address. They can directly call the approveCollateralTokenForAave function and approve any token they choose for Aave without any authorization check.

    • The attacker could invoke the function as follows:

      contractInstance.approveCollateralTokenForAave(collateralTokenAddress);
    • This would allow the attacker to approve tokens without any validation.

  2. Batch Approval:
    Similarly, with batchApproveCollateralTokenForAave, an attacker could approve multiple tokens for Aave, thereby bypassing security and exposing the system to potential financial exploitation.


Mitigation

To fix this vulnerability, the following steps are recommended:

  1. Access Control:

    • Implement access control modifiers, such as onlyOwner or a specific role-based restriction, to ensure that only authorized addresses can call these functions.

    • Example code for access control:

      modifier onlyOwner() {
      require(msg.sender == owner, "Not the contract owner");
      _;
      }
      function approveCollateralTokenForAave(address _collateralToken) external onlyOwner {
      _approveCollateralTokenForAave(_collateralToken);
      }
  2. Role-based Access Control:

    • For more flexibility, integrate the AccessControl contract from OpenZeppelin to manage privileged roles dynamically.

    • Example:

      function approveCollateralTokenForAave(address _collateralToken) external onlyRole(ADMIN_ROLE) {
      _approveCollateralTokenForAave(_collateralToken);
      }

Conclusion

The lack of access control on critical functions like approveCollateralTokenForAave and batchApproveCollateralTokenForAave poses a significant security risk. By implementing appropriate access control mechanisms (e.g., onlyOwner, onlyRole), the contract can be made secure against unauthorized users, mitigating the risk of manipulation and protecting user funds.

Updates

Lead Judging Commences

bube Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.