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

Wrong implementation of accesss control for KatanaGovernance._authorized() #22

Closed
howlbot-integration bot opened this issue Nov 4, 2024 · 4 comments
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 primary issue Highest quality submission among a set of duplicates 🤖_primary AI based primary recommendation 🤖_18_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

@howlbot-integration
Copy link

Lines of code

/root/katana-operation-contracts/src/governance/KatanaGovernance.sol#L377-L383

Vulnerability details

Proof of Concept

The following implementation of _isAuthorized is wrong since an account is considered authorized if
block.timestamp > expiry even if $.allowed[account] = false. Meanwhile, even after the authorization expires, if $.allowed[account] is true, then it is still authorized.


 function _isAuthorized(Permission storage $, address account) private view returns (bool) {
    uint256 expiry = $.whitelistUntil;
    if (expiry == UNAUTHORIZED) return false;
    if (expiry == AUTHORIZED || block.timestamp > expiry) return true; // but we have not checked the account!

    return $.allowed[account];
  }

Recommended Mitigation Steps

The correct way is to check both expiration time and $.allowed[account] with a conjunction.


 function _isAuthorized(Permission storage $, address account) private view returns (bool) {
    uint256 expiry = $.whitelistUntil;
    if (expiry == UNAUTHORIZED) return false;
-    if (expiry == AUTHORIZED || block.timestamp > expiry) return true; // but we have not checked the account!

+    if(expiry = AUTHORIZED) return true;

-    return $.allowed[account];
-    if(block.timestamp > expiry && $.allowed[account]) return true;

  }

Assessed type

Access Control

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_18_group AI based duplicate group recommendation 🤖_primary AI based primary recommendation bug Something isn't working primary issue Highest quality submission among a set of duplicates sufficient quality report This report is of sufficient quality labels Nov 4, 2024
howlbot-integration bot added a commit that referenced this issue Nov 4, 2024
@khangvv
Copy link

khangvv commented Nov 5, 2024

The authorization checks are prioritized as written in the code. Both timestamp-based permissions and those allowed via the array are valid options and should be treated as granting access. This functions as a "merge" strategy for the whitelist rather than a strict conjunction.

@khangvv khangvv added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Nov 5, 2024
@khanhtaskymaviscom
Copy link

This is a design decision, not a bug. The protocol initially allows certain accounts to interact with the token/pool for a set period. After this initial phase, anyone can interact with the created pool.

@alex-ppg
Copy link

The submission and its duplicates seem to have misinterpreted the whitelist system in use by the code. Specifically, the expiry variable represents the timestamp at which the whitelist should no longer be enforced and all users should have access.

As such, the code presently behaves correctly as it will either disallow access due to the special UNAUTHORIZED flag, allow access due to the special AUTHORIZED flag, or if the whitelist is no longer meant to be enforced, or allow access conditionally per account if the whitelist is in effect.

@c4-judge
Copy link

alex-ppg marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Nov 11, 2024
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 primary issue Highest quality submission among a set of duplicates 🤖_primary AI based primary recommendation 🤖_18_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

4 participants