Skip to content
Access control Audit finding Intermediate

Permission escalation by adding the same permission twice

The combinePermissions function adds permissions using addition instead of bitwise OR, so adding the same permission twice produces a different, potentially dangerous permission. An attacker with a controller could gain super delegatecall permission and change storage or steal assets.

gpersoon Follow with MiloTruck

Originally disclosed on Code4rena

Submitted by gpersoon, also found by MiloTruck

The function combinePermissions adds permission to available permissions. If the same permission is added twice, then this will result in a new and different permission. For example, adding _PERMISSION_STATICCALL twice results in _PERMISSION_SUPER_DELEGATECALL.

This way, accidentally dangerous permissions can be set. Once someone has a dangerous permission, for example _PERMISSION_SUPER_DELEGATECALL, they can change all storage parameters of the Universion Profile and then steal all the assets.

Proof of Concept

The following code shows this. Run with forge test -vv to see the console output.

pragma solidity ^0.8.13;

import "../../contracts/LSP6KeyManager/LSP6KeyManager.sol";
import "../../contracts/LSP0ERC725Account/LSP0ERC725Account.sol";
import "../../contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol";
import "../../contracts/LSP6KeyManager/LSP6Constants.sol";
import "./UniversalProfileTestsHelper.sol";

contract SetDataRestrictedController is UniversalProfileTestsHelper {
    LSP0ERC725Account public mainUniversalProfile;
    LSP6KeyManager public keyManagerMainUP;
    address public mainUniversalProfileOwner;
    address public combineController;

    function setUp() public {
        mainUniversalProfileOwner = vm.addr(1);
        vm.label(mainUniversalProfileOwner, "mainUniversalProfileOwner");
        combineController = vm.addr(10);
        vm.label(combineController, "combineController");
        mainUniversalProfile = new LSP0ERC725Account(mainUniversalProfileOwner);

        // deploy LSP6KeyManagers
        keyManagerMainUP = new LSP6KeyManager(address(mainUniversalProfile));
        transferOwnership(
            mainUniversalProfile,
            mainUniversalProfileOwner,
            address(keyManagerMainUP)
        );
    }

    function testCombinePermissions() public {
        bytes32[] memory ownerPermissions = new bytes32[](3);
        ownerPermissions[0] = _PERMISSION_STATICCALL;
        ownerPermissions[1] = _PERMISSION_STATICCALL;
        givePermissionsToController(
            mainUniversalProfile,
            combineController,
            address(keyManagerMainUP),
            ownerPermissions
        );
        bytes32 key = LSP2Utils.generateMappingWithGroupingKey(_LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX,bytes20(combineController));
        bytes memory r = mainUniversalProfile.getData(key);
        console.logBytes(r); // 0x00..4000  SUPER_DELEGATECALL
    }
}

See LSP6Utils.sol#L169-L177 for the code of combinePermissions.

Tools Used

Foundry

Recommended Mitigation Steps

The permissions shouldn’t be added, but they should be OR‘d. Here is a way to solve this:

function combinePermissions(bytes32[] memory permissions) internal pure returns (bytes32) {
    uint256 result = 0;
    for (uint256 i = 0; i < permissions.length; i++) {
-      result += uint256(permissions[i]);
+      result |= uint256(permissions[i]);
    }
    return bytes32(result);
}

Assessed type

Math

CJ42 (LUKSO) disagreed with severity and commented:

We don’t use this function in any of the standards. It is only used in the tests.

Because LSP6Utils is a library contract intended to be used for developer, we consider it is an issue. However, we consider it is unlikely that a developer will add the same permission two times in the array (if they do, it is on the developer end implementing our contracts that the mistakes happen in), we think the severity should be lower.

Trust (judge) decreased severity to Medium and commented:

Passing multiple identical permissions cannot be viewed as a mistake on the developer’s side. They may rightly assume that repeating permissions are ignored and aren’t expected to prefilter. The warden has not shown a clear end-to-end scenario where this would occur. Unless a reasonable likelihood can be demonstrated, the impact should be treated as a strong Medium.

The original report as published on Code4rena, by gpersoon. 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 combinePermissions function uses arithmetic addition instead of bitwise OR to combine permission bitmasks, causing duplicate permissions to overflow into other bits.

Impact

A controller could gain the super delegatecall permission, allowing them to change all storage parameters and steal all assets, though the report notes the function is only used in tests and the judge rated it Medium due to lack of a clear end-to-end scenario.

What the attacker needed

A controller with permission to set permissions; The same permission added twice in an array

How it was found

  1. Deploy a Universal Profile and a Key Manager.
  2. Give a controller an array containing the same permission twice.
  3. Read the controller's permissions and observe the unexpected permission.

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.

Permissions are stored as numbers where each bit represents a specific right. Adding two identical permission numbers can carry over to a different bit, granting an unintended right. This could let someone with limited access gain a powerful permission and take control of the account.

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 gpersoon

View all

47 more disclosed reports, best first.

More from LUKSO

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.