Skip to content
Access control Audit finding Intermediate

Ownership of EscherERC721.sol contracts can be changed, thus creator roles become useless

A user with the CREATOR_ROLE can create an ERC721 edition and grant the DEFAULT_ADMIN_ROLE to a non-creator, who can then revoke the creator's roles and take full ownership. This bypasses the intended restriction that only creators can administer editions.

stealthyz Follow

Originally disclosed on Code4rena

Submitted by stealthyz

https://github.com/code-423n4/2022-12-escher/blob/main/src/Escher.sol#L11

https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/65420cb9c943c32eb7e8c9da60183a413d90067a/contracts/access/AccessControlUpgradeable.sol#L150

https://github.com/code-423n4/2022-12-escher/blob/main/src/Escher721Factory.sol#L32

Impact

( creator = has a CREATOR_ROLE in Escher.sol

non-creator = doesn’t have a CREATOR_ROLE in Escher.sol )

Currently creating an ERC721 edition via the Escher721Factory.sol contract requires a user to have the CREATOR_ROLE in the main Escher.sol contract.

This requirement would mean that only users with the aforementioned role can be admins of editions. This requirement can be bypassed by having a ‘malicious’ creator create an edition for someone who doesn’t have the CREATOR_ROLE set by creating the edition and granting the DEFAULT_ADMIN_ROLE to the non-creator via AccessControl.sol’s grantRole() function. This way the non-creator can revoke the original creator’s roles in this edition and gain full ownership. Now this non-creator admin can create sales and operate as if he/she was a creator.

This defeats the point of having a role for creators and makes this function of the protocol not as described == faulty.

Proof of Concept

A creator can benefit from his role by taking in payments for creating ERC721 editions for other people. This would make sense so that his risk can be covered.

  1. A creator gets onboarded to Escher.
  2. For some time he stays good but then people start offering payments for edition ownership
  3. The more creators there are in Escher, the less of a chance to get caught. But then again, the more inclusive Escher gets, the more people will pay to get their own edition, which makes this pretty dangerous
  4. This creator creates an edition with the payer’s inputs and grants the payer the DEFAULTADMINROLE
  5. Payer revokes all of the creator’s roles and becomes the new admin

You can edit the Escher721.t.sol file to look like this and then run the test normally, everything should go through without errors:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "forge-std/Test.sol";
import {EscherTest} from "./utils/EscherTest.sol";

contract Escher721Test is EscherTest {
    function setUp() public override {
        super.setUp();
    }
    function test_grantRoles() public {
        address _this = address(this);
        // Malicious creator grants someone else the rights for this edition
        edition.grantRole(bytes32(0x0), address(9));
        vm.prank(address(9));
        // Now this user can grant/revoke roles
        edition.grantRole(edition.MINTER_ROLE(), address(9));
        assertEq(edition.hasRole(bytes32(0x0), address(9)), true);
        // clean out the partner
        edition.revokeRole(bytes32(0x0), _this);
        assertEq(edition.hasRole(bytes32(0x0), _this), false);
    }
}

This kind of attack/abuse is currently hard to track. There is no centralized database of created editions and their admins at the time of creations (i.e. a mapping). This makes it hard to track down malicious creators who create editions for other people. Looping through the emitted events and comparing current admins to the emitted admins is a hassle especially if this protocol gains a lot of traction in the future which I assume is the end goal here.

Tools Used

VS Code, Forge

Recommended Mitigation Steps

In EscherERC721.sol implementation contract, it is recommended to override the grantRole() function of AccessControlUpgradeable.sol with something like:

function grantRole(bytes32 role, address account) internal override {
    revert("Admins can't be chagned");
}

This will disable the granting of roles after initialization. The initialization function already has the required granting of roles done and they cannot be changed after this fix.

Overall it would be recommended to store the created editions in a mapping for example to prevent problems like these.

stevennevins (Escher) confirmed


The original report as published on Code4rena, by stealthyz. 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 edition contract inherits OpenZeppelin's AccessControlUpgradeable and does not restrict the grantRole function, so any admin can grant the DEFAULT_ADMIN_ROLE to any address.

Impact

A non-creator could gain full ownership of an edition and operate it as if they were a creator, defeating the purpose of the creator role.

What the attacker needed

A creator account; a payer willing to pay for an edition

The fix

Override grantRole in EscherERC721.sol to revert, preventing role changes after initialization, and optionally store created editions in a mapping for tracking.

How it was found

  1. A creator creates an ERC721 edition for a payer.
  2. The creator grants the payer the DEFAULT_ADMIN_ROLE.
  3. The payer revokes all of the creator's roles and becomes the new 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.

In this system, only special users called creators are supposed to be able to make and manage digital collectible editions. But a creator can hand over full control of an edition to anyone else, and that person can then remove the creator's rights. This means the special creator role does not actually stop non-creators from running editions.

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 from Escher contest

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.