@quantracode/vibecheck 0.3.3 → 0.4.1

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 CHANGED
@@ -23,6 +23,12 @@ npm install -g @quantracode/vibecheck
23
23
 
24
24
  # Or use without installing
25
25
  npx @quantracode/vibecheck scan --fail-on off --out vibecheck-scan.json
26
+
27
+ # With auto-fix enabled
28
+ npx @quantracode/vibecheck scan --apply-fixes
29
+
30
+ # With custom security rules
31
+ npx @quantracode/vibecheck scan --rules ./my-custom-rules
26
32
  ```
27
33
 
28
34
  ### Scan Another Folder
@@ -64,6 +70,18 @@ vibecheck scan --include-tests
64
70
  # Generate intent map with coverage metrics
65
71
  vibecheck scan --emit-intent-map
66
72
 
73
+ # Auto-fix security issues (with confirmation)
74
+ vibecheck scan --apply-fixes
75
+
76
+ # Auto-fix without confirmation prompts
77
+ vibecheck scan --apply-fixes --force
78
+
79
+ # Load custom YAML security rules
80
+ vibecheck scan --rules ./my-custom-rules
81
+
82
+ # Load a single custom rule file
83
+ vibecheck scan -r my-rule.yaml
84
+
67
85
  # Explain a scan report
68
86
  vibecheck explain ./scan.json
69
87
 
@@ -146,6 +164,9 @@ vibecheck view
146
164
  | `-e, --exclude <glob>` | Glob pattern to exclude (repeatable) | See below |
147
165
  | `--include-tests` | Include test files in scan | `false` |
148
166
  | `--emit-intent-map` | Include route map and coverage metrics | `false` |
167
+ | `--apply-fixes` | Apply patches from findings after scan | `false` |
168
+ | `--force` | Skip confirmation when applying patches | `false` |
169
+ | `-r, --rules <path>` | Load custom YAML rules from directory or file | - |
149
170
 
150
171
  ### Default Excludes
151
172
 
@@ -160,6 +181,238 @@ The following patterns are excluded by default:
160
181
  - `test/`, `tests/`, `fixtures/`, `__mocks__/`, `__fixtures__/`
161
182
  - `cypress/`, `e2e/`, `*.stories.*`
162
183
 
184
+ ## Auto-Fix Security Issues
185
+
186
+ VibeCheck can automatically apply security patches from findings:
187
+
188
+ ```bash
189
+ # Apply fixes with confirmation prompts for each patch
190
+ vibecheck scan --apply-fixes
191
+
192
+ # Apply all fixes automatically without prompts (use with caution!)
193
+ vibecheck scan --apply-fixes --force
194
+ ```
195
+
196
+ ### How It Works
197
+
198
+ 1. **Scan completes** - VibeCheck identifies security issues
199
+ 2. **Patches available** - Findings with `remediation.patch` field are candidates for auto-fix
200
+ 3. **Preview shown** - Each patch is displayed with before/after comparison
201
+ 4. **User confirmation** - You approve or reject each patch (unless `--force` is used)
202
+ 5. **Applied to files** - Approved patches are written to your source files
203
+
204
+ ### Safety Features
205
+
206
+ - **Unified diff format**: Only standard git-style diffs are supported for safety
207
+ - **Context validation**: Patches verify that file content matches before applying
208
+ - **Confirmation required**: Interactive approval by default
209
+ - **Detailed errors**: Clear messages if a patch fails to apply
210
+
211
+ ### Best Practices
212
+
213
+ 1. **Commit first**: Always have a clean git status before applying fixes
214
+ 2. **Review changes**: Run `git diff` after applying patches
215
+ 3. **Test thoroughly**: Run your test suite to ensure nothing broke
216
+ 4. **Use force carefully**: Only use `--force` when you fully trust the patches
217
+
218
+ **Example:**
219
+
220
+ ```bash
221
+ # 1. Ensure clean working directory
222
+ git status
223
+
224
+ # 2. Run scan with auto-fix
225
+ vibecheck scan --apply-fixes
226
+
227
+ # 3. Review what changed
228
+ git diff
229
+
230
+ # 4. Test the changes
231
+ npm test
232
+
233
+ # 5. Commit if everything looks good
234
+ git add .
235
+ git commit -m "fix: apply VibeCheck security patches"
236
+ ```
237
+
238
+ ## Custom Security Rules
239
+
240
+ Extend VibeCheck with your own YAML-based security rules - no TypeScript required!
241
+
242
+ ```bash
243
+ # Load custom rules from a directory
244
+ vibecheck scan --rules ./my-custom-rules
245
+
246
+ # Load a single rule file
247
+ vibecheck scan -r my-security-rule.yaml
248
+ ```
249
+
250
+ ### Example Custom Rule
251
+
252
+ ```yaml
253
+ id: CUSTOM-AUTH-001
254
+ severity: high
255
+ category: auth
256
+ title: "Missing authentication on POST endpoint"
257
+ description: |
258
+ POST endpoints should have authentication checks to prevent
259
+ unauthorized access to state-changing operations.
260
+
261
+ files:
262
+ file_type: [ts, tsx]
263
+ include: ["**/api/**/*.ts"]
264
+ exclude: ["**/*.test.*"]
265
+
266
+ match:
267
+ contains: "export async function POST"
268
+ not_contains: "getServerSession"
269
+ case_sensitive: false
270
+
271
+ context:
272
+ in_function: [POST]
273
+ file_not_contains: ["test", "mock"]
274
+
275
+ recommended_fix: |
276
+ Add authentication to your POST handler:
277
+
278
+ ```typescript
279
+ import { getServerSession } from "next-auth";
280
+
281
+ export async function POST(request: Request) {
282
+ const session = await getServerSession(authOptions);
283
+ if (!session) {
284
+ return new Response("Unauthorized", { status: 401 });
285
+ }
286
+ // ... rest of handler
287
+ }
288
+ ```
289
+
290
+ links:
291
+ owasp: https://owasp.org/API-Security/editions/2023/en/0xa2-broken-authentication/
292
+ cwe: https://cwe.mitre.org/data/definitions/306.html
293
+
294
+ metadata:
295
+ author: "Your Name"
296
+ tags: ["authentication", "api-security"]
297
+ created: "2025-01-07"
298
+ ```
299
+
300
+ ### Rule Structure
301
+
302
+ **Required Fields:**
303
+ - `id`: Unique identifier (format: `XXX-XXX-000`)
304
+ - `severity`: `critical`, `high`, `medium`, `low`, or `info`
305
+ - `category`: Security category (auth, validation, secrets, etc.)
306
+ - `title`: Short description
307
+ - `description`: Detailed explanation
308
+ - `match`: What to look for (see Match Conditions below)
309
+ - `recommended_fix`: How to fix the issue
310
+
311
+ **Optional Fields:**
312
+ - `files`: File filters (type, include/exclude patterns, directories)
313
+ - `context`: Advanced conditions (imports, function types, file content)
314
+ - `patch`: Unified diff for auto-fixing
315
+ - `links`: Reference URLs (OWASP, CWE, docs)
316
+ - `metadata`: Author, tags, version, dates
317
+ - `enabled`: Whether the rule is active (default: true)
318
+
319
+ ### Match Conditions
320
+
321
+ **String Match:**
322
+ ```yaml
323
+ match:
324
+ contains: "eval("
325
+ case_sensitive: true
326
+ ```
327
+
328
+ **Negative Match (should NOT contain):**
329
+ ```yaml
330
+ match:
331
+ not_contains: "getServerSession" # Flag files without auth
332
+ ```
333
+
334
+ **Regular Expression:**
335
+ ```yaml
336
+ match:
337
+ regex: "password\\s*=\\s*['\"][^'\"]+['\"]"
338
+ case_sensitive: false
339
+ ```
340
+
341
+ **Combined Conditions:**
342
+ ```yaml
343
+ match:
344
+ contains: "export async function POST"
345
+ not_contains: "await auth()"
346
+ regex: "prisma\\.(create|update|delete)"
347
+ ```
348
+
349
+ ### File Filters
350
+
351
+ ```yaml
352
+ files:
353
+ file_type: [ts, tsx, js, jsx]
354
+ include: ["**/api/**/*.ts", "**/routes/**/*.ts"]
355
+ exclude: ["**/*.test.*", "**/*.spec.*"]
356
+ directories: ["/api/", "/routes/"]
357
+ ```
358
+
359
+ Available file types: `ts`, `tsx`, `js`, `jsx`, `json`, `env`, `yaml`, `yml`, `md`, `config`, `any`
360
+
361
+ ### Context Conditions
362
+
363
+ ```yaml
364
+ context:
365
+ # Only flag if file imports these packages
366
+ requires_import: ["next-auth", "@prisma/client"]
367
+
368
+ # Don't flag if file imports these
369
+ excludes_import: ["vitest", "@testing-library"]
370
+
371
+ # File must contain all of these
372
+ file_contains: ["database", "user"]
373
+
374
+ # File must NOT contain any of these
375
+ file_not_contains: ["test", "mock"]
376
+
377
+ # Only match in specific handler types
378
+ in_function: [POST, PUT, DELETE, route_handler]
379
+ ```
380
+
381
+ ### Multiple Rules in One File
382
+
383
+ ```yaml
384
+ schema_version: "1.0"
385
+
386
+ rules:
387
+ - id: CUSTOM-001
388
+ severity: high
389
+ category: auth
390
+ title: "First rule"
391
+ # ... rule config
392
+
393
+ - id: CUSTOM-002
394
+ severity: medium
395
+ category: validation
396
+ title: "Second rule"
397
+ # ... rule config
398
+ ```
399
+
400
+ ### Complete Guide
401
+
402
+ See [examples/CUSTOM_RULES_GUIDE.md](./examples/CUSTOM_RULES_GUIDE.md) for:
403
+ - Full rule specification
404
+ - Advanced examples (SQL injection, hardcoded secrets, etc.)
405
+ - Best practices and troubleshooting
406
+ - Community contribution guidelines
407
+
408
+ ### Example Rules
409
+
410
+ Check out [examples/custom-rules/](./examples/custom-rules/) for production-ready examples:
411
+ - `hardcoded-secret.yaml` - Detect secrets in .env files
412
+ - `missing-rate-limit.yaml` - Find API routes without rate limiting
413
+ - `console-log-production.yaml` - Flag console.log in production code
414
+ - `collection-example.yaml` - Multiple rules in one file
415
+
163
416
  ## Scanner Categories
164
417
 
165
418
  VibeCheck includes 30+ enforcement verification scanners across these categories:
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- declare const CLI_VERSION = "0.3.2";
2
+ declare const CLI_VERSION = "0.4.1";
3
3
 
4
4
  export { CLI_VERSION };