codeguard
A CodeGuard security skill that helps AI coding agents write secure code and prevent common vulnerabilities. Use this skill when writing, reviewing, or…
Guide secure migration of code from memory-unsafe languages (C, C++, Assembly) to memory-safe languages (Rust, Go, Java, C#, Swift). Use when migrating or rewriting legacy C/C++ code, designing FFI boundaries between safe and unsafe code, writing new modules in existing C/C++
$ npx -y skills add cosai-oasis/project-codeguard --skill memory-safe-migration --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/memory-safe-migrationContext preview
The summary Claude sees to decide when to auto-load this skill.
Guide secure migration of code from memory-unsafe languages (C, C++, Assembly) to memory-safe languages (Rust, Go, Java, C#, Swift). Use when migrating or rewriting legacy C/C++ code, designing FFI boundaries between safe and unsafe code, writing new modules in existing C/C++
name: memory-safe-migration description: >- Guide secure migration of code from memory-unsafe languages (C, C++, Assembly) to memory-safe languages (Rust, Go, Java, C#, Swift). Use when migrating or rewriting legacy C/C++ code, designing FFI boundaries between safe and unsafe code, writing new modules in existing C/C++ codebases, reviewing mixed-language projects, planning memory safety roadmaps, or when an AI agent is about to generate new C/C++ code that could be written in a memory-safe language instead. Also triggers on CISA/NSA memory safety compliance discussions. license: CC-BY-4.0 metadata: author: codeguard-community version: "1.0" category: memory-safety
Before writing any new code, ask:
1. Is there an explicit constraint requiring C/C++? (bare-metal with no MSL runtime, hard real-time below 1μs, existing codebase policy) 2. If no constraint exists, default to a memory-safe language 3. Select the target language using the guide in [references/language-selection.md](references/language-selection.md)
If the project is predominantly C/C++, write the new module in an MSL and integrate via FFI. See [references/ffi-security.md](references/ffi-security.md) for boundary rules.
Follow these steps for every migration task:
Run the assessment script to evaluate migration priority and feasibility:
python scripts/assess-migration.py --file <source_file>
Or manually evaluate using the checklist in [references/assessment-checklist.md](references/assessment-checklist.md).
Priority order for migration: 1. Network-facing code (parsers, protocol handlers, TLS) 2. Code handling untrusted input (file parsers, deserialization) 3. Cryptographic implementations 4. Privilege boundary code (auth enforcement) 5. Code with a history of memory-related CVEs 6. Internal utility code
Never migrate a component without test coverage. If no tests exist, write them against the C/C++ implementation before touching anything. These tests become the correctness oracle for the new implementation.
One function or module at a time. Never rewrite an entire codebase in one pass. Follow the Android model: new code in MSL, existing stable code stays in place, proportion of unsafe code decreases over time.
For common migration patterns (buffers, strings, concurrency, error handling), see [references/migration-patterns.md](references/migration-patterns.md).
Every interface between safe and unsafe code is a security boundary. Follow all rules in [references/ffi-security.md](references/ffi-security.md). Key rules:
After every migration unit, verify:
Never do these during migration:
wrapper just passes through without validation, it provides false confidence
is needed, the approach should be redesigned or the code should remain in C
Go uses multiple returns. Every error path must be explicitly mapped
but can still leak file handles, sockets, and connections. Use `defer`, `try-with-resources`, `using`, or `with` patterns
For detailed guidance on specific topics:
This repository is for the work of the Coalition for Secure AI (CoSAI). CoSAI is an OASIS Open Project and an open ecosystem of AI and security experts from industry-leading organizations.
A CodeGuard security skill that helps AI coding agents write secure code and prevent common vulnerabilities. Use this skill when writing, reviewing, or…
Comprehensive security code review workflow for a target repository, producing a markdown report with findings and recommendations.