Skip to content

feat: add canister-security skill#58

Open
marc0olo wants to merge 6 commits intomainfrom
marc0olo/add-canister-security-skill
Open

feat: add canister-security skill#58
marc0olo wants to merge 6 commits intomainfrom
marc0olo/add-canister-security-skill

Conversation

@marc0olo
Copy link
Member

@marc0olo marc0olo commented Mar 2, 2026

Summary

  • Adds canister-security skill covering 12 IC-specific security pitfalls with links to official DFINITY security best practices
  • Complete Motoko (core 2.0) and Rust (ic-cdk 0.19) implementations for access control, saga pattern, and inspect_message
  • Adds @dfinity/security as CODEOWNER for skills/canister-security/
  • Adds cross-referencing guidance to CONTRIBUTING.md — domain skills should reference canister-security rather than inlining general security patterns

Relationship to #57: Complementary. #57 adds multi-canister-specific security content (reentrancy in factory patterns, production readiness). This skill covers general IC security fundamentals that apply to all canisters. Both should coexist.

marc0olo added 2 commits March 2, 2026 17:42
Covers IC-specific security patterns: access control, anonymous
principal rejection, TOCTOU/reentrancy, pre_upgrade traps, cycles
monitoring, controller backup, fetchRootKey risks, admin guards,
secret storage, storage exhaustion, callback trap inconsistency,
and unbounded wait calls. Both Motoko and Rust implementations.

Reviewed against IC interface specification, DFINITY security best
practices, and recent audit findings. Adds @dfinity/security as
CODEOWNER.

Based on the draft from #51, with corrections:
- inspect_message: specify boundary node bypass, not generic node
- freezing_threshold: default is already 30 days, canister is
  uninstalled not deleted
- fetchRootKey: not deprecated, required for local dev
- Added pitfalls: pre_upgrade trap, storage exhaustion, callback
  trap after state mutation, unbounded wait calls
- Links to official security best practices documentation
- Rust: caller() -> msg_caller(), api::call::{accept_message, method_name}
  -> api::{accept_message, msg_method_name} (removed in ic-cdk 0.19)
- Motoko: Array.append -> Array.concat (renamed in base->core migration)
- Add missing Error import note to saga pattern
- Remove deploy boilerplate, consolidate into Verify It Works
- Add cross-referencing guidance to CONTRIBUTING.md
Copy link
Member

@venkkatesh-sekar venkkatesh-sekar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marc0olo I took a first pass and left feedback. But the security team is also doing some parallel work here https://github.com/dfinity-lab/security-skills, so maybe we can unify the effort.

@marc0olo
Copy link
Member Author

marc0olo commented Mar 3, 2026

@marc0olo I took a first pass and left feedback. But the security team is also doing some parallel work here https://github.com/dfinity-lab/security-skills, so maybe we can unify the effort.

@venkkatesh-sekar thanks a lot. I didn't know about the effort of the security team. I think unifying the overall effort would be good. what I definitely like in your repo is the test harness. ideally we would have evaluations for all skills to ensure their effectiveness. this is currently completely missing on this repo.

I am wondering about the best approach to unify and whether it makes sense to have this proposed skill here in the repo.

did you have the chance to read #52 and follow-up comments? do you have any suggestion / recommendation how to structure our skills and how to incorporate your security skills?

@marc0olo
Copy link
Member Author

marc0olo commented Mar 3, 2026

Thanks for the thorough review @venkkatesh-sekar — all 9 comments are addressed in the latest push.

Regarding unification with dfinity-lab/security-skills: I recommend keeping the repos separate because they serve different personas.

  • This repo (icskills) → developer writing code. The canister-security skill triggers alongside domain skills (e.g., multi-canister, icrc-ledger) and gives the agent correct security patterns proactively — the developer didn't ask for security, but the agent applies it anyway.
  • security-skills → auditor reviewing code. Granular skills (inter-canister-calls, identity-management, etc.) with severity ratings and the security-assessor methodology for systematic vulnerability detection.

A single broad canister-security skill works better for the developer persona than loading the right combination of 11 granular audit-oriented skills. And security-skills stays optimized for auditing with no compromises.

Ideally the security team co-owns canister-security here (CODEOWNER for skills/canister-security/) since the content draws from their expertise. The security-skills repo's test harness is also something we should adopt for all skills independently (see #52).

Address all 9 review comments from venkkatesh-sekar:
- Use persistent actor instead of stable keyword (Motoko)
- Add init() method with race-window warning
- Add removeAdmin for admin revocation
- Rewrite Rust access control to use CDK guard pattern
- Move compensation into finally/Drop cleanup context
- Add call_on_cleanup mention for callback traps
- Use replica-signed queries terminology

Additional improvements:
- Rewrite description and intro for agent consumption
- Remove external links (agents cannot follow URLs)
- Replace How It Works point 4 with state-rollback-on-trap
- Add CallerGuard (per-caller locking) for both languages
- Add CompensationGuard with Drop for trap-safe rollback
- Use Call::bounded_wait with correct ic-cdk 0.19 API
- Remove Verify It Works section (not actionable by agents)
- Add placeholder comments for application-specific functions
@venkkatesh-sekar
Copy link
Member

@marc0olo is this freshly generated? I see a lot of differences from the previous review and it would be difficult for me do a full re review again.

@marc0olo
Copy link
Member Author

marc0olo commented Mar 4, 2026

@venkkatesh-sekar it looks like a complete rewrite, but it's not. however, I provided some additional changes/removals which were independent of your review.

I am not sure if a full re-review is needed, but I think it would be good.

And sorry for applying additional changes in this PR. Would have been better to come up with a follow-up PR.

Changes targeting your review:

  • persistent actor instead of stable keyword
  • Added init() with race-window warning
  • Added removeAdmin for admin revocation
  • Rewrote Rust access control to use CDK guard pattern
  • Compensation in cleanup context (try/finally / Drop)
    • Added CompensationGuard with Drop for trap-safe rollback (Rust) / try/finally compensation (Motoko)
  • Added call_on_cleanup mention for callback traps
  • Replica-signed queries terminology

Additional changes:

  • Added CallerGuard pattern (per-caller reentrancy lock) for both Motoko and Rust
  • Using Call::bounded_wait (ic-cdk 0.19 API) instead of raw inter-canister call
  • Replaced "How It Works" point 4 (was canister_inspect_message) with state-rollback-on-trap explanation
    • The canister_inspect_message is already mentioned elsewhere in the skill, so this was duplicate information for an agent.
  • Removed external links
  • Rewrote skill description and intro for agent consumption
  • Removed "Verify It Works" section
  • Replaced SNS recommendation with agent-actionable backup controller advice

Keep both canister-security (new) and wallet-integration (renamed from
oisy-wallet-signer on main).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants