claude-code-workflow 6.3.23 → 6.3.25
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.
- package/.claude/skills/review-code/SKILL.md +170 -0
- package/.claude/skills/review-code/phases/actions/action-collect-context.md +139 -0
- package/.claude/skills/review-code/phases/actions/action-complete.md +115 -0
- package/.claude/skills/review-code/phases/actions/action-deep-review.md +302 -0
- package/.claude/skills/review-code/phases/actions/action-generate-report.md +263 -0
- package/.claude/skills/review-code/phases/actions/action-quick-scan.md +164 -0
- package/.claude/skills/review-code/phases/orchestrator.md +251 -0
- package/.claude/skills/review-code/phases/state-manager.md +752 -0
- package/.claude/skills/review-code/phases/state-schema.md +174 -0
- package/.claude/skills/review-code/specs/issue-classification.md +228 -0
- package/.claude/skills/review-code/specs/quality-standards.md +214 -0
- package/.claude/skills/review-code/specs/review-dimensions.md +337 -0
- package/.claude/skills/review-code/specs/rules/architecture-rules.json +63 -0
- package/.claude/skills/review-code/specs/rules/correctness-rules.json +60 -0
- package/.claude/skills/review-code/specs/rules/index.md +140 -0
- package/.claude/skills/review-code/specs/rules/performance-rules.json +59 -0
- package/.claude/skills/review-code/specs/rules/readability-rules.json +60 -0
- package/.claude/skills/review-code/specs/rules/security-rules.json +58 -0
- package/.claude/skills/review-code/specs/rules/testing-rules.json +59 -0
- package/.claude/skills/review-code/templates/issue-template.md +186 -0
- package/.claude/skills/review-code/templates/review-report.md +173 -0
- package/.claude/skills/skill-generator/SKILL.md +56 -17
- package/.claude/skills/skill-generator/templates/autonomous-orchestrator.md +10 -0
- package/.claude/skills/skill-generator/templates/sequential-phase.md +9 -0
- package/.claude/skills/skill-generator/templates/skill-md.md +84 -5
- package/.claude/skills/text-formatter/SKILL.md +196 -0
- package/.claude/skills/text-formatter/phases/01-input-collection.md +111 -0
- package/.claude/skills/text-formatter/phases/02-content-analysis.md +248 -0
- package/.claude/skills/text-formatter/phases/03-format-transform.md +245 -0
- package/.claude/skills/text-formatter/phases/04-output-preview.md +183 -0
- package/.claude/skills/text-formatter/specs/callout-types.md +293 -0
- package/.claude/skills/text-formatter/specs/element-mapping.md +226 -0
- package/.claude/skills/text-formatter/specs/format-rules.md +273 -0
- package/.claude/skills/text-formatter/templates/bbcode-template.md +350 -0
- package/package.json +91 -91
- package/.claude/skills/code-reviewer/README.md +0 -340
- package/.claude/skills/code-reviewer/SKILL.md +0 -308
- package/.claude/skills/code-reviewer/phases/01-code-discovery.md +0 -246
- package/.claude/skills/code-reviewer/phases/02-security-analysis.md +0 -442
- package/.claude/skills/code-reviewer/phases/03-best-practices-review.md +0 -36
- package/.claude/skills/code-reviewer/phases/04-report-generation.md +0 -278
- package/.claude/skills/code-reviewer/specs/best-practices-requirements.md +0 -346
- package/.claude/skills/code-reviewer/specs/quality-standards.md +0 -252
- package/.claude/skills/code-reviewer/specs/security-requirements.md +0 -243
- package/.claude/skills/code-reviewer/templates/best-practice-finding.md +0 -234
- package/.claude/skills/code-reviewer/templates/report-template.md +0 -316
- package/.claude/skills/code-reviewer/templates/security-finding.md +0 -161
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
# Phase 1: Code Discovery & Scoping
|
|
2
|
-
|
|
3
|
-
## Objective
|
|
4
|
-
|
|
5
|
-
Discover and categorize all code files within the specified scope, preparing them for security analysis and best practices review.
|
|
6
|
-
|
|
7
|
-
## Input
|
|
8
|
-
|
|
9
|
-
- **User Arguments**:
|
|
10
|
-
- `--scope`: Directory or file patterns (default: entire project)
|
|
11
|
-
- `--languages`: Specific languages to review (e.g., typescript, python, java)
|
|
12
|
-
- `--exclude`: Patterns to exclude (e.g., test files, node_modules)
|
|
13
|
-
|
|
14
|
-
- **Configuration**: `.code-reviewer.json` (if exists)
|
|
15
|
-
|
|
16
|
-
## Process
|
|
17
|
-
|
|
18
|
-
### Step 1: Load Configuration
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
// Check for project-level configuration
|
|
22
|
-
const configPath = path.join(projectRoot, '.code-reviewer.json');
|
|
23
|
-
const config = fileExists(configPath)
|
|
24
|
-
? JSON.parse(readFile(configPath))
|
|
25
|
-
: getDefaultConfig();
|
|
26
|
-
|
|
27
|
-
// Merge user arguments with config
|
|
28
|
-
const scope = args.scope || config.scope.include;
|
|
29
|
-
const exclude = args.exclude || config.scope.exclude;
|
|
30
|
-
const languages = args.languages || config.languages || 'auto';
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Step 2: Discover Files
|
|
34
|
-
|
|
35
|
-
Use MCP tools for efficient file discovery:
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
// Use smart_search for file discovery
|
|
39
|
-
const files = await mcp__ccw_tools__smart_search({
|
|
40
|
-
action: "find_files",
|
|
41
|
-
pattern: scope,
|
|
42
|
-
includeHidden: false
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Apply exclusion patterns
|
|
46
|
-
const filteredFiles = files.filter(file => {
|
|
47
|
-
return !exclude.some(pattern => minimatch(file, pattern));
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Step 3: Categorize Files
|
|
52
|
-
|
|
53
|
-
Categorize files by:
|
|
54
|
-
- **Language/Framework**: TypeScript, Python, Java, Go, etc.
|
|
55
|
-
- **File Type**: Source, config, test, build
|
|
56
|
-
- **Priority**: Critical (auth, payment), High (API), Medium (utils), Low (docs)
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
const inventory = {
|
|
60
|
-
critical: {
|
|
61
|
-
auth: ['src/auth/login.ts', 'src/auth/jwt.ts'],
|
|
62
|
-
payment: ['src/payment/stripe.ts'],
|
|
63
|
-
},
|
|
64
|
-
high: {
|
|
65
|
-
api: ['src/api/users.ts', 'src/api/orders.ts'],
|
|
66
|
-
database: ['src/db/queries.ts'],
|
|
67
|
-
},
|
|
68
|
-
medium: {
|
|
69
|
-
utils: ['src/utils/validator.ts'],
|
|
70
|
-
services: ['src/services/*.ts'],
|
|
71
|
-
},
|
|
72
|
-
low: {
|
|
73
|
-
types: ['src/types/*.ts'],
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Step 4: Extract Metadata
|
|
79
|
-
|
|
80
|
-
For each file, extract:
|
|
81
|
-
- **Lines of Code (LOC)**
|
|
82
|
-
- **Complexity Indicators**: Function count, class count
|
|
83
|
-
- **Dependencies**: Import statements
|
|
84
|
-
- **Framework Detection**: Express, React, Django, etc.
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
const metadata = files.map(file => ({
|
|
88
|
-
path: file,
|
|
89
|
-
language: detectLanguage(file),
|
|
90
|
-
loc: countLines(file),
|
|
91
|
-
complexity: estimateComplexity(file),
|
|
92
|
-
framework: detectFramework(file),
|
|
93
|
-
priority: categorizePriority(file)
|
|
94
|
-
}));
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Output
|
|
98
|
-
|
|
99
|
-
### File Inventory
|
|
100
|
-
|
|
101
|
-
Save to `.code-review/inventory.json`:
|
|
102
|
-
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"scan_date": "2024-01-15T10:30:00Z",
|
|
106
|
-
"total_files": 247,
|
|
107
|
-
"by_language": {
|
|
108
|
-
"typescript": 185,
|
|
109
|
-
"python": 42,
|
|
110
|
-
"javascript": 15,
|
|
111
|
-
"go": 5
|
|
112
|
-
},
|
|
113
|
-
"by_priority": {
|
|
114
|
-
"critical": 12,
|
|
115
|
-
"high": 45,
|
|
116
|
-
"medium": 120,
|
|
117
|
-
"low": 70
|
|
118
|
-
},
|
|
119
|
-
"files": [
|
|
120
|
-
{
|
|
121
|
-
"path": "src/auth/login.ts",
|
|
122
|
-
"language": "typescript",
|
|
123
|
-
"loc": 245,
|
|
124
|
-
"functions": 8,
|
|
125
|
-
"classes": 2,
|
|
126
|
-
"priority": "critical",
|
|
127
|
-
"framework": "express",
|
|
128
|
-
"dependencies": ["bcrypt", "jsonwebtoken", "express"]
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Summary Report
|
|
135
|
-
|
|
136
|
-
```markdown
|
|
137
|
-
## Code Discovery Summary
|
|
138
|
-
|
|
139
|
-
**Scope**: src/**/*
|
|
140
|
-
**Total Files**: 247
|
|
141
|
-
**Languages**: TypeScript (75%), Python (17%), JavaScript (6%), Go (2%)
|
|
142
|
-
|
|
143
|
-
### Priority Distribution
|
|
144
|
-
- Critical: 12 files (authentication, payment processing)
|
|
145
|
-
- High: 45 files (API endpoints, database queries)
|
|
146
|
-
- Medium: 120 files (utilities, services)
|
|
147
|
-
- Low: 70 files (types, configs)
|
|
148
|
-
|
|
149
|
-
### Key Areas Identified
|
|
150
|
-
1. **Authentication Module** (src/auth/) - 12 files, 2,400 LOC
|
|
151
|
-
2. **Payment Processing** (src/payment/) - 5 files, 1,200 LOC
|
|
152
|
-
3. **API Layer** (src/api/) - 35 files, 5,600 LOC
|
|
153
|
-
4. **Database Layer** (src/db/) - 8 files, 1,800 LOC
|
|
154
|
-
|
|
155
|
-
**Next Phase**: Security Analysis on Critical + High priority files
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## State Management
|
|
159
|
-
|
|
160
|
-
Save phase state for potential resume:
|
|
161
|
-
|
|
162
|
-
```json
|
|
163
|
-
{
|
|
164
|
-
"phase": "01-code-discovery",
|
|
165
|
-
"status": "completed",
|
|
166
|
-
"timestamp": "2024-01-15T10:35:00Z",
|
|
167
|
-
"output": {
|
|
168
|
-
"inventory_path": ".code-review/inventory.json",
|
|
169
|
-
"total_files": 247,
|
|
170
|
-
"critical_files": 12,
|
|
171
|
-
"high_files": 45
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Agent Instructions
|
|
177
|
-
|
|
178
|
-
```markdown
|
|
179
|
-
You are in Phase 1 of the Code Review workflow. Your task is to discover and categorize code files.
|
|
180
|
-
|
|
181
|
-
**Instructions**:
|
|
182
|
-
1. Use mcp__ccw_tools__smart_search with action="find_files" to discover files
|
|
183
|
-
2. Apply exclusion patterns from config or arguments
|
|
184
|
-
3. Categorize files by language, type, and priority
|
|
185
|
-
4. Extract basic metadata (LOC, complexity indicators)
|
|
186
|
-
5. Save inventory to .code-review/inventory.json
|
|
187
|
-
6. Generate summary report
|
|
188
|
-
7. Proceed to Phase 2 with critical + high priority files
|
|
189
|
-
|
|
190
|
-
**Tools Available**:
|
|
191
|
-
- mcp__ccw_tools__smart_search (file discovery)
|
|
192
|
-
- Read (read configuration and sample files)
|
|
193
|
-
- Write (save inventory and reports)
|
|
194
|
-
|
|
195
|
-
**Output Requirements**:
|
|
196
|
-
- inventory.json with complete file list and metadata
|
|
197
|
-
- Summary markdown report
|
|
198
|
-
- State file for phase tracking
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## Error Handling
|
|
202
|
-
|
|
203
|
-
### No Files Found
|
|
204
|
-
|
|
205
|
-
```javascript
|
|
206
|
-
if (filteredFiles.length === 0) {
|
|
207
|
-
throw new Error(`No files found matching scope: ${scope}
|
|
208
|
-
|
|
209
|
-
Suggestions:
|
|
210
|
-
- Check if scope pattern is correct
|
|
211
|
-
- Verify exclude patterns are not too broad
|
|
212
|
-
- Ensure project has code files in specified scope
|
|
213
|
-
`);
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Large Codebase
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
if (filteredFiles.length > 1000) {
|
|
221
|
-
console.warn(`⚠️ Large codebase detected (${filteredFiles.length} files)`);
|
|
222
|
-
console.log(`Consider using --scope to review in batches`);
|
|
223
|
-
|
|
224
|
-
// Offer to focus on critical/high priority only
|
|
225
|
-
const answer = await askUser("Review critical/high priority files only?");
|
|
226
|
-
if (answer === 'yes') {
|
|
227
|
-
filteredFiles = filteredFiles.filter(f =>
|
|
228
|
-
f.priority === 'critical' || f.priority === 'high'
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Validation
|
|
235
|
-
|
|
236
|
-
Before proceeding to Phase 2:
|
|
237
|
-
|
|
238
|
-
- ✅ Inventory file created
|
|
239
|
-
- ✅ At least one file categorized as critical or high priority
|
|
240
|
-
- ✅ Metadata extracted for all files
|
|
241
|
-
- ✅ Summary report generated
|
|
242
|
-
- ✅ State saved for resume capability
|
|
243
|
-
|
|
244
|
-
## Next Phase
|
|
245
|
-
|
|
246
|
-
**Phase 2: Security Analysis** - Analyze critical and high priority files for security vulnerabilities using OWASP Top 10 and CWE Top 25 checks.
|
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
# Phase 2: Security Analysis
|
|
2
|
-
|
|
3
|
-
## Objective
|
|
4
|
-
|
|
5
|
-
Analyze code files for security vulnerabilities based on OWASP Top 10, CWE Top 25, and language-specific security patterns.
|
|
6
|
-
|
|
7
|
-
## Input
|
|
8
|
-
|
|
9
|
-
- **File Inventory**: From Phase 1 (`.code-review/inventory.json`)
|
|
10
|
-
- **Priority Focus**: Critical and High priority files (unless `--scope all`)
|
|
11
|
-
- **User Arguments**:
|
|
12
|
-
- `--focus security`: Security-only mode
|
|
13
|
-
- `--severity critical,high,medium,low`: Minimum severity to report
|
|
14
|
-
- `--checks`: Specific security checks to run (e.g., sql-injection, xss)
|
|
15
|
-
|
|
16
|
-
## Process
|
|
17
|
-
|
|
18
|
-
### Step 1: Load Security Rules
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
// Load security check definitions
|
|
22
|
-
const securityRules = {
|
|
23
|
-
owasp_top_10: [
|
|
24
|
-
'injection',
|
|
25
|
-
'broken_authentication',
|
|
26
|
-
'sensitive_data_exposure',
|
|
27
|
-
'xxe',
|
|
28
|
-
'broken_access_control',
|
|
29
|
-
'security_misconfiguration',
|
|
30
|
-
'xss',
|
|
31
|
-
'insecure_deserialization',
|
|
32
|
-
'vulnerable_components',
|
|
33
|
-
'insufficient_logging'
|
|
34
|
-
],
|
|
35
|
-
cwe_top_25: [
|
|
36
|
-
'cwe-79', // XSS
|
|
37
|
-
'cwe-89', // SQL Injection
|
|
38
|
-
'cwe-20', // Improper Input Validation
|
|
39
|
-
'cwe-78', // OS Command Injection
|
|
40
|
-
'cwe-190', // Integer Overflow
|
|
41
|
-
// ... more CWE checks
|
|
42
|
-
]
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Load language-specific rules
|
|
46
|
-
const languageRules = {
|
|
47
|
-
typescript: require('./rules/typescript-security.json'),
|
|
48
|
-
python: require('./rules/python-security.json'),
|
|
49
|
-
java: require('./rules/java-security.json'),
|
|
50
|
-
go: require('./rules/go-security.json'),
|
|
51
|
-
};
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Step 2: Analyze Files for Vulnerabilities
|
|
55
|
-
|
|
56
|
-
For each file in the inventory, perform security analysis:
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
const findings = [];
|
|
60
|
-
|
|
61
|
-
for (const file of inventory.files) {
|
|
62
|
-
if (file.priority !== 'critical' && file.priority !== 'high') continue;
|
|
63
|
-
|
|
64
|
-
// Read file content
|
|
65
|
-
const content = await Read({ file_path: file.path });
|
|
66
|
-
|
|
67
|
-
// Run security checks
|
|
68
|
-
const fileFindings = await runSecurityChecks(content, file, {
|
|
69
|
-
rules: securityRules,
|
|
70
|
-
languageRules: languageRules[file.language],
|
|
71
|
-
severity: args.severity || 'medium'
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
findings.push(...fileFindings);
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Step 3: Security Check Patterns
|
|
79
|
-
|
|
80
|
-
#### A. Injection Vulnerabilities
|
|
81
|
-
|
|
82
|
-
**SQL Injection**:
|
|
83
|
-
```javascript
|
|
84
|
-
// Pattern: String concatenation in SQL queries
|
|
85
|
-
const sqlInjectionPatterns = [
|
|
86
|
-
/\$\{.*\}.*SELECT/, // Template literal with SELECT
|
|
87
|
-
/"SELECT.*\+\s*\w+/, // String concatenation
|
|
88
|
-
/execute\([`'"].*\$\{.*\}.*[`'"]\)/, // Parameterized query bypass
|
|
89
|
-
/query\(.*\+.*\)/, // Query concatenation
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
// Check code
|
|
93
|
-
for (const pattern of sqlInjectionPatterns) {
|
|
94
|
-
const matches = content.matchAll(new RegExp(pattern, 'g'));
|
|
95
|
-
for (const match of matches) {
|
|
96
|
-
findings.push({
|
|
97
|
-
type: 'sql-injection',
|
|
98
|
-
severity: 'critical',
|
|
99
|
-
line: getLineNumber(content, match.index),
|
|
100
|
-
code: match[0],
|
|
101
|
-
file: file.path,
|
|
102
|
-
message: 'Potential SQL injection vulnerability',
|
|
103
|
-
recommendation: 'Use parameterized queries or ORM methods',
|
|
104
|
-
cwe: 'CWE-89',
|
|
105
|
-
owasp: 'A03:2021 - Injection'
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
**Command Injection**:
|
|
112
|
-
```javascript
|
|
113
|
-
// Pattern: Unsanitized input in exec/spawn
|
|
114
|
-
const commandInjectionPatterns = [
|
|
115
|
-
/exec\(.*\$\{.*\}/, // exec with template literal
|
|
116
|
-
/spawn\(.*,\s*\[.*\$\{.*\}.*\]\)/, // spawn with unsanitized args
|
|
117
|
-
/execSync\(.*\+.*\)/, // execSync with concatenation
|
|
118
|
-
];
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
**XSS (Cross-Site Scripting)**:
|
|
122
|
-
```javascript
|
|
123
|
-
// Pattern: Unsanitized user input in DOM/HTML
|
|
124
|
-
const xssPatterns = [
|
|
125
|
-
/innerHTML\s*=.*\$\{.*\}/, // innerHTML with template literal
|
|
126
|
-
/dangerouslySetInnerHTML/, // React dangerous prop
|
|
127
|
-
/document\.write\(.*\)/, // document.write
|
|
128
|
-
/<\w+.*\$\{.*\}.*>/, // JSX with unsanitized data
|
|
129
|
-
];
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### B. Authentication & Authorization
|
|
133
|
-
|
|
134
|
-
```javascript
|
|
135
|
-
// Pattern: Weak authentication
|
|
136
|
-
const authPatterns = [
|
|
137
|
-
/password\s*===?\s*['"]/, // Hardcoded password comparison
|
|
138
|
-
/jwt\.sign\(.*,\s*['"][^'"]{1,16}['"]\)/, // Weak JWT secret
|
|
139
|
-
/bcrypt\.hash\(.*,\s*[1-9]\s*\)/, // Low bcrypt rounds
|
|
140
|
-
/md5\(.*password.*\)/, // MD5 for passwords
|
|
141
|
-
/if\s*\(\s*user\s*\)\s*\{/, // Missing auth check
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
// Check for missing authorization
|
|
145
|
-
const authzPatterns = [
|
|
146
|
-
/router\.(get|post|put|delete)\(.*\)\s*=>/, // No middleware
|
|
147
|
-
/app\.use\([^)]*\)\s*;(?!.*auth)/, // Missing auth middleware
|
|
148
|
-
];
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### C. Sensitive Data Exposure
|
|
152
|
-
|
|
153
|
-
```javascript
|
|
154
|
-
// Pattern: Sensitive data in logs/responses
|
|
155
|
-
const sensitiveDataPatterns = [
|
|
156
|
-
/(password|secret|token|key)\s*:/i, // Sensitive keys in objects
|
|
157
|
-
/console\.log\(.*password.*\)/i, // Password in logs
|
|
158
|
-
/res\.send\(.*user.*password.*\)/, // Password in response
|
|
159
|
-
/(api_key|apikey)\s*=\s*['"]/i, // Hardcoded API keys
|
|
160
|
-
];
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
#### D. Security Misconfiguration
|
|
164
|
-
|
|
165
|
-
```javascript
|
|
166
|
-
// Pattern: Insecure configurations
|
|
167
|
-
const misconfigPatterns = [
|
|
168
|
-
/cors\(\{.*origin:\s*['"]?\*['"]?.*\}\)/, // CORS wildcard
|
|
169
|
-
/https?\s*:\s*false/, // HTTPS disabled
|
|
170
|
-
/helmet\(\)/, // Missing helmet config
|
|
171
|
-
/strictMode\s*:\s*false/, // Strict mode disabled
|
|
172
|
-
];
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Step 4: Language-Specific Checks
|
|
176
|
-
|
|
177
|
-
**TypeScript/JavaScript**:
|
|
178
|
-
```javascript
|
|
179
|
-
const jsFindings = [
|
|
180
|
-
checkPrototypePollution(content),
|
|
181
|
-
checkEvalUsage(content),
|
|
182
|
-
checkUnsafeRegex(content),
|
|
183
|
-
checkWeakCrypto(content),
|
|
184
|
-
];
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**Python**:
|
|
188
|
-
```javascript
|
|
189
|
-
const pythonFindings = [
|
|
190
|
-
checkPickleVulnerabilities(content),
|
|
191
|
-
checkYamlUnsafeLoad(content),
|
|
192
|
-
checkSqlAlchemy(content),
|
|
193
|
-
checkFlaskSecurityHeaders(content),
|
|
194
|
-
];
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
**Java**:
|
|
198
|
-
```javascript
|
|
199
|
-
const javaFindings = [
|
|
200
|
-
checkDeserialization(content),
|
|
201
|
-
checkXXE(content),
|
|
202
|
-
checkPathTraversal(content),
|
|
203
|
-
checkSQLInjection(content),
|
|
204
|
-
];
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
**Go**:
|
|
208
|
-
```javascript
|
|
209
|
-
const goFindings = [
|
|
210
|
-
checkRaceConditions(content),
|
|
211
|
-
checkSQLInjection(content),
|
|
212
|
-
checkPathTraversal(content),
|
|
213
|
-
checkCryptoWeakness(content),
|
|
214
|
-
];
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Output
|
|
218
|
-
|
|
219
|
-
### Security Findings File
|
|
220
|
-
|
|
221
|
-
Save to `.code-review/security-findings.json`:
|
|
222
|
-
|
|
223
|
-
```json
|
|
224
|
-
{
|
|
225
|
-
"scan_date": "2024-01-15T11:00:00Z",
|
|
226
|
-
"total_findings": 24,
|
|
227
|
-
"by_severity": {
|
|
228
|
-
"critical": 3,
|
|
229
|
-
"high": 8,
|
|
230
|
-
"medium": 10,
|
|
231
|
-
"low": 3
|
|
232
|
-
},
|
|
233
|
-
"by_category": {
|
|
234
|
-
"injection": 5,
|
|
235
|
-
"authentication": 3,
|
|
236
|
-
"data_exposure": 4,
|
|
237
|
-
"misconfiguration": 6,
|
|
238
|
-
"xss": 3,
|
|
239
|
-
"other": 3
|
|
240
|
-
},
|
|
241
|
-
"findings": [
|
|
242
|
-
{
|
|
243
|
-
"id": "SEC-001",
|
|
244
|
-
"type": "sql-injection",
|
|
245
|
-
"severity": "critical",
|
|
246
|
-
"file": "src/auth/user-service.ts",
|
|
247
|
-
"line": 145,
|
|
248
|
-
"column": 12,
|
|
249
|
-
"code": "const query = `SELECT * FROM users WHERE username = '${username}'`;",
|
|
250
|
-
"message": "SQL Injection vulnerability: User input directly concatenated in SQL query",
|
|
251
|
-
"cwe": "CWE-89",
|
|
252
|
-
"owasp": "A03:2021 - Injection",
|
|
253
|
-
"recommendation": {
|
|
254
|
-
"description": "Use parameterized queries to prevent SQL injection",
|
|
255
|
-
"fix_example": "const query = 'SELECT * FROM users WHERE username = ?';\ndb.execute(query, [username]);"
|
|
256
|
-
},
|
|
257
|
-
"references": [
|
|
258
|
-
"https://owasp.org/www-community/attacks/SQL_Injection",
|
|
259
|
-
"https://cwe.mitre.org/data/definitions/89.html"
|
|
260
|
-
]
|
|
261
|
-
}
|
|
262
|
-
]
|
|
263
|
-
}
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### Security Report
|
|
267
|
-
|
|
268
|
-
Generate markdown report:
|
|
269
|
-
|
|
270
|
-
```markdown
|
|
271
|
-
# Security Analysis Report
|
|
272
|
-
|
|
273
|
-
**Scan Date**: 2024-01-15 11:00:00
|
|
274
|
-
**Files Analyzed**: 57 (Critical + High priority)
|
|
275
|
-
**Total Findings**: 24
|
|
276
|
-
|
|
277
|
-
## Severity Summary
|
|
278
|
-
|
|
279
|
-
| Severity | Count | Percentage |
|
|
280
|
-
|----------|-------|------------|
|
|
281
|
-
| Critical | 3 | 12.5% |
|
|
282
|
-
| High | 8 | 33.3% |
|
|
283
|
-
| Medium | 10 | 41.7% |
|
|
284
|
-
| Low | 3 | 12.5% |
|
|
285
|
-
|
|
286
|
-
## Critical Findings (Requires Immediate Action)
|
|
287
|
-
|
|
288
|
-
### 🔴 [SEC-001] SQL Injection in User Authentication
|
|
289
|
-
|
|
290
|
-
**File**: `src/auth/user-service.ts:145`
|
|
291
|
-
**CWE**: CWE-89 | **OWASP**: A03:2021 - Injection
|
|
292
|
-
|
|
293
|
-
**Vulnerable Code**:
|
|
294
|
-
\`\`\`typescript
|
|
295
|
-
const query = \`SELECT * FROM users WHERE username = '\${username}'\`;
|
|
296
|
-
const user = await db.execute(query);
|
|
297
|
-
\`\`\`
|
|
298
|
-
|
|
299
|
-
**Issue**: User input (`username`) is directly concatenated into SQL query, allowing attackers to inject malicious SQL commands.
|
|
300
|
-
|
|
301
|
-
**Attack Example**:
|
|
302
|
-
\`\`\`
|
|
303
|
-
username: ' OR '1'='1' --
|
|
304
|
-
Result: SELECT * FROM users WHERE username = '' OR '1'='1' --'
|
|
305
|
-
Effect: Bypasses authentication, returns all users
|
|
306
|
-
\`\`\`
|
|
307
|
-
|
|
308
|
-
**Recommended Fix**:
|
|
309
|
-
\`\`\`typescript
|
|
310
|
-
// Use parameterized queries
|
|
311
|
-
const query = 'SELECT * FROM users WHERE username = ?';
|
|
312
|
-
const user = await db.execute(query, [username]);
|
|
313
|
-
|
|
314
|
-
// Or use ORM
|
|
315
|
-
const user = await User.findOne({ where: { username } });
|
|
316
|
-
\`\`\`
|
|
317
|
-
|
|
318
|
-
**References**:
|
|
319
|
-
- [OWASP SQL Injection](https://owasp.org/www-community/attacks/SQL_Injection)
|
|
320
|
-
- [CWE-89](https://cwe.mitre.org/data/definitions/89.html)
|
|
321
|
-
|
|
322
|
-
---
|
|
323
|
-
|
|
324
|
-
### 🔴 [SEC-002] Hardcoded JWT Secret
|
|
325
|
-
|
|
326
|
-
**File**: `src/auth/jwt.ts:23`
|
|
327
|
-
**CWE**: CWE-798 | **OWASP**: A07:2021 - Identification and Authentication Failures
|
|
328
|
-
|
|
329
|
-
**Vulnerable Code**:
|
|
330
|
-
\`\`\`typescript
|
|
331
|
-
const token = jwt.sign(payload, 'mysecret123', { expiresIn: '1h' });
|
|
332
|
-
\`\`\`
|
|
333
|
-
|
|
334
|
-
**Issue**: JWT secret is hardcoded and weak (only 11 characters).
|
|
335
|
-
|
|
336
|
-
**Recommended Fix**:
|
|
337
|
-
\`\`\`typescript
|
|
338
|
-
// Use environment variable with strong secret
|
|
339
|
-
const token = jwt.sign(payload, process.env.JWT_SECRET, {
|
|
340
|
-
expiresIn: '1h',
|
|
341
|
-
algorithm: 'HS256'
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
// Generate strong secret (32+ bytes):
|
|
345
|
-
// node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
346
|
-
\`\`\`
|
|
347
|
-
|
|
348
|
-
---
|
|
349
|
-
|
|
350
|
-
## High Findings
|
|
351
|
-
|
|
352
|
-
### 🟠 [SEC-003] Missing Input Validation
|
|
353
|
-
|
|
354
|
-
**File**: `src/api/users.ts:67`
|
|
355
|
-
**CWE**: CWE-20 | **OWASP**: A03:2021 - Injection
|
|
356
|
-
|
|
357
|
-
...
|
|
358
|
-
|
|
359
|
-
## Medium Findings
|
|
360
|
-
|
|
361
|
-
...
|
|
362
|
-
|
|
363
|
-
## Remediation Priority
|
|
364
|
-
|
|
365
|
-
1. **Critical (3)**: Fix within 24 hours
|
|
366
|
-
2. **High (8)**: Fix within 1 week
|
|
367
|
-
3. **Medium (10)**: Fix within 1 month
|
|
368
|
-
4. **Low (3)**: Fix in next release
|
|
369
|
-
|
|
370
|
-
## Compliance Impact
|
|
371
|
-
|
|
372
|
-
- **PCI DSS**: 4 findings affect compliance (SEC-001, SEC-002, SEC-008, SEC-011)
|
|
373
|
-
- **HIPAA**: 2 findings affect compliance (SEC-005, SEC-009)
|
|
374
|
-
- **GDPR**: 3 findings affect compliance (SEC-002, SEC-005, SEC-007)
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
## State Management
|
|
378
|
-
|
|
379
|
-
```json
|
|
380
|
-
{
|
|
381
|
-
"phase": "02-security-analysis",
|
|
382
|
-
"status": "completed",
|
|
383
|
-
"timestamp": "2024-01-15T11:15:00Z",
|
|
384
|
-
"input": {
|
|
385
|
-
"inventory_path": ".code-review/inventory.json",
|
|
386
|
-
"files_analyzed": 57
|
|
387
|
-
},
|
|
388
|
-
"output": {
|
|
389
|
-
"findings_path": ".code-review/security-findings.json",
|
|
390
|
-
"total_findings": 24,
|
|
391
|
-
"critical_count": 3,
|
|
392
|
-
"high_count": 8
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
## Agent Instructions
|
|
398
|
-
|
|
399
|
-
```markdown
|
|
400
|
-
You are in Phase 2 of the Code Review workflow. Your task is to analyze code for security vulnerabilities.
|
|
401
|
-
|
|
402
|
-
**Instructions**:
|
|
403
|
-
1. Load file inventory from Phase 1
|
|
404
|
-
2. Focus on Critical + High priority files
|
|
405
|
-
3. Run security checks for:
|
|
406
|
-
- OWASP Top 10 vulnerabilities
|
|
407
|
-
- CWE Top 25 weaknesses
|
|
408
|
-
- Language-specific security patterns
|
|
409
|
-
4. Use smart_search with mode="ripgrep" for pattern matching
|
|
410
|
-
5. Use mcp__ace-tool__search_context for semantic security pattern discovery
|
|
411
|
-
6. Classify findings by severity (Critical/High/Medium/Low)
|
|
412
|
-
7. Generate security-findings.json and markdown report
|
|
413
|
-
8. Proceed to Phase 3 (Best Practices Review)
|
|
414
|
-
|
|
415
|
-
**Tools Available**:
|
|
416
|
-
- mcp__ccw_tools__smart_search (pattern search)
|
|
417
|
-
- mcp__ace-tool__search_context (semantic search)
|
|
418
|
-
- Read (read file content)
|
|
419
|
-
- Write (save findings and reports)
|
|
420
|
-
- Grep (targeted pattern matching)
|
|
421
|
-
|
|
422
|
-
**Output Requirements**:
|
|
423
|
-
- security-findings.json with detailed findings
|
|
424
|
-
- Security report in markdown format
|
|
425
|
-
- Each finding must include: file, line, severity, CWE, OWASP, fix recommendation
|
|
426
|
-
- State file for phase tracking
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## Validation
|
|
430
|
-
|
|
431
|
-
Before proceeding to Phase 3:
|
|
432
|
-
|
|
433
|
-
- ✅ All Critical + High priority files analyzed
|
|
434
|
-
- ✅ Findings categorized by severity
|
|
435
|
-
- ✅ Each finding has fix recommendation
|
|
436
|
-
- ✅ CWE and OWASP mappings included
|
|
437
|
-
- ✅ Security report generated
|
|
438
|
-
- ✅ State saved
|
|
439
|
-
|
|
440
|
-
## Next Phase
|
|
441
|
-
|
|
442
|
-
**Phase 3: Best Practices Review** - Analyze code quality, performance, and maintainability issues.
|