Skip to content
Access control Audit finding Intermediate

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

https://github.com/code-423n4/2025-05-blackhole/blob/92fff849d3b266e609e6d63478c4164d9f608e91/contracts/PermissionsRegistry.sol#L113

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_ADMIN or GAUGE_ADMIN are 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.

Blackhole mitigated

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


The original report as published on Code4rena, by rayss. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Assume global_roles contains GOVERNANCE, VOTER_ADMIN, GAUGE_ADMIN, BRIBE_ADMIN.
  2. Alice has roles VOTER_ADMIN and GAUGE_ADMIN.
  3. Call removeRole("GAUGE_ADMIN").
  4. 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.

More by rayss

View all

1 more disclosed report, best first.

More from Blackhole

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.