codeprobe-scanner 1.0.20 ā 1.0.22
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/README.md +367 -131
- package/package.json +1 -1
- package/src/cli/commands/scan.ts +67 -2
package/README.md
CHANGED
|
@@ -1,156 +1,381 @@
|
|
|
1
|
-
# CodeProbe
|
|
1
|
+
# CodeProbe Scanner š
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Full-stack vulnerability scanner with automatic code fixing and Kimi AI patch generation.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
CodeProbe is an advanced security scanner that analyzes both your npm dependencies AND your actual source code to find and automatically fix security vulnerabilities. It combines CVE detection, SAST analysis, and AI-powered patch generation into one unified tool.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## ⨠Key Features
|
|
8
|
+
|
|
9
|
+
### š Dual-Layer Vulnerability Detection
|
|
10
|
+
- **Dependency Scanning** ā Checks npm packages against OSV.dev + npm advisory databases
|
|
11
|
+
- **Source Code Analysis (SAST)** ā Scans actual code for 7+ vulnerability patterns
|
|
12
|
+
|
|
13
|
+
### š Detects & Fixes
|
|
14
|
+
- Hardcoded secrets ā Replaced with `process.env`
|
|
15
|
+
- SQL injection patterns
|
|
16
|
+
- Command injection vulnerabilities
|
|
17
|
+
- XSS vulnerabilities
|
|
18
|
+
- Path traversal issues
|
|
19
|
+
- Insecure random generation
|
|
20
|
+
- Insecure eval/Function() usage
|
|
21
|
+
|
|
22
|
+
### š§ Automatic Fixing
|
|
23
|
+
- **Source Code Fixes** ā Repairs vulnerabilities in your code automatically
|
|
24
|
+
- **Package Updates** ā Suggests and applies secure versions
|
|
25
|
+
- **Kimi LLM Integration** ā Generates intelligent patches using AI
|
|
26
|
+
|
|
27
|
+
### šļø Recursive Scanning
|
|
28
|
+
- Automatically finds all `package.json` files in subdirectories
|
|
29
|
+
- Perfect for monorepos and multi-package projects
|
|
30
|
+
- Aggregates results across all packages
|
|
31
|
+
|
|
32
|
+
### š Comprehensive Reporting
|
|
33
|
+
- Risk score calculation (0-10)
|
|
34
|
+
- CVE severity and exploitability
|
|
35
|
+
- Proof-of-concept recordings
|
|
36
|
+
- Recent security threat alerts
|
|
37
|
+
|
|
38
|
+
## š Installation
|
|
39
|
+
|
|
40
|
+
### Global Installation
|
|
41
|
+
```bash
|
|
8
42
|
npm install -g codeprobe-scanner
|
|
9
43
|
```
|
|
10
44
|
|
|
11
|
-
|
|
45
|
+
### Project Installation
|
|
46
|
+
```bash
|
|
47
|
+
npm install --save-dev codeprobe-scanner
|
|
48
|
+
```
|
|
12
49
|
|
|
13
|
-
|
|
14
|
-
|
|
50
|
+
### Run Without Installing
|
|
51
|
+
```bash
|
|
52
|
+
npx codeprobe-scanner scan .
|
|
15
53
|
```
|
|
16
54
|
|
|
17
|
-
## Quick Start
|
|
55
|
+
## ā” Quick Start
|
|
18
56
|
|
|
19
|
-
|
|
20
|
-
# Scan the current directory
|
|
21
|
-
codeprobe scan
|
|
57
|
+
### 1. Set Up Kimi API (Recommended)
|
|
22
58
|
|
|
23
|
-
|
|
24
|
-
codeprobe scan ./my-app
|
|
59
|
+
Get your API key from [Kimi Platform](https://kimi.moonshot.cn):
|
|
25
60
|
|
|
26
|
-
|
|
27
|
-
|
|
61
|
+
```bash
|
|
62
|
+
# Option A: CLI Configuration
|
|
63
|
+
codeprobe config set kimi_api_key sk-YOUR_KEY_HERE
|
|
28
64
|
|
|
29
|
-
#
|
|
30
|
-
|
|
65
|
+
# Option B: Environment Variable
|
|
66
|
+
export KIMI_API_KEY=sk-YOUR_KEY_HERE
|
|
31
67
|
|
|
32
|
-
#
|
|
33
|
-
codeprobe
|
|
68
|
+
# Option C: Manual Configuration
|
|
69
|
+
# Edit ~/.codeprobe/config.json and add your key
|
|
34
70
|
```
|
|
35
71
|
|
|
36
|
-
|
|
72
|
+
### 2. Scan Your Project
|
|
37
73
|
|
|
38
|
-
|
|
74
|
+
**Find vulnerabilities:**
|
|
75
|
+
```bash
|
|
76
|
+
codeprobe scan .
|
|
77
|
+
```
|
|
39
78
|
|
|
40
|
-
|
|
79
|
+
**Find AND fix vulnerabilities:**
|
|
80
|
+
```bash
|
|
81
|
+
codeprobe scan . --fix
|
|
82
|
+
```
|
|
41
83
|
|
|
42
|
-
|
|
43
|
-
|------|-------------|
|
|
44
|
-
| `--fix` | Auto-fix: upgrades vulnerable packages, creates a git branch and commit |
|
|
45
|
-
| `--json` | Print results as JSON (pipe-friendly) |
|
|
46
|
-
| `--verbose` | Show detailed phase-by-phase logs |
|
|
84
|
+
## š Usage Examples
|
|
47
85
|
|
|
48
|
-
|
|
86
|
+
### Basic Vulnerability Scan
|
|
87
|
+
```bash
|
|
88
|
+
$ codeprobe scan .
|
|
49
89
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
4. Runs exploit verification in an isolated **Daytona sandbox** (when configured)
|
|
54
|
-
5. Saves the report to `~/.codeprobe/scans/<scan-id>.json`
|
|
55
|
-
6. Displays a risk score, CVE table, and recent npm threat feed
|
|
90
|
+
ā” CodeProbe v1.0.20
|
|
91
|
+
š Searching for package.json files...
|
|
92
|
+
Found 1 package.json file(s)
|
|
56
93
|
|
|
57
|
-
|
|
94
|
+
š Scanning: .
|
|
95
|
+
š¦ Parsing dependencies...
|
|
96
|
+
Found 8 dependencies
|
|
97
|
+
š Checking OSV.dev + npm advisory database...
|
|
98
|
+
Found 13 CVEs
|
|
58
99
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
| `0` | No vulnerabilities found |
|
|
62
|
-
| `1` | Vulnerabilities found |
|
|
63
|
-
| `2` | Scan failed |
|
|
100
|
+
š Analyzing source code for vulnerabilities...
|
|
101
|
+
Found 4 potential vulnerabilities
|
|
64
102
|
|
|
65
|
-
|
|
103
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
104
|
+
SCAN COMPLETE
|
|
105
|
+
Risk Score: 2.2/10 (LOW)
|
|
106
|
+
Confirmed Exploitable: 0 | Theoretical Risk: 13
|
|
107
|
+
Patches Available: 1/13
|
|
108
|
+
Duration: 1s
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Automatic Vulnerability Fixing
|
|
112
|
+
```bash
|
|
113
|
+
$ codeprobe scan . --fix
|
|
66
114
|
|
|
67
|
-
|
|
115
|
+
š§ Applying source code fixes...
|
|
116
|
+
ā Fixed 1 issues in server.js
|
|
117
|
+
ā Fixed 3 issues in seed.js
|
|
118
|
+
Applied 4 code fixes
|
|
68
119
|
|
|
69
|
-
|
|
120
|
+
š Fixed vulnerabilities:
|
|
121
|
+
- server.js:28 - Hardcoded Secret
|
|
122
|
+
- seed.js:16 - Hardcoded Secret
|
|
123
|
+
- seed.js:17 - Hardcoded Secret
|
|
124
|
+
- seed.js:18 - Hardcoded Secret
|
|
125
|
+
```
|
|
70
126
|
|
|
71
|
-
|
|
127
|
+
### Undo AI Changes
|
|
128
|
+
```bash
|
|
129
|
+
$ codeprobe scan . --undo
|
|
72
130
|
|
|
73
|
-
|
|
131
|
+
ā©ļø Reverting AI-made changes...
|
|
132
|
+
|
|
133
|
+
š¦ Reverting package.json updates...
|
|
134
|
+
ā package.json reverted
|
|
135
|
+
š§ Reverting source code fixes...
|
|
136
|
+
ā All code changes reverted
|
|
137
|
+
|
|
138
|
+
ā Undo complete! Review changes with: git status
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Configuration Management
|
|
142
|
+
```bash
|
|
143
|
+
# Set API keys
|
|
144
|
+
codeprobe config set kimi_api_key sk-YOUR_KEY
|
|
145
|
+
codeprobe config set github_token ghp_YOUR_TOKEN
|
|
74
146
|
codeprobe config set bright_data_api_key YOUR_KEY
|
|
75
|
-
|
|
147
|
+
|
|
148
|
+
# View configuration
|
|
149
|
+
codeprobe config get kimi_api_key
|
|
150
|
+
|
|
151
|
+
# Clear configuration
|
|
152
|
+
codeprobe config clear kimi_api_key
|
|
76
153
|
```
|
|
77
154
|
|
|
78
|
-
##
|
|
155
|
+
## š ļø Commands
|
|
156
|
+
|
|
157
|
+
### `codeprobe scan [path]`
|
|
79
158
|
|
|
80
|
-
|
|
159
|
+
Scans for vulnerabilities in dependencies and source code.
|
|
81
160
|
|
|
82
|
-
|
|
161
|
+
| Flag | Description |
|
|
162
|
+
|------|-------------|
|
|
163
|
+
| `--fix` | Auto-fix vulnerabilities in code + update packages |
|
|
164
|
+
| `--undo` | Revert all AI-made changes from the last scan |
|
|
165
|
+
| `--json` | Output results as JSON |
|
|
166
|
+
| `--verbose` | Show detailed logs |
|
|
83
167
|
|
|
84
|
-
|
|
85
|
-
|----------|-------------|
|
|
86
|
-
| `BRIGHT_DATA_API_KEY` | Bright Data scraping proxy (optional) |
|
|
87
|
-
| `DAYTONA_API_KEY` | Daytona sandbox for exploit verification (optional) |
|
|
88
|
-
| `NOSANA_API_KEY` | Nosana LLM for AI-assisted analysis (optional) |
|
|
89
|
-
| `GITHUB_TOKEN` | GitHub token for higher Advisory API rate limits |
|
|
90
|
-
| `PORT` | API server port (default: `3000`) |
|
|
168
|
+
### `codeprobe report`
|
|
91
169
|
|
|
92
|
-
|
|
170
|
+
Shows the last scan results from `~/.codeprobe/scans/latest.json`.
|
|
93
171
|
|
|
94
|
-
|
|
172
|
+
### `codeprobe config`
|
|
95
173
|
|
|
174
|
+
Manage configuration:
|
|
175
|
+
```bash
|
|
176
|
+
codeprobe config set <key> <value>
|
|
177
|
+
codeprobe config get <key>
|
|
178
|
+
codeprobe config clear <key>
|
|
96
179
|
```
|
|
97
|
-
|
|
180
|
+
|
|
181
|
+
## š How It Works
|
|
182
|
+
|
|
183
|
+
### Scan Pipeline
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
1ļøā£ Discovery
|
|
187
|
+
Find all package.json files recursively
|
|
188
|
+
ā
|
|
189
|
+
2ļøā£ Dependency Scanning
|
|
190
|
+
Parse packages ā Check CVE databases
|
|
98
191
|
ā
|
|
99
|
-
|
|
192
|
+
3ļøā£ Source Code Analysis
|
|
193
|
+
Scan .ts/.js files ā Detect security patterns
|
|
100
194
|
ā
|
|
101
|
-
|
|
195
|
+
4ļøā£ Exploit Verification
|
|
196
|
+
Test vulnerabilities in sandboxes (Daytona)
|
|
102
197
|
ā
|
|
103
|
-
|
|
198
|
+
5ļøā£ Patch Generation
|
|
199
|
+
Generate fixes using Kimi LLM
|
|
104
200
|
ā
|
|
105
|
-
|
|
201
|
+
6ļøā£ Risk Scoring & Reporting
|
|
202
|
+
Calculate risk ā Save results
|
|
203
|
+
ā
|
|
204
|
+
7ļøā£ Auto-Fixing (if --fix flag)
|
|
205
|
+
Replace secrets ā Update packages ā Commit
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## š Vulnerability Types
|
|
209
|
+
|
|
210
|
+
| Type | Detection | Automatic Fix |
|
|
211
|
+
|------|-----------|---|
|
|
212
|
+
| **Hardcoded Secrets** | API keys, passwords, tokens | ā
Replace with `process.env` |
|
|
213
|
+
| **Command Injection** | Unescaped shell commands | ā
Add proper escaping |
|
|
214
|
+
| **SQL Injection** | Dynamic SQL queries | ā ļø Suggest parameterized queries |
|
|
215
|
+
| **XSS** | innerHTML, dangerouslySetInnerHTML | ā
Use textContent |
|
|
216
|
+
| **Insecure Random** | Math.random() for security | ā
Use crypto.randomBytes() |
|
|
217
|
+
| **Path Traversal** | Unvalidated file paths | ā ļø Suggest validation |
|
|
218
|
+
| **Insecure Eval** | eval(), Function() usage | ā ļø Suggest alternatives |
|
|
219
|
+
|
|
220
|
+
## āļø Configuration
|
|
221
|
+
|
|
222
|
+
### Config File
|
|
223
|
+
```
|
|
224
|
+
~/.codeprobe/config.json
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### API Keys (Encrypted)
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"kimi_api_key": "sk-...",
|
|
231
|
+
"github_token": "ghp_...",
|
|
232
|
+
"bright_data_api_key": "...",
|
|
233
|
+
"daytona_api_key": "..."
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
All secrets are encrypted using AES-256-GCM.
|
|
238
|
+
|
|
239
|
+
### Environment Variables (Override Config)
|
|
240
|
+
```bash
|
|
241
|
+
export KIMI_API_KEY=sk-...
|
|
242
|
+
export GITHUB_TOKEN=ghp_...
|
|
243
|
+
export BRIGHT_DATA_API_KEY=...
|
|
244
|
+
export DAYTONA_API_KEY=...
|
|
106
245
|
```
|
|
107
246
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
-
|
|
247
|
+
## š Security
|
|
248
|
+
|
|
249
|
+
### Built-In Security Features
|
|
250
|
+
- ā
**Encrypted Config** ā API keys encrypted in `~/.codeprobe/config.json`
|
|
251
|
+
- ā
**No Hardcoded Secrets** ā Detects and fixes credentials in code
|
|
252
|
+
- ā
**Command Injection Prevention** ā Proper shell escaping
|
|
253
|
+
- ā
**Secure Random** ā Uses `crypto.randomBytes()`
|
|
254
|
+
- ā
**Full SAST Analysis** ā Comprehensive source code scanning
|
|
255
|
+
- ā
**Zero Vulnerabilities** ā See [SECURITY_AUDIT.md](./SECURITY_AUDIT.md)
|
|
256
|
+
|
|
257
|
+
### Privacy
|
|
258
|
+
- Scans run locally on your machine
|
|
259
|
+
- Reports saved to `~/.codeprobe/scans/` (private)
|
|
260
|
+
- Kimi only called for patch generation (configurable)
|
|
111
261
|
|
|
112
|
-
##
|
|
262
|
+
## š Output Files
|
|
113
263
|
|
|
114
|
-
|
|
264
|
+
### Scan Reports
|
|
265
|
+
```
|
|
266
|
+
~/.codeprobe/scans/
|
|
267
|
+
āāā scan_<timestamp>.json # Individual scans
|
|
268
|
+
āāā latest.json # Latest scan
|
|
269
|
+
```
|
|
115
270
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
271
|
+
### Fixed Code
|
|
272
|
+
```
|
|
273
|
+
.proofs/
|
|
274
|
+
āāā CVE-2022-29078_timestamp.json
|
|
275
|
+
āāā ...
|
|
276
|
+
```
|
|
120
277
|
|
|
121
|
-
|
|
278
|
+
## š Advanced Usage
|
|
122
279
|
|
|
123
|
-
|
|
280
|
+
### Monorepo Scanning
|
|
281
|
+
```bash
|
|
282
|
+
codeprobe scan /path/to/monorepo
|
|
283
|
+
# Automatically finds and scans all package.json files
|
|
284
|
+
```
|
|
124
285
|
|
|
125
|
-
|
|
286
|
+
### JSON Export
|
|
287
|
+
```bash
|
|
288
|
+
codeprobe scan . --json > report.json
|
|
289
|
+
```
|
|
126
290
|
|
|
127
|
-
|
|
128
|
-
|
|
291
|
+
### Verbose Output
|
|
292
|
+
```bash
|
|
293
|
+
codeprobe scan . --verbose
|
|
129
294
|
```
|
|
130
295
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
| `GET /api/auth/github` | GET | GitHub OAuth callback |
|
|
137
|
-
| `GET /api/auth/logout` | GET | Logout |
|
|
296
|
+
### Undo Previous Changes
|
|
297
|
+
```bash
|
|
298
|
+
# Revert all AI-made fixes from the last scan
|
|
299
|
+
codeprobe scan . --undo
|
|
300
|
+
```
|
|
138
301
|
|
|
139
|
-
|
|
302
|
+
### Combined Options
|
|
303
|
+
```bash
|
|
304
|
+
codeprobe scan . --fix --verbose --json
|
|
305
|
+
```
|
|
140
306
|
|
|
141
|
-
##
|
|
307
|
+
## š Troubleshooting
|
|
142
308
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
309
|
+
### "No Kimi API key configured"
|
|
310
|
+
```bash
|
|
311
|
+
codeprobe config set kimi_api_key sk-YOUR_KEY
|
|
146
312
|
```
|
|
147
313
|
|
|
148
|
-
|
|
314
|
+
### "No package.json files found"
|
|
315
|
+
Make sure your project has a `package.json` file.
|
|
149
316
|
|
|
150
|
-
|
|
317
|
+
### "Uncommitted changes detected"
|
|
318
|
+
After `--fix`, commit the changes:
|
|
319
|
+
```bash
|
|
320
|
+
git add -A
|
|
321
|
+
git commit -m "Security fixes: patch vulnerabilities"
|
|
322
|
+
```
|
|
151
323
|
|
|
324
|
+
## š Performance
|
|
325
|
+
|
|
326
|
+
| Task | Time |
|
|
327
|
+
|------|------|
|
|
328
|
+
| Dependency scanning | 1-3s |
|
|
329
|
+
| Source code analysis | <1s per 100 files |
|
|
330
|
+
| Exploit verification | 2-10s |
|
|
331
|
+
| Patch generation | 5-15s |
|
|
332
|
+
| **Total** | **1-30s** |
|
|
333
|
+
|
|
334
|
+
## šļø Project Structure
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
src/
|
|
338
|
+
āāā cli/ # CLI commands and interface
|
|
339
|
+
āāā engine/ # Core scanner modules
|
|
340
|
+
ā āāā parser.ts # Package parsing
|
|
341
|
+
ā āāā scraper.ts # CVE database queries
|
|
342
|
+
ā āāā sast.ts # Source code analysis
|
|
343
|
+
ā āāā code-fixer.ts # Automatic code fixing
|
|
344
|
+
ā āāā patcher.ts # Patch generation (Kimi)
|
|
345
|
+
ā āāā sandbox.ts # Exploit verification
|
|
346
|
+
āāā shared/ # Types and utilities
|
|
347
|
+
āāā api/ # REST API (optional)
|
|
348
|
+
āāā integrations/ # Daytona, VideoDB, etc.
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## š Examples
|
|
352
|
+
|
|
353
|
+
### Scan Your Project
|
|
354
|
+
```bash
|
|
355
|
+
codeprobe scan .
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Fix All Vulnerabilities
|
|
359
|
+
```bash
|
|
360
|
+
codeprobe scan . --fix
|
|
361
|
+
git add -A && git commit -m "Security fixes"
|
|
362
|
+
git push
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Scan Monorepo
|
|
366
|
+
```bash
|
|
367
|
+
codeprobe scan ./monorepo
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Export as JSON
|
|
371
|
+
```bash
|
|
372
|
+
codeprobe scan . --json | jq '.summary'
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## š Integration
|
|
376
|
+
|
|
377
|
+
### GitHub Actions
|
|
152
378
|
```yaml
|
|
153
|
-
# .github/workflows/codeprobe-scan.yml
|
|
154
379
|
name: Security Scan
|
|
155
380
|
on: [push, pull_request]
|
|
156
381
|
jobs:
|
|
@@ -158,52 +383,63 @@ jobs:
|
|
|
158
383
|
runs-on: ubuntu-latest
|
|
159
384
|
steps:
|
|
160
385
|
- uses: actions/checkout@v3
|
|
161
|
-
- run: npx codeprobe-scanner scan --json
|
|
162
|
-
- uses: actions/upload-artifact@v3
|
|
163
|
-
with:
|
|
164
|
-
name: security-report
|
|
165
|
-
path: report.json
|
|
386
|
+
- run: npx codeprobe-scanner scan --json
|
|
166
387
|
```
|
|
167
388
|
|
|
168
|
-
|
|
169
|
-
|
|
389
|
+
### Pre-commit Hook
|
|
390
|
+
```bash
|
|
391
|
+
#!/bin/sh
|
|
392
|
+
codeprobe scan . || exit 1
|
|
170
393
|
```
|
|
171
|
-
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
172
|
-
ā CodeProbe Scanner ā
|
|
173
|
-
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
174
394
|
|
|
175
|
-
|
|
176
|
-
Risk Score: š“ HIGH (43)
|
|
177
|
-
Confirmed Exploitable: 2 | Theoretical Risk: 5
|
|
178
|
-
Patches Available: 3
|
|
179
|
-
Duration: 8.3s
|
|
395
|
+
## š License
|
|
180
396
|
|
|
181
|
-
|
|
182
|
-
CVE-2022-29078: ejs 3.1.6 [CRITICAL] ā CONFIRMED EXPLOITABLE
|
|
183
|
-
ā Patch available: 3.1.7
|
|
184
|
-
CVE-2023-44487: http2-server 1.0.0 [HIGH] ā CONFIRMED EXPLOITABLE
|
|
185
|
-
ā Patch available: 1.0.1
|
|
397
|
+
MIT License - See LICENSE file
|
|
186
398
|
|
|
187
|
-
|
|
188
|
-
CRITICAL lodash - Prototype Pollution
|
|
189
|
-
HIGH axios - SSRF via redirect
|
|
190
|
-
```
|
|
399
|
+
## š Contributing
|
|
191
400
|
|
|
192
|
-
|
|
401
|
+
Contributions welcome! Please:
|
|
402
|
+
1. Fork the repository
|
|
403
|
+
2. Create a feature branch
|
|
404
|
+
3. Submit a pull request
|
|
193
405
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
406
|
+
## š Support
|
|
407
|
+
|
|
408
|
+
- š [Issue Tracker](https://github.com/NachikethReddyY/codeprobe/issues)
|
|
409
|
+
- š¬ [Discussions](https://github.com/NachikethReddyY/codeprobe/discussions)
|
|
410
|
+
- š [Full Documentation](./SECURITY_AUDIT.md)
|
|
411
|
+
|
|
412
|
+
## š Changelog
|
|
413
|
+
|
|
414
|
+
### v1.0.20
|
|
415
|
+
- ⨠Integrated SAST code vulnerability scanning
|
|
416
|
+
- ⨠Automatic source code fixing
|
|
417
|
+
- š Fixed code fixer to actually apply fixes
|
|
418
|
+
- š Kimi as primary patch generator
|
|
419
|
+
|
|
420
|
+
### v1.0.19
|
|
421
|
+
- ⨠Full codebase scanning
|
|
422
|
+
- ⨠Automatic code fixing
|
|
423
|
+
|
|
424
|
+
### v1.0.18
|
|
425
|
+
- ⨠Security audit (0 vulnerabilities found)
|
|
426
|
+
|
|
427
|
+
### v1.0.17
|
|
428
|
+
- ⨠Kimi patch generation enabled
|
|
429
|
+
- š§ Fixed patches_available reporting
|
|
430
|
+
|
|
431
|
+
### v1.0.16
|
|
432
|
+
- ⨠SAST scanner implementation
|
|
433
|
+
- š Fixed security vulnerabilities
|
|
434
|
+
|
|
435
|
+
### v1.0.15
|
|
436
|
+
- ⨠Recursive package.json scanning
|
|
437
|
+
|
|
438
|
+
### v1.0.14
|
|
439
|
+
- š Fixed VideoDB proof recording
|
|
440
|
+
|
|
441
|
+
---
|
|
206
442
|
|
|
207
|
-
|
|
443
|
+
**CodeProbe: Security, Simplified** š
|
|
208
444
|
|
|
209
|
-
|
|
445
|
+
[GitHub](https://github.com/NachikethReddyY/codeprobe) | [npm](https://npmjs.com/package/codeprobe-scanner) | [Issues](https://github.com/NachikethReddyY/codeprobe/issues)
|
package/package.json
CHANGED
package/src/cli/commands/scan.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { createScraper } from '../../engine/scraper.js';
|
|
|
12
12
|
|
|
13
13
|
interface ScanOptions {
|
|
14
14
|
fix: boolean;
|
|
15
|
+
undo: boolean;
|
|
15
16
|
json: boolean;
|
|
16
17
|
verbose: boolean;
|
|
17
18
|
}
|
|
@@ -19,6 +20,7 @@ interface ScanOptions {
|
|
|
19
20
|
function parseArgs(args: string[]): { repoPath: string; options: ScanOptions } {
|
|
20
21
|
const options: ScanOptions = {
|
|
21
22
|
fix: false,
|
|
23
|
+
undo: false,
|
|
22
24
|
json: false,
|
|
23
25
|
verbose: false,
|
|
24
26
|
};
|
|
@@ -29,6 +31,8 @@ function parseArgs(args: string[]): { repoPath: string; options: ScanOptions } {
|
|
|
29
31
|
const arg = args[i];
|
|
30
32
|
if (arg === '--fix') {
|
|
31
33
|
options.fix = true;
|
|
34
|
+
} else if (arg === '--undo') {
|
|
35
|
+
options.undo = true;
|
|
32
36
|
} else if (arg === '--json') {
|
|
33
37
|
options.json = true;
|
|
34
38
|
} else if (arg === '--verbose') {
|
|
@@ -114,10 +118,68 @@ function displayReport(report: Report, json: boolean, durationMs: number): void
|
|
|
114
118
|
logger.printSeparator();
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
async function undoLastChanges(): Promise<void> {
|
|
122
|
+
console.log("ā©ļø Reverting AI-made changes...\n");
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
// Load last scan report
|
|
126
|
+
const latestPath = path.join(PATHS.SCANS_DIR, 'latest.json');
|
|
127
|
+
if (!existsSync(latestPath)) {
|
|
128
|
+
console.log(chalk.yellow("ā ļø No previous scan found to undo."));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const latestReport = JSON.parse(await Bun.file(latestPath).text());
|
|
133
|
+
|
|
134
|
+
// Revert package.json if it was modified
|
|
135
|
+
if (latestReport.scan.cves && latestReport.scan.cves.length > 0) {
|
|
136
|
+
console.log("š¦ Reverting package.json updates...");
|
|
137
|
+
try {
|
|
138
|
+
// Use git to revert
|
|
139
|
+
const result = await Bun.$`git checkout package.json 2>&1`.nothrow();
|
|
140
|
+
if (result.exitCode === 0) {
|
|
141
|
+
console.log(chalk.green(" ā package.json reverted"));
|
|
142
|
+
} else {
|
|
143
|
+
console.log(chalk.yellow(" ā ļø Could not auto-revert package.json. Run: git checkout package.json"));
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
console.log(chalk.yellow(" ā ļø Could not auto-revert package.json. Run: git checkout package.json"));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Revert code fixes if any were made
|
|
151
|
+
if ((latestReport as any).code_vulnerabilities && (latestReport as any).code_vulnerabilities.length > 0) {
|
|
152
|
+
console.log("š§ Reverting source code fixes...");
|
|
153
|
+
try {
|
|
154
|
+
// Use git to revert all changes
|
|
155
|
+
const result = await Bun.$`git checkout -- . 2>&1`.nothrow();
|
|
156
|
+
if (result.exitCode === 0) {
|
|
157
|
+
console.log(chalk.green(" ā All code changes reverted"));
|
|
158
|
+
} else {
|
|
159
|
+
console.log(chalk.yellow(" ā ļø Could not auto-revert code. Run: git checkout -- ."));
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
console.log(chalk.yellow(" ā ļø Could not auto-revert code. Run: git checkout -- ."));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.log(chalk.green("\nā Undo complete! Review changes with: git status"));
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error(chalk.red(`ā Undo failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
169
|
+
process.exitCode = EXIT_CODES.FAILURE;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
117
173
|
export async function scanCommand(args: string[]): Promise<void> {
|
|
118
174
|
const { repoPath, options } = parseArgs(args);
|
|
119
175
|
const logger = new ProgressLogger(options.verbose);
|
|
120
176
|
|
|
177
|
+
// Handle --undo flag
|
|
178
|
+
if (options.undo) {
|
|
179
|
+
await undoLastChanges();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
121
183
|
logger.printHeader();
|
|
122
184
|
|
|
123
185
|
const startTime = Date.now();
|
|
@@ -189,9 +251,12 @@ export async function scanCommand(args: string[]): Promise<void> {
|
|
|
189
251
|
await scanWithFixCommand([repoPath], report, logger);
|
|
190
252
|
}
|
|
191
253
|
|
|
192
|
-
//
|
|
254
|
+
// Set exit code based on vulnerabilities found
|
|
193
255
|
const hasVulnerabilities = report.scan.cves.length > 0;
|
|
194
|
-
|
|
256
|
+
const exitCode = hasVulnerabilities ? EXIT_CODES.VULNERABILITIES_FOUND : EXIT_CODES.SUCCESS;
|
|
257
|
+
|
|
258
|
+
// Exit gracefully with appropriate code
|
|
259
|
+
process.exitCode = exitCode;
|
|
195
260
|
} catch (error) {
|
|
196
261
|
handleError(error, logger, true);
|
|
197
262
|
}
|