Comprehensive security rules for AI coding agents

version
1.5.0
GitHub stars
374

Install

/plugin install codeguard-security@project-codeguard

Run it inside Claude Code after adding the marketplace with /plugin marketplace add cosai-oasis/project-codeguard.

Contents

Discovered from source

Skills 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:

  1. Always-Apply Rules: Some rules MUST be checked on every code operation:
  • codeguard-1-hardcoded-credentials.md - Never hardcode secrets, passwords, API keys, or tokens
  • codeguard-1-crypto-algorithms.md - Use only modern, secure cryptographic algorithms
  • codeguard-1-digital-certificates.md - Validate and manage digital certificates securely
  1. 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
authenticationcodeguard-0-authentication-mfa.md, codeguard-0-session-management-and-cookies.md
data-securitycodeguard-0-additional-cryptography.md, codeguard-0-data-storage.md
infrastructurecodeguard-0-cloud-orchestration-kubernetes.md, codeguard-0-data-storage.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md
privacycodeguard-0-logging.md, codeguard-0-privacy-data-protection.md
secretscodeguard-0-additional-cryptography.md, codeguard-1-digital-certificates.md, codeguard-1-hardcoded-credentials.md
webcodeguard-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
  1. Language-Specific Rules: Apply rules from /rules directory based on the programming language of the feature being implemented using the table given below:
LanguageRule Files to Apply
apexcodeguard-0-input-validation-injection.md
ccodeguard-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
cppcodeguard-0-safe-c-functions.md
dockercodeguard-0-devops-ci-cd-containers.md, codeguard-0-supply-chain-security.md
gocodeguard-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
hclcodeguard-0-iac-security.md
htmlcodeguard-0-client-side-web-security.md, codeguard-0-input-validation-injection.md
javacodeguard-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
javascriptcodeguard-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
kotlincodeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md
phpcodeguard-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
powershellcodeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md
pythoncodeguard-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
rubycodeguard-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
rustcodeguard-0-mcp-security.md
shellcodeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md
sqlcodeguard-0-data-storage.md, codeguard-0-input-validation-injection.md
swiftcodeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md
typescriptcodeguard-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
xmlcodeguard-0-api-web-services.md, codeguard-0-mobile-apps.md, codeguard-0-xml-and-serialization.md
yamlcodeguard-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
  1. 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:

  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

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:

  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

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 unsafe blocks — wrap only the minimum necessary operation
  • Document every unsafe block 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_unwind at FFI entry points

Step 5: Validate

After every migration unit, verify:

  • All existing tests pass against the new implementation
  • No new unsafe surface 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 (clippy for Rust, go vet for Go)
  • Add formatting checks (rustfmt, gofmt)
  • Add safety-specific CI checks (deny unsafe without 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 unsafe to replicate C-style patterns in Rust — if extensive unsafe is 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, or with patterns
  • 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
  • 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

  1. Load the security knowledge base from Project CodeGuard

    • First read the Security_Code_Reviewer_Guidelines.md file 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/rules
      

      These 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/owasp
      

      Only load OWASP rules that match the target repository's technology stack.

  2. 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.
  3. 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_report folder in the current working directory.

Sponsors

Details

Marketplace
cosai-oasis/project-codeguard
Category
Community