dfinity avatar

Canister Security

If you're writing Internet Computer canisters, this covers the security patterns that aren't obvious from Web2 backend development. The async messaging model creates TOCTOU vulnerabilities between await calls, canister_inspect_message isn't a real security boundary, and the anonymous principal is a shared identity anyone can use. You get copy-paste patterns for CallerGuard (reentrancy prevention), saga pattern (async safety), and upgrade traps that brick canisters. The pitfalls section is dense but accurate, especially on callback traps after state mutation and the fact that a malicious replica can skip inspect_message entirely. Covers both Motoko and Rust. Read the pitfalls first, then use the patterns when you hit them.

skills.sh installs
324
GitHub stars
39
last updated
Aug 21, 2026

Install

$ npx -y skills add dfinity/icskills --skill canister-security --agent claude-code

Installs into .claude/skills of the current project.

Files

Canister Security

What This Is

Security patterns for IC canisters in Motoko and Rust. The async messaging model creates TOCTOU (time-of-check-time-of-use) vulnerabilities where state changes between await calls. canister_inspect_message is NOT a reliable security boundary. Anyone on the internet can burn your cycles by sending update calls. This skill provides copy-paste correct patterns for access control, reentrancy prevention, async safety, and callback trap handling.

Prerequisites

  • For Motoko: mops package manager, core = "2.0.0" in mops.toml
  • For Rust: ic-cdk = "0.19", candid = "0.10"

Security Pitfalls

  1. Relying on canister_inspect_message for access control. This hook runs on a single replica without full consensus. If that replica is malicious, it can simply skip the check and execute the update call without any message inspection. It is also never called for inter-canister calls, query calls, or management canister calls. Always duplicate access checks inside every update method. Use inspect_message only as a cycle-saving optimization, never as a security boundary.

Sponsors

Details

Repository
github.com/dfinity/icskills
Categories
Security, Documentation, Rust
First seen
Jun 3, 2026

More from dfinity/icskills

All 16

Recommended

More Security
1sickn33 avatarsecurity-scanning-security-dependenciessickn33/antigravity-awesome-skillssecurity scanning security dependencies311skills.sh installs
2cinience avataralicloud-security-kms-testcinience/alicloud-skillsMinimal smoke test for KMS skill. Validate auth and read-only key listing path.295skills.sh installs
3cinience avataralicloud-security-center-sas-testcinience/alicloud-skillsMinimal smoke test for Security Center SAS skill. Validate read-only query flow.293skills.sh installs
4cinience avataralicloud-security-cloudfw-testcinience/alicloud-skillsMinimal smoke test for Cloud Firewall skill. Validate read-only inventory query path.293skills.sh installs
5sickn33 avatarsecurity-compliance-compliance-checksickn33/antigravity-awesome-skillssecurity compliance compliance check292skills.sh installs
6cinience avataralicloud-security-content-moderation-greencinience/alicloud-skillsManage Alibaba Cloud Content Moderation (Green) via OpenAPI/SDK. Use whenever the user needs content moderation resource and policy operations, including list/c273skills.sh installs