Skip to content

Latest commit

 

History

History
91 lines (65 loc) · 3.17 KB

S001.md

File metadata and controls

91 lines (65 loc) · 3.17 KB

S001 — Missing Authorization Guard

  • Category: authentication
  • Severity: Critical
  • Rule name: auth_gap

What it detects

S001 flags any public function inside an impl block that performs a privileged operation without first calling require_auth() or require_auth_for_args(). Privileged operations are:

  • Storage mutation — .set(), .update(), .remove(), or .extend_ttl() on storage().persistent(), temporary(), or instance().
  • External contract call — .invoke_contract(), or a method call on a receiver whose type name ends in Client / _client.

Reserved Soroban entry-points (__constructor, __check_auth) are excluded automatically. Private (fn) functions and functions outside impl blocks are not checked.

Why it matters

A public function that writes state or calls external contracts without checking the caller's identity can be invoked by anyone — draining balances, replacing the admin, or triggering arbitrary cross-contract logic. This is one of the most common critical findings in Soroban audits: if require_auth is missing, anyone can drain your contract.

Vulnerable example

#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env};

#[contracttype]
pub enum DataKey {
    Admin,
}

#[contract]
pub struct Token;

#[contractimpl]
impl Token {
    // S001: anyone can replace the admin — no auth guard.
    pub fn set_admin(env: Env, new_admin: Address) {
        env.storage().instance().set(&DataKey::Admin, &new_admin);
    }
}

Safe example

#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env};

#[contracttype]
pub enum DataKey {
    Admin,
}

#[contract]
pub struct Token;

#[contractimpl]
impl Token {
    pub fn set_admin(env: Env, new_admin: Address) {
        // Guard added: the current admin must authorize the change.
        let admin: Address = env.storage().instance().get(&DataKey::Admin).unwrap();
        admin.require_auth();
        env.storage().instance().set(&DataKey::Admin, &new_admin);
    }
}

CVSS-style risk rating

  • Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
  • Base score: 9.8
  • Rating: Critical

An unauthenticated network attacker can fully compromise integrity and availability (and confidentiality of controlled assets) with a single low-complexity transaction.

How to fix

  1. Call addr.require_auth() (or addr.require_auth_for_args(...)) as the first statement in every state-mutating or external-call public function.
  2. Authorize the correct principal — typically the current admin for privileged operations, or the from address for value transfers.
  3. Consider whether read-only functions that expose sensitive data also need authentication.
  4. Re-run sanctifier to confirm the finding clears.

Related rules

Related rules: S010, S012

References