Skip to content
Access control Audit finding Advanced

auth only works well with external functions

The auth modifier in AccessControl.sol checks msg.sig, which reflects the first function called in a transaction, not the current function. Thus, if a public function with auth is called internally from another function, the modifier checks authorisation for the caller function instead of the intended one, potentially allowing unauthorised access if such a call path exists.

Yield Witch v2 contest

Originally disclosed on Code4rena

The auth modifier of AccessControl.sol doesn’t work as you would expect. It checks if you are authorized for msg.sig. However, msg.sig is the signature of the first function you have called (not the current function). So, if you call function A, which calls function B, the “auth” modifier of function B checks if you are authorized for function A!

There is a difference between external and public functions. For external functions, this works as expected because a fresh call (with a new msg.sig) is always made. However, with public functions called from within the same contract, this doesn’t happen as the problem described above occurs.

See the issue page for proof of concept, which shows the problem. In the code, several functions have public and auth combined; see also in the proof of concept.

In the current codebase, I couldn’t find a problem situation; however, this could be accidentally introduced with future changes. It could also be introduced via the _moduleCall of Ladle.sol, which allows functions to be defined which might call the public functions.

See issue #4 page for proof of concept and a list of occurrences of public auth.

Recommend making sure all auth functions use external (still error-prone) Or, recommend changing the modifier to something like:

modifier auth(bytes4 fs) {
require (msg.sig == fs,"Wrong selector");
require (_hasRole(msg.sig, msg.sender), "Access denied");
_;
}
function setFee(uint256) public auth(this.setFee.selector) {
   .....
}

albertocuestacanada (Yield) confirmed:

While many governance functions have been marked public instead of external throughout the code, they are never called from any other function in the same contract, and they should never be.

In all contracts of the protocol, auth functions are only called by other contracts or by EOAs, with the latter being governance actions.

The suggestion of changing all public auth functions to external auth will be applied; however, no changes will be made to AccessControl.sol, and the suggested severity is 1.

The original report as published on Code4rena. 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

The auth modifier relies on msg.sig, which does not update for internal calls to public functions, so it checks the wrong function selector.

Impact

The text states that no problem situation was found in the current codebase, but the issue could be accidentally introduced with future changes or via the _moduleCall of Ladle.sol, potentially allowing unauthorised access to auth-protected public functions.

What the attacker needed

A public function with auth modifier; that function is called internally

The fix

The suggestion to change all public auth functions to external auth will be applied, but no changes will be made to AccessControl.sol.

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 smart contracts, a modifier is a check that runs before a function. The auth modifier is supposed to ensure only authorised users can call certain functions. However, it uses msg.sig, which is the identifier of the first function called in a transaction. If a public function with auth is called from another function in the same contract, msg.sig still points to the first function, so the check may pass incorrectly.

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 Yield Witch v2 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.