Skip to content
Access control Audit finding Intermediate

Restricted modifier should not be used with int

The report claims that the `restricted` modifier from OpenZeppelin's `AccessManagedUpgradeable` is applied to internal functions `_authorizeUpgrade` in `PufferDepositor` and `PufferVault`, which the reporter says bypasses access control because internal functions are not externally callable. The reporter asserts this could allow unauthorised access or operations, but no concrete exploit is demonstrated.

SAAJ Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

29082 - [SC - Insight] Restricted modifier should not be used with int...

Submitted on Mar 6th 2024 at 19:19:09 UTC by @SAAJ for Boost | Puffer Finance

Report ID: #29082

Report type: Smart Contract

Report severity: Insight

Target: https://etherscan.io/address/0x7276925e42f9c4054afa2fad80fa79520c453d6a

Impacts:

  • wrong usage of OpenZeppelin library in contract

Description

Vulnerability Details

_authorizeUpgrade is an internal function in PufferDepositor and PufferVault that uses the restricted modifier from the contract AccessManagedUpgradeable.

Impact

The restricted modifier is designed to enforce access control based on the caller's identity and the function being called. It checks if the caller is authorized to perform the operation.

Internal functions are not accessible from outside the contract, the access control mechanism provided by the restricted modifier is effectively bypassed. This means that any internal function marked with restricted can be called without any checks, potentially allowing unauthorized access or operations.

Code Reference

https://github.com/PufferFinance/pufETH/blob/2768d69196717e9f77a6837153b426e06e15c51f/src/PufferDepositor.sol#L202

https://github.com/PufferFinance/pufETH/blob/2768d69196717e9f77a6837153b426e06e15c51f/src/PufferVault.sol#294

Recommendations

The recommendation is made to use ownable2StepUpgradeable instead of AccessManagedUpgradeable for both the the ownable2StepUpgradeable have onlyAdmin modifier which can be used without any restrictions.

Proof of concept

POC

OZ clearly warns about using the restricted modifier with internal functions that can lead to serious security issues as stated in the contract:

‘Unless you know what you're doing, it should never be used on internal functions. Failure to follow these rules can have critical security implications! This is because the permissions are determined by the function that entered the contract, i.e. the function at the bottom of the call stack, and not the function where the modifier is visible in the source code.’

/**
     * @dev Authorizes an upgrade to a new implementation
     * Restricted access
     * @param newImplementation The address of the new implementation
     */
    function _authorizeUpgrade(address newImplementation) internal virtual override restricted { }

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

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 `restricted` modifier was applied to an internal function, which OpenZeppelin warns against because permissions are determined by the externally called function, not the internal one.

Impact

The report claims this could allow unauthorised access or operations, but no actual exploit or proof is provided.

What the attacker needed

None

The fix

The report recommends using `ownable2StepUpgradeable` instead of `AccessManagedUpgradeable` for both contracts.

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 modifier is a small piece of code that runs before a function to check something, like whether the caller is allowed. The report says a check meant for public functions was put on an internal function, which outside users cannot call directly, so the check may not work as intended. However, the report does not show a real attack, only a warning.

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 SAAJ

View all

9 more disclosed reports, best first.

More from Puffer Finance

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.