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★ 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-iccrate (e.g.16.1). WithPOCKET_IC_BINunset,PocketIc::new()downloads the matching server release fromdfinity/pocketicon first use. To pin a binary you have verified (sha256) instead, pointPOCKET_IC_BINat it; the server's major version must match the crate's.
The audit workflow
- Detect the canister. Confirm it is a Rust ic-cdk canister: a
Cargo.tomldepending onic-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. - 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. Fortoken_vaultthe invariant issum(balances) <= total_deposited. - 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 = ...),asyncor not — with no caller check (is_controller, an owner check, or a== Principal::anonymous()rejection).CallerGuardis a reentrancy lock, not a caller check: it admits the anonymous principal; fetch_root_key/fetchRootKey/shouldFetchRootKeyanywhere in the repo, including calls behind an environment check (canister-securitypitfall #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 theic_envcookie (IC_ROOT_KEY, viasafeGetCanisterEnv()) asrootKeytoHttpAgent.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 ofmsg_caller(); legacy call sites often predate the current guard conventions. A deliberately high-recall rule flagsdeposit,withdraw, andclaim_bonushere, even thoughdepositrejects the anonymous principal andwithdrawtakes aCallerGuard- 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
- state-changing update fns —
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- 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), без исполняемых скриптов.
Похожие скиллы
docx
AnthropicUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
xlsx
AnthropicUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
pptx
AnthropicUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…