Skip to content

Commit 62615d9

Browse files
authored
Merge pull request #90 from project-codeguard/develop
Updated codeguard-1-crypto-algorithms.md rule to include guidance on post quantum cryptography Updated ClaudeCodeSkills to a more generic class AgentSkills after Agent Skills are adopted as a standard. Fixed codeguard-1-digital-certificates.md so that the agent does not assume certificate parsing capabilities. Updated codeguard-0-input-validation-injection.md to include guidance on SOQL along with SQL. Added documentation for generating custom rule files.
2 parents bdd060e + f6bbd06 commit 62615d9

14 files changed

Lines changed: 509 additions & 315 deletions

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Get started in minutes:
5454
## How It Works
5555

5656
1. **Security rules** are written in unified markdown format (`sources/` directory)
57-
2. **Conversion tools** translate rules to IDE-specific formats (Cursor, Windsurf, Copilot, Claude Code, Antigravity)
57+
2. **Conversion tools** translate rules to IDE-specific formats (Cursor, Windsurf, Copilot, Agent Skills, Antigravity)
5858
3. **Release automation** packages rules into downloadable ZIP files
5959
4. **AI assistants** reference these rules when generating or reviewing code
6060
5. **Secure code** is produced automatically without developer intervention
@@ -63,7 +63,7 @@ Get started in minutes:
6363

6464
```
6565
sources/ # Source rules
66-
skills/ # Claude Code plugin (generated, committed)
66+
skills/ # Agent Skills format (generated, committed)
6767
src/ # Conversion and validation tools
6868
dist/ # Other IDE bundles (generated, not committed)
6969
```
@@ -78,6 +78,7 @@ python src/convert_to_ide_formats.py # Generate skills/ and dist/
7878
```
7979

8080
**More options**: `python src/convert_to_ide_formats.py --help`
81+
**Custom rules**: Create your own rules — see [Custom Rules](https://project-codeguard.org/custom-rules/)
8182
**Maintainers**: See [CONTRIBUTING.md](CONTRIBUTING.md) for release process.
8283

8384
## Community

docs/custom-rules.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Custom Rules
2+
3+
Create custom rules to enforce your own policies, compliance requirements, or coding standards.
4+
5+
## Quick Start
6+
7+
1. **Create a source folder** under `sources/`:
8+
```
9+
sources/
10+
├── core/ # Project CodeGuard rules
11+
├── owasp/ # OWASP supplementary rules
12+
└── my-rules/ # Your custom rules
13+
```
14+
15+
2. **Copy the template** from `sources/templates/custom-rule-template.md.example` and customize it
16+
17+
3. **Build with your rules**:
18+
```bash
19+
uv run python src/convert_to_ide_formats.py --source core my-rules
20+
```
21+
22+
## Frontmatter Schema
23+
24+
| Field | Required | Description |
25+
|-------|----------|-------------|
26+
| `description` | Yes | Brief description of the rule |
27+
| `languages` | If `alwaysApply` is false | List of languages this rule applies to |
28+
| `alwaysApply` | No | If `true`, rule applies to all files (omit `languages`) |
29+
| `tags` | No | Categories for filtering: `authentication`, `data-security`, `infrastructure`, `privacy`, `secrets`, `web` |
30+
31+
## CLI Reference
32+
33+
### convert_to_ide_formats.py
34+
35+
Converts source rules to IDE-specific formats.
36+
37+
| Option | Description |
38+
|--------|-------------|
39+
| `--source` | Source folders under `sources/` to include. Default: `core` |
40+
| `--output-dir`, `-o` | Output directory for generated bundles. Default: `dist` |
41+
| `--tag` | Filter rules by tags (comma-separated, case-insensitive, AND logic) |
42+
43+
**Examples:**
44+
45+
```bash
46+
# Default: convert core rules only
47+
uv run python src/convert_to_ide_formats.py
48+
49+
# Include multiple sources
50+
uv run python src/convert_to_ide_formats.py --source core owasp my-rules
51+
52+
# Custom output directory
53+
uv run python src/convert_to_ide_formats.py --source core my-rules -o build
54+
55+
# Filter to only rules tagged with data-security
56+
uv run python src/convert_to_ide_formats.py --tag data-security
57+
58+
# Multiple tags (AND logic - rules must have ALL tags)
59+
uv run python src/convert_to_ide_formats.py --tag data-security,authentication
60+
```
61+
62+
### validate_unified_rules.py
63+
64+
Validates rule files have correct frontmatter and structure before building.
65+
66+
```bash
67+
# Validate all rules in a directory
68+
uv run python src/validate_unified_rules.py sources/my-rules/
69+
70+
# Validate all sources
71+
uv run python src/validate_unified_rules.py sources/
72+
```
73+
74+
## Notes
75+
76+
- Filenames must be unique across all sources
77+
- Use `.md` extension for all rule files
78+
- Rules are converted to all supported IDE formats
79+
- To add new tags, update `KNOWN_TAGS` in `src/tag_mappings.py`

skills/software-security/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ When writing or reviewing code:
2929

3030
| Language | Rule Files to Apply |
3131
|----------|---------------------|
32+
| apex | codeguard-0-input-validation-injection.md |
3233
| 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 |
3334
| cpp | codeguard-0-safe-c-functions.md |
3435
| d | codeguard-0-iac-security.md |

skills/software-security/rules/codeguard-0-input-validation-injection.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
2-
description: Input validation and injection defense (SQL/LDAP/OS), parameterization, prototype pollution
2+
description: Input validation and injection defense (SQL/SOQL/LDAP/OS), parameterization, prototype pollution
33
languages:
4+
- apex
45
- c
56
- go
67
- html
@@ -49,6 +50,16 @@ pstmt.setString( 1, custname);
4950
ResultSet results = pstmt.executeQuery( );
5051
```
5152

53+
### SOQL/SOSL Injection (Salesforce)
54+
55+
SOQL and SOSL are query/search languages (no SQL-style DDL/DML). Data changes are performed via Apex DML or Database methods. Note: SOQL can lock rows via `FOR UPDATE`.
56+
57+
- Primary risk: data exfiltration by bypassing intended query filters/business logic; impact is amplified when Apex runs with elevated access (system mode) or when CRUD/FLS aren't enforced.
58+
- Second-order risk (conditional): if queried records are passed to DML, injection can broaden the record set and cause unintended mass updates/deletes.
59+
- Prefer static SOQL/SOSL with bind variables: `[SELECT Id FROM Account WHERE Name = :userInput]` or `FIND :term`.
60+
- For dynamic SOQL, use `Database.queryWithBinds()`; for dynamic SOSL, use `Search.query()`. Allow‑list any dynamic identifiers. If concatenation is unavoidable, escape string values with `String.escapeSingleQuotes()`.
61+
- Enforce CRUD/FLS with `WITH USER_MODE` or `WITH SECURITY_ENFORCED` (don't combine both). Enforce record sharing with `with sharing` or user-mode operations. Use `Security.stripInaccessible()` before DML.
62+
5263
### LDAP Injection Prevention
5364
- Always apply context‑appropriate escaping:
5465
- DN escaping for `\ # + < > , ; " =` and leading/trailing spaces

skills/software-security/rules/codeguard-1-crypto-algorithms.md

Lines changed: 96 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,126 @@
11
---
2-
description: Cryptographic Security Guidelines
2+
description: Cryptographic Security Guidelines & Post-Quantum Readiness
33
alwaysApply: true
44
---
55

66
rule_id: codeguard-1-crypto-algorithms
77

8-
# Cryptographic Security Guidelines
8+
# Cryptographic Security Guidelines & Post-Quantum Readiness
99

10-
## Banned (Insecure) Algorithms
10+
## 1. Banned (Insecure) Algorithms
1111

12-
The following algorithms are known to be broken or fundamentally insecure. **NEVER** generate or use code with these algorithms.
13-
Examples:
12+
The following algorithms are known to be broken or fundamentally insecure. NEVER generate or use code with these algorithms.
1413

15-
* Hash: `MD2`, `MD4`, `MD5`, `SHA-0`
16-
* Symmetric: `RC2`, `RC4`, `Blowfish`, `DES`, `3DES`
17-
* Key Exchange: Static RSA, Anonymous Diffie-Hellman
18-
* Classical: `Vigenère`
14+
* Hash: `MD2`, `MD4`, `MD5`, `SHA-0`
15+
* Symmetric: `RC2`, `RC4`, `Blowfish`, `DES`, `3DES`
16+
* Key Exchange: Static RSA, Anonymous Diffie-Hellman
17+
* Classical: `Vigenère`
1918

20-
## Deprecated (Legacy/Weak) Algorithms
19+
Reason: These are cryptographically broken and vulnerable to collision or man-in-the-middle attacks.
2120

22-
The following algorithms are not outright broken, but have known weaknesses, or are considered obsolete. **NEVER** generate or use code with these algorithms.
23-
Examples:
21+
## 2. Deprecated (Legacy/Weak) Algorithms
2422

25-
* Hash: `SHA-1`
26-
* Symmetric: `AES-CBC`, `AES-ECB`
27-
* Signature: RSA with `PKCS#1 v1.5` padding
28-
* Key Exchange: DHE with weak/common primes
23+
The following algorithms have known weaknesses or are considered obsolete. Avoid in new designs and prioritize migration.
2924

25+
* Hash: `SHA-1`
26+
* Symmetric: `AES-CBC`, `AES-ECB`
27+
* Signature: RSA with `PKCS#1 v1.5` padding
28+
* Key Exchange: DHE with weak/common primes
3029

31-
## Deprecated SSL/Crypto APIs - FORBIDDEN
32-
NEVER use these deprecated functions. Use the replacement APIs listed below:
30+
## 3. Recommended & Post-Quantum Ready Algorithms
3331

34-
### Symmetric Encryption (AES)
32+
Implement these modern, secure algorithms to ensure resistance against both classical and quantum threats.
33+
34+
### Symmetric Encryption
35+
* Standard: `AES-GCM` (AEAD), `ChaCha20-Poly1305`(when allowed).
36+
* PQC Requirement: Prefer AES-256 keys (or stronger) as they are resistant to quantum attacks (Grover's algorithm).
37+
* Avoid: Custom crypto or unauthenticated modes.
38+
39+
### Key Exchange (KEM)
40+
* Standard: ECDHE (`X25519` or `secp256r1`)
41+
* PQC Requirement: Use Hybrid Key Exchange (Classical + PQC) when supported.
42+
* Preferred: `X25519MLKEM768` (X25519 + ML-KEM-768)
43+
* Alternative: `SecP256r1MLKEM768` (P-256 + ML-KEM-768)
44+
* High Assurance: `SecP384r1MLKEM1024` (P-384 + ML-KEM-1024)
45+
* Pure PQC: ML-KEM-768 (baseline) or ML-KEM-1024. Avoid ML-KEM-512 unless explicitly risk-accepted.
46+
* Constraints:
47+
* Use vendor-documented identifiers (RFC 9242/9370).
48+
* Remove legacy/draft "Hybrid-Kyber" groups (e.g., `X25519Kyber`) and draft or hardcoded OIDs.
49+
50+
### Signatures & Certificates
51+
* Standard: ECDSA (`P-256`)
52+
* PQC Migration: Continue using ECDSA (`P-256`) for mTLS and code signing until hardware-backed (HSM/TPM) ML-DSA is available.
53+
* Hardware Requirement: Do not enable PQC ML-DSA signatures using software-only keys. Require HSM/TPM storage.
54+
55+
### Protocol Versions
56+
* (D)TLS: Enforce (D)TLS 1.3 only (or later).
57+
* IPsec: Enforce IKEv2 only.
58+
* Use ESP with AEAD (AES-256-GCM).
59+
* Require PFS via ECDHE.
60+
* Implement RFC 9242 and RFC 9370 for Hybrid PQC (ML-KEM + ECDHE).
61+
* Ensure re-keys (CREATE_CHILD_SA) maintain hybrid algorithms.
62+
* SSH: Enable only vendor-supported PQC/hybrid KEX (e.g., `sntrup761x25519`).
63+
64+
## 4. Secure Implementation Guidelines
65+
66+
### General Best Practices
67+
* Configuration over Code: Expose algorithm choices in config/policy to allow agility without code changes.
68+
* Key Management:
69+
* Use KMS/HSM for key storage.
70+
* Generate keys with a CSPRNG.
71+
* Separate encryption keys from signature keys.
72+
* Rotate keys per policy.
73+
* NEVER hardcode keys, secrets, or experimental OIDs.
74+
* Telemetry: Capture negotiated groups, handshake sizes, and failure causes to monitor PQC adoption.
75+
76+
### Deprecated SSL/Crypto APIs (C/OpenSSL) - FORBIDDEN
77+
NEVER use these deprecated functions. Use the replacement EVP high-level APIs.
78+
79+
#### Symmetric Encryption (AES)
3580
- Deprecated: `AES_encrypt()`, `AES_decrypt()`
36-
- Replacement: Use EVP high-level APIs:
37-
```c
38-
EVP_EncryptInit_ex()
81+
- Replacement:
82+
83+
EVP_EncryptInit_ex() // Use EVP_aes_256_gcm() for PQC readiness
3984
EVP_EncryptUpdate()
4085
EVP_EncryptFinal_ex()
41-
EVP_DecryptInit_ex()
42-
EVP_DecryptUpdate()
43-
EVP_DecryptFinal_ex()
44-
```
45-
46-
### RSA Operations
47-
- Deprecated: `RSA_new()`, `RSA_up_ref()`, `RSA_free()`, `RSA_set0_crt_params()`, `RSA_get0_n()`
48-
- Replacement: Use EVP key management APIs:
49-
```c
86+
87+
88+
#### RSA/PKEY Operations
89+
- Deprecated: `RSA_new()`, `RSA_free()`, `RSA_get0_n()`
90+
- Replacement:
91+
5092
EVP_PKEY_new()
5193
EVP_PKEY_up_ref()
5294
EVP_PKEY_free()
53-
```
54-
55-
### Hash Functions
56-
- Deprecated: `SHA1_Init()`, `SHA1_Update()`, `SHA1_Final()`
57-
- Replacement: Use EVP digest APIs:
58-
```c
59-
EVP_DigestInit_ex()
60-
EVP_DigestUpdate()
61-
EVP_DigestFinal_ex()
62-
EVP_Q_digest() // For simple one-shot hashing
63-
```
64-
65-
### MAC Operations
66-
- Deprecated: `CMAC_Init()`, `HMAC()` (especially with SHA1)
67-
- Replacement: Use EVP MAC APIs:
68-
```c
69-
EVP_Q_MAC() // For simple MAC operations
70-
```
71-
72-
### Key Wrapping
73-
- Deprecated: `AES_wrap_key()`, `AES_unwrap_key()`
74-
- Replacement: Use EVP key wrapping APIs or implement using EVP encryption
75-
76-
### Other Deprecated Functions
77-
- Deprecated: `DSA_sign()`, `DH_check()`
78-
- Replacement: Use corresponding EVP APIs for DSA and DH operations
79-
80-
## Banned Insecure Algorithms - STRICTLY FORBIDDEN
81-
These algorithms MUST NOT be used in any form:
82-
83-
### Hash Algorithms (Banned)
84-
- MD2, MD4, MD5, SHA-0
85-
- Reason: Cryptographically broken, vulnerable to collision attacks
86-
- Use Instead: SHA-256, SHA-384, SHA-512
87-
88-
### Symmetric Ciphers (Banned)
89-
- RC2, RC4, Blowfish, DES, 3DES
90-
- Reason: Weak key sizes, known vulnerabilities
91-
- Use Instead: AES-128, AES-256, ChaCha20
92-
93-
### Key Exchange (Banned)
94-
- Static RSA key exchange
95-
- Anonymous Diffie-Hellman
96-
- Reason: No forward secrecy, vulnerable to man-in-the-middle attacks
97-
- Use Instead: ECDHE, DHE with proper validation
98-
99-
## Broccoli Project Specific Requirements
100-
- HMAC() with SHA1: Deprecated per Broccoli project requirements
95+
96+
97+
#### Hash & MAC Functions
98+
- Deprecated: `SHA1_Init()`, `HMAC()` (especially with SHA1)
99+
- Replacement:
100+
101+
EVP_DigestInit_ex() // Use SHA-256 or stronger
102+
EVP_Q_MAC() // For one-shot MAC
103+
104+
105+
## 5. Broccoli Project Specific Requirements
106+
- HMAC() with SHA1: Deprecated.
101107
- Replacement: Use HMAC with SHA-256 or stronger:
102-
```c
103-
// Instead of HMAC() with SHA1
104-
EVP_Q_MAC(NULL, "HMAC", NULL, "SHA256", NULL, key, key_len, data, data_len, out, out_size, &out_len);
105-
```
106108

107-
## Secure Crypto Implementation Pattern
109+
110+
// Example: Secure replacement for HMAC-SHA1
111+
```c
112+
EVP_Q_MAC(NULL, "HMAC", NULL, "SHA256", NULL, key, key_len, data, data_len, out, out_size, &out_len);
113+
```
114+
115+
## 6. Secure Crypto Implementation Pattern
116+
117+
118+
// Example: Secure AES-256-GCM encryption (PQC-Ready Symmetric Strength)
108119
```c
109-
// Example: Secure AES encryption
110120
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
111121
if (!ctx) handle_error();
112122
123+
// Use AES-256-GCM
113124
if (EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, key, iv) != 1)
114125
handle_error();
115126
@@ -124,11 +135,3 @@ ciphertext_len += len;
124135
125136
EVP_CIPHER_CTX_free(ctx);
126137
```
127-
128-
## Code Review Checklist
129-
- [ ] No deprecated SSL/crypto APIs used
130-
- [ ] No banned algorithms (MD5, DES, RC4, etc.)
131-
- [ ] HMAC uses SHA-256 or stronger (not SHA1)
132-
- [ ] All crypto operations use EVP high-level APIs
133-
- [ ] Proper error handling for all crypto operations
134-
- [ ] Key material properly zeroed after use

0 commit comments

Comments
 (0)