You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🧐 Motivation
Right now the only function to set an admin role is: function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual
That can be used to set up a role hierarchy in the constructor of a class extending AccessControl, but there would be issues if the role hierarchy should be defined at runtime.
📝 Details
If defining roles at runtime, changing the role admin for a particular role should be restricted to members of the current admin role. Otherwise anyone could change an admin role to gain control of another role.
Example: A role with DEFAULT_ADMIN_ROLE as the admin role. Only members of the DEFAULT_ADMIN_ROLE should be able to redefine the admin role.
A class extending AccessControl doesn't have access to getRoleAdmin (external) or _roles (private). That means that a class extending AccessControl cannot know what is the admin role of another role, and cannot implement the rule above.
Options
Make getRoleAdmin public.
Add an external setRoleAdmin function checking for admin role membership of msg.sender.
function setRoleAdmin(bytes32 role, bytes32 adminRole) external virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to set admin role");
_setRoleAdmin(role, adminRole);
}
Both options could be implemented.
I'm not sure of the reason for a view function to be external (bug?).
AccessControl.sol implements a role hierarchy, I think that without an external setRoleAdmin function the contract is incomplete, forcing the user to correct this vulnerability in an extending contract if they want to obtain the full functionality.
The text was updated successfully, but these errors were encountered:
Thanks for opening this @albertocuestacanada! Indeed, the intent behind AccessControl is to allow for dynamic role hierarchies, but it is not supported out of the box: you'll have to think about which requirements to add when exposing _setRoleAdmin externally.
Your comment about getRoleAdmin() external getting in the way is spot-on: we've identified a number of issues related to having external functions, and so opened #2162 to get rid of them all. Once that PR is merged, dynamic hierarchies should work just fine.
🧐 Motivation
Right now the only function to set an admin role is:
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual
That can be used to set up a role hierarchy in the constructor of a class extending
AccessControl
, but there would be issues if the role hierarchy should be defined at runtime.📝 Details
If defining roles at runtime, changing the role admin for a particular role should be restricted to members of the current admin role. Otherwise anyone could change an admin role to gain control of another role.
Example: A role with
DEFAULT_ADMIN_ROLE
as the admin role. Only members of theDEFAULT_ADMIN_ROLE
should be able to redefine the admin role.A class extending
AccessControl
doesn't have access togetRoleAdmin
(external) or_roles
(private). That means that a class extendingAccessControl
cannot know what is the admin role of another role, and cannot implement the rule above.Options
getRoleAdmin
public.setRoleAdmin
function checking for admin role membership ofmsg.sender
.function setRoleAdmin(bytes32 role, bytes32 adminRole) external virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to set admin role");
_setRoleAdmin(role, adminRole);
}
Both options could be implemented.
AccessControl.sol
implements a role hierarchy, I think that without an externalsetRoleAdmin
function the contract is incomplete, forcing the user to correct this vulnerability in an extending contract if they want to obtain the full functionality.The text was updated successfully, but these errors were encountered: