Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: low
Valid

Inadequate Access Control in approve Function of CapitalPool Contract


Summary:

The approve function in the CapitalPool contract lacks sufficient access control, allowing any external entity to execute it. This vulnerability could lead to unauthorized approval of tokens to the tokenManager address, potentially resulting in a significant security risk if the tokenManager is compromised or misconfigured.


Vulnerability Details:

Description:
The approve function within the CapitalPool contract is publicly accessible, meaning any external address can invoke it. This function approves an unlimited allowance of tokens from the contract to the tokenManager address. Given the absence of any restrictive access controls, this could allow unauthorized entities to grant unlimited token allowances to the tokenManager, posing a severe risk if the tokenManager address is compromised or misconfigured.

Affected Code Snippet:

contract CapitalPool is CapitalPoolStorage, Rescuable, ICapitalPool {
bytes4 private constant APPROVE_SELECTOR =
bytes4(keccak256(bytes("approve(address,uint256)")));
constructor() Rescuable() {}
/**
* @dev Approve token for token manager
* @notice only can be called by token manager
* @param tokenAddr address of token
*/
function approve(address tokenAddr) external {
address tokenManager = tadleFactory.relatedContracts(
RelatedContractLibraries.TOKEN_MANAGER
);
(bool success, ) = tokenAddr.call(
abi.encodeWithSelector(
APPROVE_SELECTOR,
tokenManager,
type(uint256).max
)
);
if (!success) {
revert ApproveFailed();
}
}
}

Vulnerability Summary:

  • Function: approve(address tokenAddr)

  • Issue: Lack of access control on the approve function.

  • Risk: Unauthorized approval of tokens to the tokenManager address.


Impact:

  • Token Theft: If an attacker can successfully call the approve function, they can authorize the tokenManager to spend an unlimited amount of tokens from the CapitalPool contract. This could lead to the unauthorized draining of the contract's tokens.

  • Misconfiguration Risk: If the tokenManager address stored in the tadleFactory contract is incorrectly set or compromised, it could result in unintended or malicious entities gaining control over the tokens.

  • Loss of Funds: The exploitation of this vulnerability could result in a complete loss of tokens held within the CapitalPool contract, leading to significant financial damage.


Recommendations:

  1. Implement Access Control:

    • Restrict the approve function to only be callable by authorized addresses, such as the contract owner or a specific role (e.g., onlyOwner, onlyTokenManager).

    • Example modification:

      modifier onlyOwnerOrManager() {
      require(msg.sender == owner() || msg.sender == tadleFactory.relatedContracts(RelatedContractLibraries.TOKEN_MANAGER), "Not authorized");
      _;
      }
      function approve(address tokenAddr) external onlyOwnerOrManager {
      // existing logic
      }
  2. Secure tokenManager Address:

    • Ensure that the tadleFactory contract, which provides the tokenManager address, is secure and only allows trusted addresses to be set as the tokenManager.

    • Implement checks to verify the integrity of the tokenManager address before approval.

  3. Audit Related Contracts:

    • Conduct a thorough audit of the tadleFactory and tokenManager contracts to ensure there are no other vulnerabilities that could be exploited in conjunction with this issue.

  4. Implement Reentrancy Guards (if necessary):

    • While not directly related to this specific issue, consider implementing reentrancy guards to protect against potential reentrancy attacks, especially if the function is modified to include other state-changing logic in the future.


Conclusion:

The approve function in the CapitalPool contract poses a significant security risk due to the lack of proper access control. By implementing recommended security measures, including access control modifiers and securing the tokenManager address, the risk of unauthorized token approvals can be mitigated, protecting the contract from potential exploitation and financial loss.

Updates

Lead Judging Commences

0xnevi Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-CapitalPool-approve-missing-access-control

This is at most low severity, even though giving max approvals shouldn't be permisionless, the respective tokenManager address is retrieved from the TadleFactory contract whereby the trusted guardian role is responsible for deploying such contracts as seen [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/factory/TadleFactory.sol#L68). Since the user still has to go through the PreMarkets/DeliveryPlace contracts to perform market actions, this max approval cannot be exploited.

Support

FAQs

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