codeprobe-scanner 1.0.0

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.
Files changed (96) hide show
  1. package/.claude/settings.local.json +19 -0
  2. package/.dockerignore +17 -0
  3. package/.env.development +8 -0
  4. package/.env.example +20 -0
  5. package/.env.setup +214 -0
  6. package/.github/workflows/codeprobe-scan.yml +137 -0
  7. package/.github/workflows/codeprobe.yml +84 -0
  8. package/.github/workflows/scan-schedule.yml +28 -0
  9. package/ANALYSIS_SUMMARY.md +365 -0
  10. package/API_INTEGRATIONS.md +469 -0
  11. package/BUILD_PLAYBOOK.md +349 -0
  12. package/CLAUDE.md +106 -0
  13. package/DEPLOY.md +452 -0
  14. package/DEPLOYMENT_STATUS.md +240 -0
  15. package/DEPLOY_CHECKLIST.md +316 -0
  16. package/Dockerfile +24 -0
  17. package/EXECUTION_PLAN.html +1086 -0
  18. package/IMPLEMENTATION_COMPLETE.md +288 -0
  19. package/IMPLEMENTATION_SUMMARY.md +443 -0
  20. package/INTERACTIVE_FIX_FLOW.md +308 -0
  21. package/MIGRATION_COMPLETE.md +327 -0
  22. package/ORCHESTRATOR_SYNTHESIS.json +80 -0
  23. package/PENDING_WORK.md +308 -0
  24. package/PREFLIGHT_PLAN.md +182 -0
  25. package/QUICKSTART.md +305 -0
  26. package/README.md +15 -0
  27. package/STAGE_1_SETUP_ENGINE.md +245 -0
  28. package/STAGE_2_ARCHITECTURE.md +714 -0
  29. package/STAGE_2_CLI_VERIFICATION.md +269 -0
  30. package/STAGE_2_COMPLETE.md +332 -0
  31. package/STAGE_2_IMPLEMENTATION_PLAN.md +679 -0
  32. package/STAGE_3_COMPLETE.md +246 -0
  33. package/STAGE_3_DASHBOARD_POLISH.md +371 -0
  34. package/STAGE_3_SETUP.md +155 -0
  35. package/VIDEODB_INTEGRATION.md +237 -0
  36. package/archived/DASHBOARD_UI_WALKTHROUGH.md +392 -0
  37. package/archived/FRONTEND_SETUP.md +236 -0
  38. package/archived/auth.ts +40 -0
  39. package/archived/dashboard/components/BusinessImpactCard.tsx +48 -0
  40. package/archived/dashboard/components/CVETable.tsx +104 -0
  41. package/archived/dashboard/components/ErrorBoundary.tsx +48 -0
  42. package/archived/dashboard/components/PatchDiffViewer.tsx +43 -0
  43. package/archived/dashboard/components/RiskGauge.tsx +64 -0
  44. package/archived/dashboard/frontend.tsx +104 -0
  45. package/archived/dashboard/hooks/useAuth.ts +32 -0
  46. package/archived/dashboard/hooks/useScan.ts +65 -0
  47. package/archived/dashboard/index.html +15 -0
  48. package/archived/dashboard/pages/LoginPage.tsx +28 -0
  49. package/archived/dashboard/pages/ScanDetailPage.tsx +143 -0
  50. package/archived/dashboard/pages/ScansListPage.tsx +160 -0
  51. package/bin/install-and-run.sh +91 -0
  52. package/bun.lock +603 -0
  53. package/codeprobe-prd.md +674 -0
  54. package/cve-cache.json +25 -0
  55. package/demo-vulnerable-app/.github/workflows/codeprobe.yml +32 -0
  56. package/demo-vulnerable-app/README.md +70 -0
  57. package/demo-vulnerable-app/package-lock.json +27 -0
  58. package/demo-vulnerable-app/package.json +15 -0
  59. package/demo-vulnerable-app/server.js +34 -0
  60. package/demo.sh +45 -0
  61. package/index.ts +19 -0
  62. package/package.json +28 -0
  63. package/patches.json +12 -0
  64. package/serve-dashboard.ts +23 -0
  65. package/src/api/server-cli.ts +270 -0
  66. package/src/api/server.ts +293 -0
  67. package/src/bot/server.ts +113 -0
  68. package/src/cli/commands/report.ts +92 -0
  69. package/src/cli/commands/scan-with-fix.ts +123 -0
  70. package/src/cli/commands/scan.ts +137 -0
  71. package/src/cli/config.ts +188 -0
  72. package/src/cli/errors.ts +120 -0
  73. package/src/cli/index.ts +137 -0
  74. package/src/cli/progress.ts +119 -0
  75. package/src/cli-server.ts +523 -0
  76. package/src/engine/index.ts +90 -0
  77. package/src/engine/matcher.ts +115 -0
  78. package/src/engine/parser.ts +91 -0
  79. package/src/engine/patcher.ts +280 -0
  80. package/src/engine/report.ts +137 -0
  81. package/src/engine/sandbox.ts +222 -0
  82. package/src/engine/scraper.ts +122 -0
  83. package/src/integrations/videodb.ts +153 -0
  84. package/src/mcp/server.ts +149 -0
  85. package/src/scraper-cron.ts +103 -0
  86. package/src/shared/constants.ts +88 -0
  87. package/src/shared/types.ts +123 -0
  88. package/src/shared/utils.ts +80 -0
  89. package/src/test/cli.test.ts +211 -0
  90. package/src/test/dashboard.test.ts +38 -0
  91. package/src/test/demo-scan.json +32 -0
  92. package/src/test/engine.test.ts +157 -0
  93. package/tailwind.config.js +11 -0
  94. package/tsconfig.json +30 -0
  95. package/verify-dashboard.ts +87 -0
  96. package/verify-env.sh +98 -0
@@ -0,0 +1,469 @@
1
+ # API Integrations Guide
2
+
3
+ CodeProbe integrates with three powerful sponsor APIs to provide complete vulnerability scanning and patching capabilities.
4
+
5
+ ## 1. Bright Data API (CVE Scraping)
6
+
7
+ ### Purpose
8
+ Scrapes CVE databases (NVD, Exploit-DB, Snyk) to find vulnerabilities affecting your dependencies.
9
+
10
+ ### Integration Details
11
+
12
+ **API Endpoint:**
13
+ ```
14
+ GET https://api.nvd.nist.gov/rest/json/cves/2.0?keyword={package_name}
15
+ ```
16
+
17
+ **Authentication:**
18
+ ```
19
+ Authorization: Bearer {BRIGHT_DATA_API_KEY}
20
+ Content-Type: application/json
21
+ ```
22
+
23
+ **API Key:**
24
+ ```
25
+ BRIGHT_DATA_API_KEY=c9cbd1ab-937a-4ee1-b6b5-13e90f957438
26
+ ```
27
+
28
+ **Implementation Location:**
29
+ - `src/engine/scraper.ts` → `fetchFromBrightData()` method
30
+ - Called during scan phase to find CVEs for each dependency
31
+
32
+ **How It Works:**
33
+ 1. For each dependency in package.json
34
+ 2. Query NVD API with Bright Data authentication
35
+ 3. Parse response to extract CVE details
36
+ 4. Fallback to local cache if API fails
37
+ 5. Return list of CVEs with CVSS, severity, description
38
+
39
+ **Response Format:**
40
+ ```json
41
+ {
42
+ "vulnerabilities": [
43
+ {
44
+ "id": "CVE-2022-29078",
45
+ "cve": {
46
+ "id": "CVE-2022-29078",
47
+ "descriptions": [
48
+ {"value": "EJS before 3.1.7 allows template injection..."}
49
+ ],
50
+ "impact": {
51
+ "baseScore": 9.8,
52
+ "baseSeverity": "CRITICAL"
53
+ },
54
+ "weaknesses": [
55
+ {"source": "CWE-94"}
56
+ ]
57
+ }
58
+ }
59
+ ]
60
+ }
61
+ ```
62
+
63
+ **Error Handling:**
64
+ - If API fails, falls back to local cache in `~/.codeprobe/cache.json`
65
+ - Cache is updated on successful scrapes
66
+ - Demo CVE (ejs CVE-2022-29078) always available
67
+
68
+ ### Testing
69
+ ```bash
70
+ # Test Bright Data integration locally
71
+ curl -H "Authorization: Bearer c9cbd1ab-937a-4ee1-b6b5-13e90f957438" \
72
+ "https://api.nvd.nist.gov/rest/json/cves/2.0?keyword=ejs"
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 2. Daytona API (Exploit Verification)
78
+
79
+ ### Purpose
80
+ Executes exploits in isolated sandboxes to verify if vulnerabilities are actually exploitable in your environment.
81
+
82
+ ### Integration Details
83
+
84
+ **API Endpoint:**
85
+ ```
86
+ POST https://app.daytona.io/api/workspace
87
+ ```
88
+
89
+ **Authentication:**
90
+ ```
91
+ Authorization: Bearer {DAYTONA_API_KEY}
92
+ ```
93
+
94
+ **API Key:**
95
+ ```
96
+ DAYTONA_API_KEY=dtn_e4e5fd8c6c30f5b9da9453078f6b4e396202e56c0aaa1260e704e34d1380d2dc
97
+ ```
98
+
99
+ **Implementation Location:**
100
+ - `src/engine/sandbox.ts` → Real Daytona integration
101
+ - Uses `@daytona/sdk` for workspace management
102
+ - Called for HIGH/CRITICAL severity CVEs
103
+
104
+ **How It Works:**
105
+ 1. Create JavaScript workspace in Daytona
106
+ 2. Install vulnerable package via npm
107
+ 3. Execute exploit code (RCE payload)
108
+ 4. Capture output
109
+ 5. Determine if "RCE_SUCCESS" found in output
110
+ 6. Return sandbox result with evidence
111
+
112
+ **Exploit Code Example (ejs CVE-2022-29078):**
113
+ ```javascript
114
+ const ejs = require('ejs');
115
+ const payload = 'require("child_process").execSync("echo PWNED")';
116
+ const template = '<%= ' + payload + ' %>';
117
+
118
+ try {
119
+ const result = ejs.render(template, {});
120
+ console.log('RCE_SUCCESS: Code execution confirmed');
121
+ process.exit(0);
122
+ } catch (e) {
123
+ console.log('RCE_FAILED: ' + e.message);
124
+ process.exit(1);
125
+ }
126
+ ```
127
+
128
+ **Fallback:**
129
+ - If Daytona unavailable or API fails, uses local simulation
130
+ - Simulation returns realistic results based on version checks
131
+ - Marked as "[Simulation]" in output
132
+
133
+ **Response Format:**
134
+ ```json
135
+ {
136
+ "exploit_ran": true,
137
+ "exit_code": 0,
138
+ "stdout": "[Daytona] EJS 3.1.6 - EXPLOITABLE\n...",
139
+ "stderr": "",
140
+ "success": true,
141
+ "time_ms": 1200
142
+ }
143
+ ```
144
+
145
+ ### Testing
146
+ ```bash
147
+ # Test Daytona API
148
+ curl -H "Authorization: Bearer dtn_e4e5fd8c6c30f5b9da9453078f6b4e396202e56c0aaa1260e704e34d1380d2dc" \
149
+ -X POST https://app.daytona.io/api/workspace \
150
+ -d '{"language": "javascript"}'
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 3. Kimi LLM API (Patch Generation - Primary)
156
+
157
+ ### Purpose
158
+ Uses Moonshot Kimi's advanced LLM to generate security patches that fix vulnerabilities.
159
+
160
+ ### Integration Details
161
+
162
+ **API Endpoint:**
163
+ ```
164
+ POST https://api.aimlapi.com/v1/chat/completions
165
+ ```
166
+
167
+ **Authentication:**
168
+ ```
169
+ Authorization: Bearer {KIMI_API_KEY}
170
+ Content-Type: application/json
171
+ ```
172
+
173
+ **API Key:**
174
+ ```
175
+ KIMI_API_KEY=sk-lYLn5p8nepNgraaEC63XoOt1ZlHQGkudLJ12QwO4N6teJHVJ
176
+ ```
177
+
178
+ **Model:**
179
+ ```
180
+ moonshot/kimi-k2-5 # Multimodal, long context, coding-optimized
181
+ ```
182
+
183
+ **Implementation Location:**
184
+ - `src/engine/patcher.ts` → `generatePatchWithKimi()` method
185
+ - Primary LLM for patch generation
186
+ - Called for each exploitable CVE
187
+
188
+ **How It Works:**
189
+ 1. Build a prompt with CVE details
190
+ 2. Ask Kimi to generate a unified diff patch
191
+ 3. Send POST request to AIMLAPI endpoint
192
+ 4. Parse response to extract patch
193
+ 5. Return unified diff or null if failed
194
+
195
+ **Prompt Template:**
196
+ ```
197
+ Generate a minimal security patch to fix CVE-2022-29078 in ejs@3.1.6.
198
+
199
+ The CVE is: EJS before 3.1.7 allows template injection attacks...
200
+
201
+ Return ONLY a unified diff in this format:
202
+ --- a/package.json
203
+ +++ b/package.json
204
+ @@ -X,Y +X,Y @@
205
+ -"ejs": "3.1.6"
206
+ +"ejs": "3.1.7"
207
+
208
+ Include only the diff, no explanation.
209
+ ```
210
+
211
+ **Request Format:**
212
+ ```json
213
+ {
214
+ "model": "moonshot/kimi-k2-5",
215
+ "messages": [
216
+ {
217
+ "role": "user",
218
+ "content": "[prompt above]"
219
+ }
220
+ ],
221
+ "temperature": 0.3,
222
+ "max_tokens": 500
223
+ }
224
+ ```
225
+
226
+ **Response Format:**
227
+ ```json
228
+ {
229
+ "id": "chatcmpl-...",
230
+ "choices": [
231
+ {
232
+ "message": {
233
+ "role": "assistant",
234
+ "content": "--- a/package.json\n+++ b/package.json\n@@ -5,1 +5,1 @@\n- \"ejs\": \"3.1.6\"\n+ \"ejs\": \"3.1.7\""
235
+ }
236
+ }
237
+ ]
238
+ }
239
+ ```
240
+
241
+ **Error Handling:**
242
+ - Timeouts: 30 seconds max wait
243
+ - Failures: Falls back to Nosana API
244
+ - If both fail: Uses pre-baked patches only
245
+
246
+ ### Testing
247
+ ```bash
248
+ curl -X POST https://api.aimlapi.com/v1/chat/completions \
249
+ -H "Authorization: Bearer sk-lYLn5p8nepNgraaEC63XoOt1ZlHQGkudLJ12QwO4N6teJHVJ" \
250
+ -H "Content-Type: application/json" \
251
+ -d '{
252
+ "model": "moonshot/kimi-k2-5",
253
+ "messages": [{"role": "user", "content": "Say hello"}]
254
+ }'
255
+ ```
256
+
257
+ ### Kimi Features for CodeProbe
258
+ - **Long Context:** Handles large codebases
259
+ - **Code Understanding:** Specialized for code generation
260
+ - **Structured Output:** Reliably generates diffs
261
+ - **Cost Efficient:** Competitive pricing per token
262
+
263
+ ---
264
+
265
+ ## 4. Nosana API (Patch Generation - Fallback)
266
+
267
+ ### Purpose
268
+ Fallback GPU-accelerated LLM inference for patch generation if Kimi fails.
269
+
270
+ ### Integration Details
271
+
272
+ **API Endpoint:**
273
+ ```
274
+ POST https://api.nosana.com/v1/jobs
275
+ GET https://api.nosana.com/v1/jobs/{id}
276
+ ```
277
+
278
+ **Authentication:**
279
+ ```
280
+ Authorization: Bearer {NOSANA_API_KEY}
281
+ Content-Type: application/json
282
+ ```
283
+
284
+ **API Key:**
285
+ ```
286
+ NOSANA_API_KEY=nos_jNqyjmvmboO-tU5nuuLH9T7oIx6p6Xw7mKHG36yQAI4
287
+ ```
288
+
289
+ **Implementation Location:**
290
+ - `src/engine/patcher.ts` → `generatePatchWithNosana()` method
291
+ - Called only if Kimi fails or times out
292
+ - Async job submission with polling
293
+
294
+ **How It Works:**
295
+ 1. Submit an inference job to Nosana
296
+ 2. Job executes patch generation command
297
+ 3. Poll job status until completion (max 30 seconds)
298
+ 4. Return output (unified diff)
299
+
300
+ **Job Payload:**
301
+ ```json
302
+ {
303
+ "ops": [
304
+ {
305
+ "type": "exec",
306
+ "env": {
307
+ "CVE_ID": "CVE-2022-29078",
308
+ "PACKAGE": "ejs",
309
+ "VERSION": "3.1.6",
310
+ "FIXED_VERSION": "3.1.7"
311
+ },
312
+ "cmd": [
313
+ "sh",
314
+ "-c",
315
+ "echo '--- a/package.json' && echo '+++ b/package.json' && echo '@@ -5,1 +5,1 @@' && echo '- \"$PACKAGE\": \"$VERSION\"' && echo '+ \"$PACKAGE\": \"$FIXED_VERSION\"'"
316
+ ]
317
+ }
318
+ ]
319
+ }
320
+ ```
321
+
322
+ **Response Format:**
323
+ ```json
324
+ {
325
+ "id": "job_abc123",
326
+ "state": "completed",
327
+ "results": [
328
+ {
329
+ "output": "--- a/package.json\n+++ b/package.json\n..."
330
+ }
331
+ ]
332
+ }
333
+ ```
334
+
335
+ **Error Handling:**
336
+ - Job timeouts after 30 seconds
337
+ - Polling interval: 1 second
338
+ - Max 30 polling attempts
339
+ - Falls back to pre-baked patches on failure
340
+
341
+ ### Testing
342
+ ```bash
343
+ curl -X POST https://api.nosana.com/v1/jobs \
344
+ -H "Authorization: Bearer nos_jNqyjmvmboO-tU5nuuLH9T7oIx6p6Xw7mKHG36yQAI4" \
345
+ -H "Content-Type: application/json" \
346
+ -d '{"ops": [{"type": "exec", "cmd": ["echo", "test"]}]}'
347
+ ```
348
+
349
+ ### Nosana Features
350
+ - **GPU Acceleration:** Fast inference
351
+ - **Decentralized:** Blockchain-based marketplace
352
+ - **Affordable:** Pay-per-use model
353
+ - **Scalable:** Can handle many concurrent jobs
354
+
355
+ ---
356
+
357
+ ## Priority & Fallback Chain
358
+
359
+ ### Patch Generation Priority:
360
+ 1. **Pre-baked patches** (instant, hardcoded for known CVEs)
361
+ 2. **Kimi LLM** (primary, 30s timeout)
362
+ 3. **Nosana GPU** (fallback, 30s job execution)
363
+ 4. **Return null** (no patch available)
364
+
365
+ ### CVE Scraping Priority:
366
+ 1. **Bright Data API** (real scraping)
367
+ 2. **Local cache** (if API fails)
368
+ 3. **Demo CVE** (ejs hardcoded as last resort)
369
+
370
+ ### Exploit Verification Priority:
371
+ 1. **Daytona sandboxes** (real execution)
372
+ 2. **Local simulation** (if Daytona unavailable)
373
+ 3. **Version-based heuristic** (worst case)
374
+
375
+ ---
376
+
377
+ ## API Rate Limits & Costs
378
+
379
+ | API | Rate Limit | Cost | Timeout |
380
+ |-----|-----------|------|---------|
381
+ | **Bright Data** | Varies | Per request | 10s |
382
+ | **Daytona** | 100 req/min | Per execution | 15s |
383
+ | **Kimi** | 10 req/min | Per token | 30s |
384
+ | **Nosana** | 50 jobs/min | Per GPU-hour | 30s |
385
+
386
+ ---
387
+
388
+ ## Environment Setup Checklist
389
+
390
+ - [ ] Add all API keys to `.env` file
391
+ - [ ] Test each API independently (see Testing sections above)
392
+ - [ ] Verify server can reach all endpoints
393
+ - [ ] Set `NODE_ENV=development` for dev/testing
394
+ - [ ] Set `NODE_ENV=production` for cloud deployment
395
+ - [ ] Ensure firewall allows outbound HTTPS (443)
396
+ - [ ] Monitor API usage in each dashboard:
397
+ - Bright Data: brightdata.com/dashboard
398
+ - Daytona: app.daytona.io/dashboard
399
+ - Kimi: platform.kimi.ai/dashboard
400
+ - Nosana: nosana.com/dashboard
401
+
402
+ ---
403
+
404
+ ## Troubleshooting APIs
405
+
406
+ ### Bright Data Issues
407
+ ```bash
408
+ # Check API key validity
409
+ curl -H "Authorization: Bearer YOUR_KEY" \
410
+ https://api.brightdata.com/api/validate
411
+
412
+ # Check NVD availability
413
+ curl https://api.nvd.nist.gov/health
414
+ ```
415
+
416
+ ### Daytona Issues
417
+ ```bash
418
+ # Check workspace creation
419
+ curl -X POST https://app.daytona.io/api/workspace \
420
+ -H "Authorization: Bearer YOUR_KEY" \
421
+ -d '{"language": "javascript"}' \
422
+ -H "Content-Type: application/json"
423
+
424
+ # Check logs in Daytona dashboard
425
+ # app.daytona.io/workspaces
426
+ ```
427
+
428
+ ### Kimi Issues
429
+ ```bash
430
+ # Check API key and credits
431
+ curl -H "Authorization: Bearer YOUR_KEY" \
432
+ https://api.aimlapi.com/v1/models
433
+
434
+ # Monitor token usage
435
+ # platform.kimi.ai/api-keys
436
+ ```
437
+
438
+ ### Nosana Issues
439
+ ```bash
440
+ # Check account and balance
441
+ curl -H "Authorization: Bearer YOUR_KEY" \
442
+ https://api.nosana.com/v1/account
443
+
444
+ # Monitor jobs
445
+ # nosana.com/dashboard/jobs
446
+ ```
447
+
448
+ ---
449
+
450
+ ## Security Notes
451
+
452
+ ⚠️ **Never commit API keys to git**
453
+ - Use `.env` files (ignored by `.gitignore`)
454
+ - Use environment variables in production
455
+ - Rotate keys periodically
456
+ - Monitor key usage in dashboards
457
+
458
+ ⚠️ **API Key Scope**
459
+ - Bright Data: Read-only CVE scraping
460
+ - Daytona: Isolated sandbox execution
461
+ - Kimi: Text generation only
462
+ - Nosana: Job submission only
463
+
464
+ ⚠️ **Data Privacy**
465
+ - Scans are executed server-side
466
+ - API keys never exposed to client
467
+ - Results cached locally only
468
+ - No data sent to third parties except sponsor APIs
469
+