Skip to content
Access control Audit finding Beginner

set_invocation_costs_config() fails to authorize admin allowing anyone to set invocation costs

The set_invocation_costs_config function in the beam contract does not check that the caller is an admin, so any user can change the invocation costs. An attacker could set these costs to an extremely high value, causing price consumers to lose funds through excessive fees.

YouCrossTheLineAlfie Follow with 0x_kmr_, 0xbrett8571 and 48 others

Originally disclosed on Code4rena

Submitted by YouCrossTheLineAlfie, also found by 0x_kmr_, 0xbrett8571, 0xgeeee, 0xkrodhan, 0xnija, 0xpetern, 0xshdax, 0xsolisec, 0xvd, AllTooWell, Almanax, ameng, Angry_Mustache_Man, arturtoros, aster, august1_, axelot, Bale, BioMatriX, cd_pandora, ChainSentry, CoMMaNDO, CowBoy, Dest1ny_rs, djshan_eden, dmdg321, edoscoba, escrow, eta, felconsec, foxb868, fullstop, Ganesh_197, HalalAudits, hecker_trieu_tien, holtzzx, ht111111, HUNTERRRRRRR, hyp3rion123, inh3l, jerry0422, Jesse, johnyfwesh, Josh4324, jsmaxi, JustUzair, K42, kimnoic, Kirkeelee, kjc, klau5, kwad, l3gb, luckygru, lufP, Mahmud, Manosh19, markoliver, marsspaceX, mbuba666, merlin, merlin_san, Mhayatt, mrdafidi, Mrunal2610, Mylifechangefast_eth, nathan47, NexusAudits, niffylord, NovaTheMachine, OhmOudits, oxwhite, piki, pv, rare_one, rhaloh_ke, rubencrxz, shaflow2, SiddiqX786, sl1, slavina, slvDev, swordfish, teoslaf, th3_hybrid, TheCarrot, touristS, trilobyteS, unique, Wojack, y4y, yixuan, zcai, zubyoz, and zzkiel

lib.rs #L404

Finding description and impact

The set_invocation_costs_config() function in beam-contract/lib.rs is designed to allow the admin to set invocation costs which is charged when prices are read by the consumer:

    // Update costs configuration per each invocation category
    // Requires admin authorization
    //
    // # Arguments
    //
    // * `config` - Invocation costs for different invocation categories
    //
    // # Panics
    //
    // Panics if not authorized or not initialized yet
    pub fn set_invocation_costs_config(e: &Env, config: Vec<u64>) {
        set_costs_config(e, &config);
    }

However, this function fails to verify if the caller is admin; allowing anyone to set invocation costs.

This leads to unwarranted loss of funds to the price consumers as their tokens would get burnt as per invocation fee, which can be changed to a irrationally high number by a malicious actor.

Recommended mitigation steps

It is recommended to add a auth::panic_if_not_admin(e); check in order to mitigate this issue.

Proof of Concept

Add the following test case inside beam-contract/src/test.rs:

#[test]
fn anyone_can_set_invocation_config_test() {
    let (env, client, _) = init_contract_with_admin();

    env.mock_all_auths();

    let costs = Vec::from_array(&env, [10, 20, 30, 40, 50]);
    client.set_invocation_costs_config(&costs);

    let result = client.invocation_costs();
    assert_eq!(result, costs);
}

The original report as published on Code4rena, by YouCrossTheLineAlfie. 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 function set_invocation_costs_config calls set_costs_config without verifying that the caller is the admin.

Impact

Anyone can set invocation costs to an irrationally high number, causing price consumers to lose funds as their tokens are burnt as invocation fees.

What the attacker needed

None

The fix

Add an admin authorisation check, such as auth::panic_if_not_admin(e), inside set_invocation_costs_config.

How it was found

  1. Deploy the contract and initialise it with an admin.
  2. Call set_invocation_costs_config with a new list of costs.
  3. Read invocation_costs and observe that the new costs were accepted.

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 a smart contract, some functions should only be callable by the administrator. Here, a function that sets the fees charged when prices are read lacks that check. Anyone can call it and set the fees to a huge number, so people using the service lose money.

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 YouCrossTheLineAlfie

View all

10 more disclosed reports, best first.

More from Reflector V3

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.