
codeguard-security
Comprehensive security rules for AI coding agents
- version
- 1.5.0
- GitHub stars
- 374
Install
/plugin install codeguard-security@project-codeguardRun it inside Claude Code after adding the marketplace with /plugin marketplace add cosai-oasis/project-codeguard.
Contents
Discovered from sourceSkills 3
CodeGuard Skill
This skill provides comprehensive security guidance to help AI coding agents generate secure code and prevent common vulnerabilities. It is based on Project CodeGuard, an open-source, model-agnostic security framework that embeds secure-by-default practices into AI coding workflows.
When to Use This Skill
This skill should be activated when:
- Writing new code in any language
- Reviewing or modifying existing code
- Implementing security-sensitive features (authentication, cryptography, data handling, etc.)
- Working with user input, databases, APIs, or external services
- Configuring cloud infrastructure, CI/CD pipelines, or containers
- Handling sensitive data, credentials, or cryptographic operations
How to Use This Skill
When writing or reviewing code:
- Always-Apply Rules: Some rules MUST be checked on every code operation:
codeguard-1-hardcoded-credentials.md- Never hardcode secrets, passwords, API keys, or tokenscodeguard-1-crypto-algorithms.md- Use only modern, secure cryptographic algorithmscodeguard-1-digital-certificates.md- Validate and manage digital certificates securely
- Tag-Based Rules: When you identify any of these security contexts in the code, apply ALL rules with the matching tag:
| Security Context (Tag) | Rule Files to Apply |
|---|---|
| authentication | codeguard-0-authentication-mfa.md, codeguard-0-session-management-and-cookies.md |
| data-security | codeguard-0-additional-cryptography.md, codeguard-0-data-storage.md |
| infrastructure | codeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md |
| privacy | codeguard-0-logging.md, codeguard-0-privacy-data-protection.md |
| secrets | codeguard-0-additional-cryptography.md, codeguard-1-digital-certificates.md, codeguard-1-hardcoded-credentials.md |
| web | codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-client-side-web-security.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md |
- Language-Specific Rules: Apply rules from /rules directory based on the programming language of the feature being implemented using the table given below:
| Language | Rule Files to Apply |
|---|---|
| apex | codeguard-0-input-validation-injection.md |
| c | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-data-storage.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-safe-c-functions.md, codeguard-0-xml-and-serialization.md |
| cpp | codeguard-0-safe-c-functions.md |
| docker | codeguard-0-devops-ci-cd-containers.md, codeguard-0-supply-chain-security.md |
| go | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
| hcl | codeguard-0-iac-security.md |
| html | codeguard-0-client-side-web-security.md, codeguard-0-input-validation-injection.md |
| java | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-mobile-apps.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
| javascript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-mcp-security.md, codeguard-0-mobile-apps.md, codeguard-0-privacy-data-protection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-supply-chain-security.md |
| kotlin | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md |
| php | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
| powershell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
| python | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
| ruby | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
| rust | codeguard-0-mcp-security.md |
| shell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
| sql | codeguard-0-data-storage.md, codeguard-0-input-validation-injection.md |
| swift | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md |
| typescript | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-authentication-mfa.md, codeguard-0-authorization-access-control.md, codeguard-0-client-side-web-security.md, codeguard-0-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-input-validation-injection.md, codeguard-0-mcp-security.md, codeguard-0-session-management-and-cookies.md |
| xml | codeguard-0-api-web-services.md, codeguard-0-mobile-apps.md, codeguard-0-xml-and-serialization.md |
| yaml | codeguard-0-authorization-access-control.md, codeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-supply-chain-security.md |
- Proactive Security: Don't just avoid vulnerabilities-actively implement secure patterns:
- Use parameterized queries for database access
- Validate and sanitize all user input
- Apply least-privilege principles
- Use modern cryptographic algorithms and libraries
- Implement defense-in-depth strategies
CodeGuard Security Rules
The security rules are available in the rules/ directory.
Usage Workflow
When generating or reviewing code, follow this workflow:
1. Initial Security Check
Before writing any code:
- Check: Will this handle credentials? → Apply codeguard-1-hardcoded-credentials
- Check: What security tags apply? → Load all rules with matching tags (e.g., "authentication", "web", "secrets")
- Check: What language am I using? → Identify applicable language-specific rules
2. Code Generation
While writing code:
- Apply secure-by-default patterns from relevant Project CodeGuard rules
- Add security-relevant comments explaining choices
3. Security Review
After writing code:
- Review against implementation checklists in each rule
- Verify no hardcoded credentials or secrets
- Validate that all the rules have been successfully followed when applicable.
- Explain which security rules were applied
- Highlight security features implemented
Memory-safe language migration
When this skill activates
- User asks to migrate, port, or rewrite C/C++ code to Rust, Go, Java, C#, or Swift
- User asks to add a new module or feature to an existing C/C++ project
- User asks to design an FFI boundary between safe and unsafe code
- User asks about memory safety roadmaps or CISA/NSA compliance
- User asks to review mixed-language code for safety issues
- AI agent is about to generate new C/C++ code — check if an MSL alternative is viable
Decision: new code language selection
Before writing any new code, ask:
- Is there an explicit constraint requiring C/C++? (bare-metal with no MSL runtime, hard real-time below 1μs, existing codebase policy)
- If no constraint exists, default to a memory-safe language
- Select the target language using the guide in 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 for boundary rules.
Migration workflow
Follow these steps for every migration task:
Step 1: Assess the component
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.
Priority order for migration:
- Network-facing code (parsers, protocol handlers, TLS)
- Code handling untrusted input (file parsers, deserialization)
- Cryptographic implementations
- Privilege boundary code (auth enforcement)
- Code with a history of memory-related CVEs
- Internal utility code
Step 2: Write tests first
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.
Step 3: Migrate incrementally
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.
Step 4: Secure the FFI boundary
Every interface between safe and unsafe code is a security boundary. Follow all rules in references/ffi-security.md. Key rules:
- Validate all inputs from the unsafe side (null checks, bounds checks, type checks)
- Minimize
unsafeblocks — wrap only the minimum necessary operation - Document every
unsafeblock with a// SAFETY:comment - The allocator that created memory must free it — never mix allocators
- Never panic across FFI boundaries
- Catch all panics with
std::panic::catch_unwindat FFI entry points
Step 5: Validate
After every migration unit, verify:
- All existing tests pass against the new implementation
- No new
unsafesurface without documented safety invariants - FFI boundaries fuzzed with malformed inputs, null pointers, extreme lengths
- Memory safety tools run clean (Miri for Rust, race detector for Go, ASan for C side)
- Performance benchmarked against the original — no unacceptable regression
- All new MSL dependencies audited for trustworthiness and active maintenance
Step 6: Update build and CI
- Integrate the MSL toolchain (cargo, go build, etc.) into the existing build system
- Add MSL-specific linting (
clippyfor Rust,go vetfor Go) - Add formatting checks (
rustfmt,gofmt) - Add safety-specific CI checks (deny
unsafewithout annotation, dependency audit)
Anti-patterns to prevent
Never do these during migration:
- Wrapping unsafe C in a "safe" API without actual safety guarantees — if the wrapper just passes through without validation, it provides false confidence
- Using
unsafeto replicate C-style patterns in Rust — if extensiveunsafeis needed, the approach should be redesigned or the code should remain in C - Migrating without tests — write tests for C/C++ first, then validate MSL version
- Ignoring error handling differences — C uses return codes, Rust uses
Result, Go uses multiple returns. Every error path must be explicitly mapped - Assuming GC languages need no resource discipline — they prevent memory corruption
but can still leak file handles, sockets, and connections. Use
defer,try-with-resources,using, orwithpatterns - Migrating performance-critical loops without benchmarking — verify first
References
For detailed guidance on specific topics:
Security Review
When to use
- Use for a full codebase security review with prioritized findings, remediation guidance, and a formal report.
Inputs
- Target repository path (first argument after invocation).
- Example:
$security-review /path/to/repo
- Example:
- Security knowledge base source:
- Rules are sourced from Project CodeGuard, an open-source, model-agnostic security framework by CoSAI/OASIS.
If the repo path is missing or unclear, ask the user for it before proceeding.
Workflow
-
Load the security knowledge base from Project CodeGuard
-
First read the
Security_Code_Reviewer_Guidelines.mdfile bundled with this skill. Use its purpose and rule-loading strategy to guide the review. -
Load all core security rules from Project CodeGuard:
https://github.com/cosai-oasis/project-codeguard/tree/main/skills/codeguard/rulesThese are mandatory foundational rules that must be loaded for every review.
-
Load relevant OWASP rules for the detected tech stack from:
https://github.com/cosai-oasis/project-codeguard/tree/main/sources/rules/owaspOnly load OWASP rules that match the target repository's technology stack.
-
-
Perform deep code analysis
- Review the repository line by line.
- Focus on: injection flaws, authn/authz, hardcoded secrets, crypto misuse, SSRF, path traversal, RCE vectors, XSS/CSRF, unsafe deserialization, insecure defaults/configuration, and supply chain issues.
-
Produce the report in markdown.
Report requirements
- Executive Summary
- Total findings by severity (Critical/High/Medium/Low/Info)
- Top 5 most critical issues
- Overall security posture
- Detailed Findings (for each issue)
- Title, Severity, Rule Reference(s), Location, Code Snippet
- Description, Impact, Remediation (with examples), References
- Findings by Category
- Recommendations
- Immediate actions, short-term (1-3 months), long-term improvements, tooling/process suggestions
- Appendix
- Files reviewed, rules applied/coverage, methodology notes
Output
- Save the report to:
./security_report/sec_review_<repo-name>_<YYYY-MM-DD_HH-mm-ss>.md- Use the target repo folder name for
<repo-name>and replace spaces with-. - Write to the
security_reportfolder in the current working directory.
Sponsors
Details
- Marketplace
- cosai-oasis/project-codeguard
- Category
- Community