claude-code-templates 1.22.0 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,309 @@
1
+ # Security Audit System Architecture
2
+
3
+ ## Overview
4
+ This document outlines the security validation system for Claude Code Templates components (agents, commands, MCPs, settings, hooks).
5
+
6
+ ## Industry Standards Reference
7
+
8
+ ### Implemented Standards
9
+ - **NPM 2025**: SHA256 hashing, provenance metadata, trusted publishing principles
10
+ - **SLSA Framework**: Level 2 compliance (build integrity, tamper resistance)
11
+ - **PyPI Security**: Content validation, typo-squatting detection
12
+ - **GitHub Security**: Secret scanning patterns, malicious pattern detection
13
+
14
+ ## System Architecture
15
+
16
+ ```
17
+ cli-tool/src/validation/
18
+ ├── validators/
19
+ │ ├── StructuralValidator.js # Frontmatter, size, encoding
20
+ │ ├── SemanticValidator.js # Prompt injection, jailbreaks
21
+ │ ├── ReferenceValidator.js # URLs, HTML, Safe Browsing
22
+ │ ├── IntegrityValidator.js # SHA256, version tracking
23
+ │ └── ProvenanceValidator.js # Author, repo, commit metadata
24
+ ├── ValidationOrchestrator.js # Coordinates all validators
25
+ ├── security-audit.js # CLI command implementation
26
+ └── ARCHITECTURE.md # This file
27
+
28
+ .github/workflows/
29
+ └── component-validation.yml # PR validation workflow
30
+ ```
31
+
32
+ ## Validation Tiers
33
+
34
+ ### Tier 1: Structural Validation (CRITICAL)
35
+ **Validators**: `StructuralValidator.js`
36
+ - ✅ YAML frontmatter validation (name, description, tools, model)
37
+ - ✅ File size limits (max 100KB for agents/commands)
38
+ - ✅ UTF-8 encoding validation
39
+ - ✅ Section count limits (prevent context overflow)
40
+ - ✅ Required fields presence check
41
+
42
+ **Error Codes**: `STRUCT_*`
43
+
44
+ ### Tier 2: Semantic Validation (HIGH PRIORITY)
45
+ **Validators**: `SemanticValidator.js`
46
+ - ✅ Prompt injection detection
47
+ - ✅ Jailbreak pattern detection
48
+ - ✅ Instruction override attempts
49
+ - ✅ Self-modification requests
50
+ - ✅ Credential harvesting patterns
51
+
52
+ **Patterns to Detect**:
53
+ ```javascript
54
+ const DANGEROUS_PATTERNS = [
55
+ /ignore\s+(previous|all)\s+instructions?/i,
56
+ /system\s+prompt|developer\s+instructions?/i,
57
+ /you\s+are\s+now\s+(a|an)\s+/i,
58
+ /execute\s+the\s+following\s+(code|command)/i,
59
+ /fetch.*?(token|key|password|credential)/i,
60
+ /open\s+a?\s?shell/i,
61
+ /<script|<iframe|javascript:/i
62
+ ];
63
+ ```
64
+
65
+ **Error Codes**: `SEM_*`
66
+
67
+ ### Tier 3: Reference Validation (MEDIUM PRIORITY)
68
+ **Validators**: `ReferenceValidator.js`
69
+ - ✅ URL validation (HTTPS only)
70
+ - ✅ Private IP blocking (127.0.0.1, 10.0.0.0/8, 192.168.0.0/16)
71
+ - ✅ file:// protocol blocking
72
+ - ✅ HTML tag sanitization
73
+ - ✅ Google Safe Browsing API integration (optional)
74
+
75
+ **Error Codes**: `REF_*`
76
+
77
+ ### Tier 4: Integrity (HIGH PRIORITY)
78
+ **Validators**: `IntegrityValidator.js`
79
+ - ✅ SHA256 hash generation
80
+ - ✅ Hash verification on install
81
+ - ✅ Version tracking
82
+ - ✅ Signature validation (future)
83
+
84
+ **Error Codes**: `INT_*`
85
+
86
+ ### Tier 5: Provenance (MEDIUM PRIORITY)
87
+ **Validators**: `ProvenanceValidator.js`
88
+ - ✅ Author metadata extraction
89
+ - ✅ Source repository tracking
90
+ - ✅ Git commit SHA tracking
91
+ - ✅ Timestamp tracking
92
+ - ⏳ Digital signatures (future)
93
+
94
+ **Error Codes**: `PROV_*`
95
+
96
+ ## CLI Usage
97
+
98
+ ### Command: `--security-audit`
99
+
100
+ ```bash
101
+ # Validate all components in the repository
102
+ npx create-claude-config --security-audit
103
+
104
+ # Validate specific component type
105
+ npx create-claude-config --security-audit --agent frontend-developer
106
+
107
+ # Validate specific file
108
+ npx create-claude-config --security-audit --file ./components/agents/frontend-developer.md
109
+
110
+ # Validate with verbose output
111
+ npx create-claude-config --security-audit --verbose
112
+
113
+ # Generate security report (JSON)
114
+ npx create-claude-config --security-audit --output report.json
115
+
116
+ # Validate in CI/CD mode (exit 1 on errors)
117
+ npx create-claude-config --security-audit --ci
118
+ ```
119
+
120
+ ### Output Format
121
+
122
+ ```
123
+ 🔒 Security Audit Report
124
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
125
+
126
+ 📁 Scanning: cli-tool/components/agents/
127
+
128
+ ✅ frontend-developer.md
129
+ ├─ Structural: PASS
130
+ ├─ Semantic: PASS
131
+ ├─ References: PASS
132
+ ├─ Integrity: PASS (sha256: a3f2...)
133
+ └─ Provenance: PASS (author: claude-code-templates)
134
+
135
+ ⚠️ backend-api-specialist.md
136
+ ├─ Structural: PASS
137
+ ├─ Semantic: WARNING (SEM_W001: Potential instruction override)
138
+ ├─ References: PASS
139
+ ├─ Integrity: PASS (sha256: b4e1...)
140
+ └─ Provenance: PASS
141
+
142
+ ❌ malicious-agent.md
143
+ ├─ Structural: PASS
144
+ ├─ Semantic: FAIL (SEM_E001: Jailbreak pattern detected)
145
+ ├─ References: FAIL (REF_E001: file:// protocol detected)
146
+ └─ Integrity: PASS (sha256: c5d2...)
147
+
148
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
149
+ Summary:
150
+ Total: 3 components
151
+ ✅ Passed: 1
152
+ ⚠️ Warnings: 1
153
+ ❌ Failed: 1
154
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
155
+ ```
156
+
157
+ ## GitHub Actions Integration
158
+
159
+ ### Workflow: `.github/workflows/component-validation.yml`
160
+
161
+ ```yaml
162
+ name: Component Security Validation
163
+
164
+ on:
165
+ pull_request:
166
+ paths:
167
+ - 'cli-tool/components/**/*.md'
168
+ push:
169
+ branches:
170
+ - main
171
+
172
+ jobs:
173
+ security-audit:
174
+ runs-on: ubuntu-latest
175
+ steps:
176
+ - uses: actions/checkout@v4
177
+
178
+ - name: Setup Node.js
179
+ uses: actions/setup-node@v4
180
+ with:
181
+ node-version: '18'
182
+
183
+ - name: Install dependencies
184
+ run: |
185
+ cd cli-tool
186
+ npm install
187
+
188
+ - name: Run Security Audit
189
+ run: |
190
+ cd cli-tool
191
+ npm run security-audit -- --ci --verbose
192
+
193
+ - name: Upload Security Report
194
+ if: always()
195
+ uses: actions/upload-artifact@v4
196
+ with:
197
+ name: security-audit-report
198
+ path: cli-tool/security-report.json
199
+ ```
200
+
201
+ ### PR Checks
202
+ - ✅ All validators must pass
203
+ - ⚠️ Warnings are allowed but reported
204
+ - ❌ Any errors block the PR
205
+
206
+ ## Component Metadata Schema
207
+
208
+ ### Enhanced components.json
209
+ ```json
210
+ {
211
+ "agents": [
212
+ {
213
+ "name": "frontend-developer",
214
+ "path": "agents/development-team/frontend-developer.md",
215
+ "description": "...",
216
+ "security": {
217
+ "validated": true,
218
+ "validatedAt": "2025-10-15T15:30:00Z",
219
+ "hash": "sha256:a3f2e1d4...",
220
+ "version": "1.0.0",
221
+ "provenance": {
222
+ "author": "claude-code-templates",
223
+ "repository": "https://github.com/danimesq/claude-code-templates",
224
+ "commit": "43dd5f9",
225
+ "verifiedAuthor": false
226
+ },
227
+ "audit": {
228
+ "structural": { "passed": true, "score": 100 },
229
+ "semantic": { "passed": true, "score": 100 },
230
+ "references": { "passed": true, "score": 100 },
231
+ "integrity": { "passed": true, "score": 100 },
232
+ "provenance": { "passed": true, "score": 95 }
233
+ }
234
+ }
235
+ }
236
+ ]
237
+ }
238
+ ```
239
+
240
+ ## Error Code Reference
241
+
242
+ ### Structural (STRUCT_*)
243
+ - `STRUCT_E001`: Missing required frontmatter
244
+ - `STRUCT_E002`: Invalid YAML syntax
245
+ - `STRUCT_E003`: File size exceeds limit
246
+ - `STRUCT_E004`: Invalid UTF-8 encoding
247
+ - `STRUCT_W001`: Missing optional field
248
+
249
+ ### Semantic (SEM_*)
250
+ - `SEM_E001`: Jailbreak pattern detected
251
+ - `SEM_E002`: Prompt injection detected
252
+ - `SEM_E003`: Instruction override attempt
253
+ - `SEM_E004`: Self-modification request
254
+ - `SEM_E005`: Credential harvesting pattern
255
+ - `SEM_W001`: Suspicious instruction wording
256
+
257
+ ### References (REF_*)
258
+ - `REF_E001`: Insecure protocol (file://, http://)
259
+ - `REF_E002`: Private IP address detected
260
+ - `REF_E003`: Malicious URL (Safe Browsing)
261
+ - `REF_E004`: Dangerous HTML tag
262
+ - `REF_W001`: Missing HTTPS
263
+
264
+ ### Integrity (INT_*)
265
+ - `INT_E001`: Hash mismatch
266
+ - `INT_E002`: Missing version
267
+ - `INT_E003`: Invalid signature
268
+ - `INT_W001`: No signature provided
269
+
270
+ ### Provenance (PROV_*)
271
+ - `PROV_E001`: Missing author
272
+ - `PROV_E002`: Invalid repository URL
273
+ - `PROV_W001`: Unverified author
274
+ - `PROV_W002`: Missing commit SHA
275
+
276
+ ## Testing Strategy
277
+
278
+ ### Unit Tests
279
+ ```bash
280
+ npm test -- --testPathPattern=validation
281
+ ```
282
+
283
+ ### Integration Tests
284
+ ```bash
285
+ npm run test:integration -- validation
286
+ ```
287
+
288
+ ### Test Coverage
289
+ - Target: 90%+ for validators
290
+ - Mocking: GitHub API, Safe Browsing API
291
+ - Fixtures: Malicious and benign component examples
292
+
293
+ ## Future Enhancements
294
+
295
+ ### Phase 2
296
+ - [ ] LLM-based semantic analysis (lightweight model)
297
+ - [ ] Community reporting system
298
+ - [ ] Automated revocation mechanism
299
+ - [ ] Digital signatures with PGP/GPG
300
+
301
+ ### Phase 3
302
+ - [ ] Real-time validation API endpoint
303
+ - [ ] Browser extension for component preview
304
+ - [ ] Trust score system (0-100)
305
+ - [ ] Historical vulnerability tracking
306
+
307
+ ## Security Contact
308
+ For security concerns, please open an issue at:
309
+ https://github.com/danimesq/claude-code-templates/security
@@ -0,0 +1,152 @@
1
+ /**
2
+ * BaseValidator - Abstract base class for component validation
3
+ *
4
+ * Provides common validation infrastructure and result formatting
5
+ * All validators extend this class and implement the validate() method
6
+ */
7
+ class BaseValidator {
8
+ constructor() {
9
+ this.errors = [];
10
+ this.warnings = [];
11
+ this.info = [];
12
+ }
13
+
14
+ /**
15
+ * Add an error to the validation results
16
+ * @param {string} code - Error code for identification (e.g., STRUCT_E001)
17
+ * @param {string} message - Human-readable error message
18
+ * @param {object} metadata - Additional context about the error
19
+ */
20
+ addError(code, message, metadata = {}) {
21
+ this.errors.push({
22
+ level: 'error',
23
+ code,
24
+ message,
25
+ metadata,
26
+ timestamp: new Date().toISOString()
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Add a warning to the validation results
32
+ * @param {string} code - Warning code for identification
33
+ * @param {string} message - Human-readable warning message
34
+ * @param {object} metadata - Additional context about the warning
35
+ */
36
+ addWarning(code, message, metadata = {}) {
37
+ this.warnings.push({
38
+ level: 'warning',
39
+ code,
40
+ message,
41
+ metadata,
42
+ timestamp: new Date().toISOString()
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Add an info message to the validation results
48
+ * @param {string} code - Info code for identification
49
+ * @param {string} message - Human-readable info message
50
+ * @param {object} metadata - Additional context
51
+ */
52
+ addInfo(code, message, metadata = {}) {
53
+ this.info.push({
54
+ level: 'info',
55
+ code,
56
+ message,
57
+ metadata,
58
+ timestamp: new Date().toISOString()
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Check if validation passed (no errors)
64
+ * @returns {boolean}
65
+ */
66
+ isValid() {
67
+ return this.errors.length === 0;
68
+ }
69
+
70
+ /**
71
+ * Calculate validation score (0-100)
72
+ * Errors reduce score more than warnings
73
+ * @returns {number}
74
+ */
75
+ getScore() {
76
+ const errorPenalty = this.errors.length * 25;
77
+ const warningPenalty = this.warnings.length * 5;
78
+ return Math.max(0, 100 - errorPenalty - warningPenalty);
79
+ }
80
+
81
+ /**
82
+ * Get all validation results
83
+ * @returns {object}
84
+ */
85
+ getResults() {
86
+ return {
87
+ valid: this.isValid(),
88
+ score: this.getScore(),
89
+ errorCount: this.errors.length,
90
+ warningCount: this.warnings.length,
91
+ infoCount: this.info.length,
92
+ errors: this.errors,
93
+ warnings: this.warnings,
94
+ info: this.info
95
+ };
96
+ }
97
+
98
+ /**
99
+ * Reset validation state
100
+ */
101
+ reset() {
102
+ this.errors = [];
103
+ this.warnings = [];
104
+ this.info = [];
105
+ }
106
+
107
+ /**
108
+ * Calculate line number from character index in content
109
+ * @param {string} content - Full content
110
+ * @param {number} index - Character index
111
+ * @returns {object} Line information (line number, column, line text)
112
+ */
113
+ getLineFromIndex(content, index) {
114
+ // Count newlines before the index to get line number
115
+ const beforeIndex = content.substring(0, index);
116
+ const lineNumber = (beforeIndex.match(/\n/g) || []).length + 1;
117
+
118
+ // Find the start of the current line
119
+ const lineStart = beforeIndex.lastIndexOf('\n') + 1;
120
+
121
+ // Find the end of the current line
122
+ const afterIndex = content.substring(index);
123
+ const nextNewline = afterIndex.indexOf('\n');
124
+ const lineEnd = nextNewline === -1 ? content.length : index + nextNewline;
125
+
126
+ // Extract the full line text
127
+ const lineText = content.substring(lineStart, lineEnd);
128
+
129
+ // Calculate column (position in the line)
130
+ const column = index - lineStart + 1;
131
+
132
+ return {
133
+ line: lineNumber,
134
+ column: column,
135
+ lineText: lineText.trim(),
136
+ position: `${lineNumber}:${column}`
137
+ };
138
+ }
139
+
140
+ /**
141
+ * Abstract method - must be implemented by subclasses
142
+ * @param {object} component - Component to validate
143
+ * @param {object} options - Validation options
144
+ * @returns {Promise<object>} Validation results
145
+ * @throws {Error} If not implemented
146
+ */
147
+ async validate(component, options = {}) {
148
+ throw new Error('validate() must be implemented by subclass');
149
+ }
150
+ }
151
+
152
+ module.exports = BaseValidator;