Command Palette

Search for a command to run...

Назад к скиллам
скилл № 32422

canister-audit

Audit an existing Internet Computer Rust canister (ic-cdk) for security flaws and PROVE a confirmed one with a PocketIC reproduction. Covers detecting the…

БесплатноБез исполняемых скриптов
jiayaoqijiaот jiayaoqijia★ 81 звезда на GitHub

Установить canister-audit в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Canister Audit

What This Is

A workflow for auditing a Rust ic-cdk canister you did not write, and for turning a suspected flaw into a proven one. canister-security teaches the patterns a canister should follow; this skill is the other side of that coin - given existing code, find where those patterns are violated, and prove the highest-severity finding by reproducing the exploit in PocketIC. A grep hit or a hunch is a candidate; a PocketIC test that drives the deployed wasm and crosses the security boundary is evidence.

The worked example throughout is a deliberately-broken ledger canister, token_vault, whose accounting invariant sum(balances) <= total_deposited is broken by exactly one unguarded method.

Prerequisites

  • Rust toolchain + the wasm target: rustup target add wasm32-unknown-unknown.
  • Optional static tools: cargo-audit (RustSec dependency CVEs) and Semgrep (a coarse first pass; Rust support is experimental, so treat it as high-recall).
  • For the proof step: the pocket-ic crate (e.g. 16.1). With POCKET_IC_BIN unset, PocketIc::new() downloads the matching server release from dfinity/pocketic on first use. To pin a binary you have verified (sha256) instead, point POCKET_IC_BIN at it; the server's major version must match the crate's.

The audit workflow

  1. Detect the canister. Confirm it is a Rust ic-cdk canister: a Cargo.toml depending on ic-cdk/candid, #[ic_cdk::update]/#[ic_cdk::query] entrypoints, a .did. A canister's logic is not recoverable from its deployed wasm, so you need the source - there is no audit-by-mainnet-address mode.
  2. Model the invariants first. Before reading for bugs, write down what must always hold: the accounting identity, who may call what, which state moves across each await. The audit then hunts for a path that breaks each invariant. For token_vault the invariant is sum(balances) <= total_deposited.
  3. Static first pass (high-recall, best-effort). Grep or Semgrep for the obvious footguns, treating every hit as a candidate to confirm, never an automatic finding:
    • state-changing update fns — #[update], #[ic_cdk::update], with or without arguments (guard = ..., name = ...), async or not — with no caller check (is_controller, an owner check, or a == Principal::anonymous() rejection). CallerGuard is a reentrancy lock, not a caller check: it admits the anonymous principal;
    • fetch_root_key / fetchRootKey / shouldFetchRootKey anywhere in the repo, including calls behind an environment check (canister-security pitfall #7 forbids it even there — environment branches leak into production builds); only test-only code is exempt. The fix to recommend is removing the call and passing the root key from the ic_env cookie (IC_ROOT_KEY, via safeGetCanisterEnv()) as rootKey to HttpAgent.create();
    • let _ = CallerGuard::new(...) - a guard bound to _ is dropped at the end of the statement, so the lock is released immediately;
    • ic_cdk::caller() - deprecated in favour of msg_caller(); legacy call sites often predate the current guard conventions. A deliberately high-recall rule flags deposit, withdraw, and claim_bonus here, even though deposit rejects the anonymous principal and withdraw takes a CallerGuard - the point is to surface candidates for review, not to decide. Example Semgrep rule (tested with Semgrep 1.185):
    rules:
      - id: ic-update-missing-caller-auth
        message: update method with no visible caller check - candidate for review
        languages: [rust]
        severity: ERROR
        patterns:
          # Every update entrypoint: bare or parameterized attribute, sync or async.
          - pattern-either:
              - pattern: |
                  #[$ATTR]
                  fn $F(...) { ... }
              - pattern: |
                  #[$ATTR]
                  fn $F(...) -> $R { ... }
              - pattern: |
                  #[$ATTR]
                  async fn $F(...) { ... }
              - pattern: |
                  #[$ATTR]
                  async fn $F(...) -> $R { ... }
              - pattern: |
                  #[$ATTR(...)]
                  fn $F(...) { ... }
              - pattern: |
                  #[$ATTR(...)]
                  fn $F(...) -> $R { ... }
              - pattern: |
                  #[$ATTR(...)]
                  async fn $F(...) { ... }
              - pattern: |
                  #[$ATTR(...)]
                  async fn $F(...) -> $R { ... }
          - metavariable-regex:
              metavariable: $ATTR
              regex: ^(ic_cdk::)?update$
          # A bare `== Principal::anonymous()` is deliberately NOT a suppressor (a
          # comparison that does not reject the caller is not a guard), and neither
          # is CallerGuard (a reentrancy lock). Under-reporting is worse than noise.
          - pattern-not-regex: (is_controller|require_owner|require_admin)
    

    The suppression is

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • LICENSE
  • SOURCE.md
  • TRUST.auto.yaml

FAQ

Что делает скилл canister-audit?

Audit an existing Internet Computer Rust canister (ic-cdk) for security flaws and PROVE a confirmed one with a PocketIC reproduction. Covers detecting the canister, a high-recall static first pass, a systematic review against the canister-security pitfalls, and the distinctive step: building the canister to wasm and executing the exploit in PocketIC to turn a suspected flaw into a demonstrated one. Use when reviewing or auditing a canister you did NOT write, or proving a finding before you report it. Complements canister-security (which teaches the secure patterns); this one finds and proves violations of them.

Как установить скилл canister-audit?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл canister-audit запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить canister-audit с