Critical access control flaw: Role removal logic incorrectly grants unauthorized roles
The removeRole function incorrectly replaces a removed role with the last role from the global roles list, granting the user an unrelated role. An attacker could gain unauthorized administrative permissions such as BRIBE_ADMIN or GAUGE_ADMIN.
rayss Follow with KineticsOfWeb3
Originally disclosed on Code4rena
Submitted by rayss, also found by KineticsOfWeb3
Finding description
The removeRole() function incorrectly updates a user’s role list by replacing a removed role with the last role from the global_roles array. This results in unintended and unauthorized role assignments to users.
The removeRole() function correctly removes a role from the system by deleting it from the global roles list. However, when updating the users’ assigned roles arrays, the current logic mistakenly replaces the removed role with the last role from the global roles list rather than just deleting the role from the array.
When removing a role from a user’s assigned roles array (_addressToRoles[user]), the function tries to keep the array compact by replacing the role to be removed with the last element of the global_roles array. This is incorrect because it mistakenly assigns a completely unrelated role from the global roles list to the user, corrupting their role assignments.
This causes unrelated global roles to be incorrectly assigned to the user whose role is being removed.
Proof of Concept (Example)
Assume the global_roles array contains:
["GOVERNANCE", "VOTER_ADMIN", "GAUGE_ADMIN", "BRIBE_ADMIN"]
Alice has two roles:
_addressToRoles[Alice] = ["VOTER_ADMIN", "GAUGE_ADMIN"]
Calling removeRole("GAUGE_ADMIN") results in:
_addressToRoles[Alice][1] = _roles[_roles.length - 1]; // "BRIBE_ADMIN"
_addressToRoles[Alice].pop();// removes last element
Alice’s roles become:
["VOTER_ADMIN", "BRIBE_ADMIN"]
Now Alice has Alice unintentionally gains the BRIBE_ADMIN role without authorization.
Impact
- This bug leads to privilege escalation — a user can be granted a role they were never assigned, simply due to role removal logic. If roles like
BRIBE_ADMINorGAUGE_ADMINare mistakenly granted. - Broken access control due to corrupted role removal logic.
Severity Justification
This issue is classified as high severity because it directly compromises the integrity of the protocol’s access control system. By unintentionally assigning incorrect roles during the removal process, users may be granted powerful administrative permissions such as GAUGE_ADMIN or BRIBE_ADMIN (or any other role) without proper authorization. These roles often govern critical operations, which can influence protocol behavior.
Recommended mitigation steps
for (uint i = 0; i < atr.length; i++) {
if (keccak256(atr[i]) == keccak256(_role)) {
atr[i] = atr[atr.length - 1]; // Replace with last element
atr.pop(); // Remove last element
break;
}
}
The mitigation correctly updates the user’s assigned roles array (_addressToRoles[user]) without referencing the global_roles array. When removing a role, it swaps the role to be removed with the last element in the user’s own roles array and then removes (pops) the last element. This preserves the compactness and order of the array while ensuring only roles actually assigned to the user remain.
Crucially, it avoids mistakenly assigning unrelated roles from the global_roles list, preventing corruption of the user’s role data and maintaining accurate access control.
Status: Mitigation confirmed. Full details in reports from rayss and maxvzuvex.
The sponsor team requested that the following note be included:
This issue originates from the upstream codebase, inherited from ThenaV2 fork. Given that ThenaV2 has successfully operated at scale for several months without incident, we assess the severity of this issue as low. The implementation has been effectively battle-tested in a production environment, which significantly reduces the practical risk associated with this finding. Reference: https://github.com/ThenafiBNB/THENA-Contracts/blob/main/contracts/PermissionsRegistry.sol#L108
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code uses the global roles array instead of the user's own roles array when compacting the array after removal.
Impact
A user could be granted an administrative role they were never assigned, leading to privilege escalation.
What the attacker needed
User has at least one role; role to remove is not the last in global list
The fix
The fix should replace the removed role with the last element of the user's own roles array, not the global roles array.
How it was found
- Assume global_roles contains GOVERNANCE, VOTER_ADMIN, GAUGE_ADMIN, BRIBE_ADMIN.
- Alice has roles VOTER_ADMIN and GAUGE_ADMIN.
- Call removeRole("GAUGE_ADMIN").
- Alice's roles become VOTER_ADMIN and BRIBE_ADMIN.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract manages who has which permissions. When removing a permission, the code mistakenly gives the user a different permission from a global list. This means someone could end up with admin rights they were never supposed to have.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.