canister-security

Implement IC-specific security patterns for Motoko and Rust canisters.

28|11|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/dfinity/icskills --skill canister-security
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: canister-security
Source: https://github.com/dfinity/icskills/tree/main/skills/canister-security
Command: npx skills add https://github.com/dfinity/icskills --skill canister-security

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses critical security vulnerabilities inherent in Internet Computer (IC) canister development, preventing common exploits and ensuring robust application security.

Core Features & Use Cases

  • Access Control: Implement secure authentication and authorization for canister methods.
  • Reentrancy Prevention: Protect against TOCTOU vulnerabilities using the CallerGuard pattern.
  • Async Safety: Ensure state integrity during inter-canister calls with patterns like saga.
  • Upgrade Safety: Prevent non-upgradeable canisters due to pre_upgrade traps.
  • Cycle Management: Protect against cycle drains and ensure canister longevity.
  • Use Case: When developing a decentralized finance (DeFi) application on the IC, use these patterns to secure token transfers, prevent reentrancy attacks, and ensure safe upgrades during maintenance.

Quick Start

Secure your Motoko canister by implementing the requireOwner guard for sensitive admin actions.

Frequently Asked Questions about canister-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent reentrancy attacks in IC canisters?

Prevent reentrancy attacks in IC canisters using the CallerGuard pattern, which protects against TOCTOU vulnerabilities by validating caller state before modifying canister data or handling token transfers.

How do I secure access control and reject anonymous principals in Motoko?

Secure access control and reject anonymous principals in Motoko by implementing the requireOwner guard for sensitive admin actions, ensuring only authorized callers can modify canister state or execute restricted methods.

What's the best way to ensure state integrity during async inter-canister calls?

Ensure state integrity during async inter-canister calls by applying saga patterns, which maintain consistent canister state and safely handle callback traps when making asynchronous cross-canister requests.

Why do IC canisters become non-upgradeable after a pre_upgrade trap?

IC canisters become non-upgradeable after a pre_upgrade trap because the trap prevents saving state before the upgrade, requiring safe upgrade patterns to ensure pre_upgrade hooks execute without failing.

How do I protect my IC canister from cycle drain attacks?

Protect IC canisters from cycle drain attacks using cycle management patterns that monitor consumption and restrict unauthorized inter-canister calls, ensuring canister longevity and preventing malicious resource exhaustion.

Can I use these security patterns for both Rust and Motoko canisters?

These IC-specific security patterns support both Rust and Motoko canister development, providing access control, reentrancy prevention, and safe upgrade implementations for any canister modifying state or handling tokens.