Skip to content

Commit 971ef7f

Browse files
authored
Merge pull request #7 from cosai-oasis/feature/add-rules
Add Project CodeGuard rules and skill files
2 parents 171ce3f + 1e73b27 commit 971ef7f

137 files changed

Lines changed: 15527 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude-plugin/marketplace.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "project-codeguard",
3+
"metadata": {
4+
"description": "Official Project CodeGuard plugins for secure AI-assisted coding"
5+
},
6+
"owner": {
7+
"name": "Project CodeGuard",
8+
"url": "https://project-codeguard.org",
9+
"email": "contact@project-codeguard.org"
10+
},
11+
"plugins": [
12+
{
13+
"name": "codeguard-security",
14+
"source": "./",
15+
"description": "Comprehensive security rules for AI coding agents",
16+
"version": "1.2.0",
17+
"repository": "https://github.com/cosai-oasis/project-codeguard.git",
18+
"tags": [
19+
"security",
20+
"code-review",
21+
"vulnerability-prevention"
22+
]
23+
}
24+
]
25+
}

.claude-plugin/plugin.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "codeguard-security",
3+
"description": "Security code review skill based on Project CodeGuard's comprehensive security rules. Helps AI coding agents write secure code and prevent common vulnerabilities.",
4+
"version": "1.2.0",
5+
"author": {
6+
"name": "Project CodeGuard",
7+
"url": "https://project-codeguard.org"
8+
},
9+
"homepage": "https://github.com/cosai-oasis/project-codeguard",
10+
"repository": "https://github.com/cosai-oasis/project-codeguard.git",
11+
"keywords": [
12+
"security",
13+
"secure-coding",
14+
"vulnerability-prevention",
15+
"code-review",
16+
"appsec"
17+
]
18+
}

skills/software-security/SKILL.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
name: software-security
3+
description: A software security skill that integrates with Project CodeGuard to help AI coding agents write secure code and prevent common vulnerabilities. Use this skill when writing, reviewing, or modifying code to ensure secure-by-default practices are followed.
4+
codeguard-version: "1.2.0"
5+
framework: "Project CodeGuard"
6+
purpose: "Embed secure-by-default practices into AI coding workflows"
7+
---
8+
9+
# Software Security Skill (Project CodeGuard)
10+
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.
11+
12+
## When to Use This Skill
13+
This skill should be activated when:
14+
- Writing new code in any language
15+
- Reviewing or modifying existing code
16+
- Implementing security-sensitive features (authentication, cryptography, data handling, etc.)
17+
- Working with user input, databases, APIs, or external services
18+
- Configuring cloud infrastructure, CI/CD pipelines, or containers
19+
- Handling sensitive data, credentials, or cryptographic operations
20+
21+
## How to Use This Skill
22+
When writing or reviewing code:
23+
1. Always-Apply Rules: Some rules MUST be checked on every code operation:
24+
- `codeguard-1-hardcoded-credentials.md` - Never hardcode secrets, passwords, API keys, or tokens
25+
- `codeguard-1-crypto-algorithms.md` - Use only modern, secure cryptographic algorithms
26+
- `codeguard-1-digital-certificates.md` - Validate and manage digital certificates securely
27+
2. Context-Specific Rules: Apply rules from /rules directory based on the language of the feature being implemented using the table given below:
28+
29+
30+
| Language | Rule Files to Apply |
31+
|----------|---------------------|
32+
| apex | codeguard-0-input-validation-injection.md |
33+
| c | 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-file-handling-and-uploads.md, codeguard-0-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-logging.md, codeguard-0-safe-c-functions.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
34+
| cpp | codeguard-0-safe-c-functions.md |
35+
| d | codeguard-0-iac-security.md |
36+
| docker | codeguard-0-devops-ci-cd-containers.md, codeguard-0-supply-chain-security.md |
37+
| 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 |
38+
| html | codeguard-0-client-side-web-security.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md |
39+
| 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 |
40+
| 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-cloud-orchestration-kubernetes.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-iac-security.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 |
41+
| kotlin | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md |
42+
| matlab | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md, codeguard-0-privacy-data-protection.md |
43+
| perl | codeguard-0-mobile-apps.md |
44+
| 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 |
45+
| powershell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
46+
| 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 |
47+
| 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-iac-security.md, codeguard-0-input-validation-injection.md, codeguard-0-session-management-and-cookies.md, codeguard-0-xml-and-serialization.md |
48+
| rust | codeguard-0-mcp-security.md |
49+
| shell | codeguard-0-devops-ci-cd-containers.md, codeguard-0-iac-security.md, codeguard-0-input-validation-injection.md |
50+
| sql | codeguard-0-data-storage.md, codeguard-0-input-validation-injection.md |
51+
| swift | codeguard-0-additional-cryptography.md, codeguard-0-authentication-mfa.md, codeguard-0-mobile-apps.md |
52+
| 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 |
53+
| vlang | codeguard-0-client-side-web-security.md |
54+
| xml | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, codeguard-0-devops-ci-cd-containers.md, codeguard-0-framework-and-languages.md, codeguard-0-mobile-apps.md, codeguard-0-xml-and-serialization.md |
55+
| yaml | codeguard-0-additional-cryptography.md, codeguard-0-api-web-services.md, 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-framework-and-languages.md, codeguard-0-iac-security.md, codeguard-0-logging.md, codeguard-0-privacy-data-protection.md, codeguard-0-supply-chain-security.md |
56+
57+
58+
3. Proactive Security: Don't just avoid vulnerabilities-actively implement secure patterns:
59+
- Use parameterized queries for database access
60+
- Validate and sanitize all user input
61+
- Apply least-privilege principles
62+
- Use modern cryptographic algorithms and libraries
63+
- Implement defense-in-depth strategies
64+
65+
## CodeGuard Security Rules
66+
The security rules are available in the `rules/` directory.
67+
68+
### Usage Workflow
69+
When generating or reviewing code, follow this workflow:
70+
71+
### 1. Initial Security Check
72+
Before writing any code:
73+
- Check: Will this handle credentials? → Apply codeguard-1-hardcoded-credentials
74+
- Check: What language am I using? → Identify applicable language-specific rules
75+
- Check: What security domains are involved? → Load relevant rule files
76+
77+
### 2. Code Generation
78+
While writing code:
79+
- Apply secure-by-default patterns from relevant Project CodeGuard rules
80+
- Add security-relevant comments explaining choices
81+
82+
### 3. Security Review
83+
After writing code:
84+
- Review against implementation checklists in each rule
85+
- Verify no hardcoded credentials or secrets
86+
- Validate that all the rules have been successfully followed when applicable.
87+
- Explain which security rules were applied
88+
- Highlight security features implemented
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
description: Additional Cryptography guidance
3+
languages:
4+
- c
5+
- go
6+
- java
7+
- javascript
8+
- kotlin
9+
- matlab
10+
- php
11+
- python
12+
- ruby
13+
- swift
14+
- typescript
15+
- xml
16+
- yaml
17+
alwaysApply: false
18+
---
19+
20+
rule_id: codeguard-0-additional-cryptography
21+
22+
## Additional Cryptography & TLS
23+
24+
Apply modern, vetted cryptography for data at rest and in transit. Manage keys safely, configure TLS correctly, deploy HSTS, and consider pinning only when appropriate.
25+
26+
### Algorithms and Modes
27+
- Symmetric: AES‑GCM or ChaCha20‑Poly1305 preferred. Avoid ECB. CBC/CTR only with encrypt‑then‑MAC.
28+
- Asymmetric: RSA ≥2048 or modern ECC (Curve25519/Ed25519). Use OAEP for RSA encryption.
29+
- Hashing: SHA‑256+ for integrity; avoid MD5/SHA‑1.
30+
- RNG: Use CSPRNG appropriate to platform (e.g., SecureRandom, crypto.randomBytes, secrets module). Never use non‑crypto RNGs.
31+
32+
### Key Management
33+
- Generate keys within validated modules (HSM/KMS) and never from passwords or predictable inputs.
34+
- Separate keys by purpose (encryption, signing, wrapping). Rotate on compromise, cryptoperiod, or policy.
35+
- Store keys in KMS/HSM or vault; never hardcode; avoid plain env vars. Use KEK to wrap DEKs; store separately.
36+
- Control access to trust stores; validate updates; audit all key access and operations.
37+
38+
### Data at Rest
39+
- Encrypt sensitive data; minimize stored secrets; tokenize where possible.
40+
- Use authenticated encryption; manage nonces/IVs properly; keep salts unique per item.
41+
- Protect backups: encrypt, restrict access, test restores, manage retention.
42+
43+
### TLS Configuration
44+
- Protocols: TLS 1.3 preferred; allow TLS 1.2 only for legacy compatibility; disable TLS 1.0/1.1 and SSL. Enable TLS_FALLBACK_SCSV.
45+
- Ciphers: prefer AEAD suites; disable NULL/EXPORT/anon. Keep libraries updated; disable compression.
46+
- Key exchange groups: prefer x25519/secp256r1; configure secure FFDHE groups if needed.
47+
- Certificates: 2048‑bit+ keys, SHA‑256, correct CN/SAN. Manage lifecycle and revocation (OCSP stapling).
48+
- Application: HTTPS site‑wide; redirect HTTP→HTTPS; prevent mixed content; set cookies `Secure`.
49+
50+
### HSTS
51+
- Send Strict‑Transport‑Security only over HTTPS. Phase rollout:
52+
- Test: short max‑age (e.g., 86400) with includeSubDomains
53+
- Prod: ≥1 year max‑age; includeSubDomains when safe
54+
- Optional preload once mature; understand permanence and subdomain impact
55+
56+
### Pinning
57+
- Avoid browser HPKP. Consider pinning only for controlled clients (e.g., mobile) and when you own both ends.
58+
- Prefer SPKI pinning with backup pins; plan secure update channels; never allow user bypass.
59+
- Thoroughly test rotation and failure handling; understand operational risk.
60+
61+
### Implementation Checklist
62+
- AEAD everywhere; vetted libraries only; no custom crypto.
63+
- Keys generated and stored in KMS/HSM; purpose‑scoped; rotation documented.
64+
- TLS 1.3/1.2 with strong ciphers; compression off; OCSP stapling on.
65+
- HSTS deployed per phased plan; mixed content eliminated.
66+
- Pinning used only where justified, with backups and update path.
67+
68+
### Test Plan
69+
- Automated config scans (e.g., SSL Labs, testssl.sh) for protocol/cipher/HSTS.
70+
- Code review for crypto API misuse; tests for key rotation, backup/restore.
71+
- Pinning simulations for rotation/failures if deployed.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
description: API & Web services security (REST/GraphQL/SOAP), schema validation, authn/z, SSRF
3+
languages:
4+
- c
5+
- go
6+
- java
7+
- javascript
8+
- php
9+
- python
10+
- ruby
11+
- typescript
12+
- xml
13+
- yaml
14+
alwaysApply: false
15+
---
16+
17+
rule_id: codeguard-0-api-web-services
18+
19+
## API & Web Services Security
20+
21+
Secure REST, GraphQL, and SOAP/WS services end‑to‑end: transport, authn/z, schema validation, SSRF controls, DoS limits, and microservice‑safe patterns.
22+
23+
### Transport and TLS
24+
- HTTPS only; consider mTLS for high‑value/internal services. Validate certs (CN/SAN, revocation) and prevent mixed content.
25+
26+
### Authentication and Tokens
27+
- Use standard flows (OAuth2/OIDC) for clients; avoid custom schemes. For services, use mTLS or signed service tokens.
28+
- JWTs: pin algorithms; validate iss/aud/exp/nbf; short lifetimes; rotation; denylist on logout/revoke. Prefer opaque tokens when revocation is required and central store is available.
29+
- API keys: scope narrowly; rate limit; monitor usage; do not use alone for sensitive operations.
30+
31+
### Authorization
32+
- Enforce per‑endpoint, per‑resource checks server‑side; deny by default.
33+
- For microservices, authorize at gateway (coarse) and service (fine) layers; propagate signed internal identity, not external tokens.
34+
35+
### Input and Content Handling
36+
- Validate inputs via contracts: OpenAPI/JSON Schema, GraphQL SDL, XSD. Reject unknown fields and oversize payloads; set limits.
37+
- Content types: enforce explicit Content‑Type/Accept; reject unsupported combinations. Harden XML parsers against XXE/expansion.
38+
39+
### SQL/Injection Safety in Resolvers and Handlers
40+
- Use parameterized queries/ORM bind parameters; never concatenate user input into queries or commands.
41+
42+
### GraphQL‑Specific Controls
43+
- Limit query depth and overall complexity; enforce pagination; timeouts on execution; disable introspection and IDEs in production.
44+
- Implement field/object‑level authorization to prevent IDOR/BOLA; validate batching and rate limit per object type.
45+
46+
### SSRF Prevention for Outbound Calls
47+
- Do not accept raw URLs. Validate domains/IPs using libraries; restrict to HTTP/HTTPS only (block file://, gopher://, ftp://, etc.).
48+
- Case 1 (fixed partners): strict allow‑lists; disable redirects; network egress allow‑lists.
49+
- Case 2 (arbitrary): block private/link‑local/localhost ranges; resolve and verify all IPs are public; require signed tokens from the target where feasible.
50+
51+
### SOAP/WS and XML Safety
52+
- Validate SOAP payloads with XSD; limit message sizes; enable XML signatures/encryption where required.
53+
- Configure parsers against XXE, entity expansion, and recursive payloads; scan attachments.
54+
55+
### Rate Limiting and DoS
56+
- Apply per‑IP/user/client limits, circuit breakers, and timeouts. Use server‑side batching and caching to reduce load.
57+
58+
### Management Endpoints
59+
- Do not expose over the Internet. Require strong auth (MFA), network restrictions, and separate ports/hosts.
60+
61+
### Testing and Assessment
62+
- Maintain formal API definitions; drive contract tests and fuzzing from specs.
63+
- Assess endpoints for authn/z bypass, SSRF, injection, and information leakage; log token validation failures.
64+
65+
### Microservices Practices
66+
- Policy‑as‑code with embedded decision points; sidecar or library PDPs.
67+
- Service identity via mTLS or signed tokens; never reuse external tokens internally.
68+
- Centralized structured logging with correlation IDs; sanitize sensitive data.
69+
70+
### Implementation Checklist
71+
- HTTPS/mTLS configured; certs managed; no mixed content.
72+
- Contract validation at the edge and service; unknown fields rejected; size/time limits enforced.
73+
- Strong authn/z per endpoint; GraphQL limits applied; introspection disabled in prod.
74+
- SSRF protections at app and network layers; redirects disabled; allow‑lists where possible.
75+
- Rate limiting, circuit breakers, and resilient patterns in place.
76+
- Management endpoints isolated and strongly authenticated.
77+
- Logs structured and privacy‑safe with correlation IDs.
78+
79+
### Test Plan
80+
- Contract tests for schema adherence; fuzzing with schema‑aware tools.
81+
- Pen tests for SSRF, IDOR/BOLA, and authz bypass; performance tests for DoS limits.
82+
- Test all HTTP methods per endpoint; discover parameters in URL paths, headers, and structured data beyond obvious query strings.
83+
- Automated checks for token validation and revocation behavior.

0 commit comments

Comments
 (0)