@vibecheckai/cli 3.5.0 → 3.5.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.
- package/bin/registry.js +214 -237
- package/bin/runners/cli-utils.js +33 -2
- package/bin/runners/context/analyzer.js +52 -1
- package/bin/runners/context/generators/cursor.js +2 -49
- package/bin/runners/context/git-context.js +3 -1
- package/bin/runners/context/team-conventions.js +33 -7
- package/bin/runners/lib/analysis-core.js +25 -5
- package/bin/runners/lib/analyzers.js +431 -481
- package/bin/runners/lib/default-config.js +127 -0
- package/bin/runners/lib/doctor/modules/security.js +3 -1
- package/bin/runners/lib/engine/ast-cache.js +210 -0
- package/bin/runners/lib/engine/auth-extractor.js +211 -0
- package/bin/runners/lib/engine/billing-extractor.js +112 -0
- package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
- package/bin/runners/lib/engine/env-extractor.js +207 -0
- package/bin/runners/lib/engine/express-extractor.js +208 -0
- package/bin/runners/lib/engine/extractors.js +849 -0
- package/bin/runners/lib/engine/index.js +207 -0
- package/bin/runners/lib/engine/repo-index.js +514 -0
- package/bin/runners/lib/engine/types.js +124 -0
- package/bin/runners/lib/engines/accessibility-engine.js +18 -218
- package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
- package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
- package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
- package/bin/runners/lib/engines/mock-data-engine.js +10 -53
- package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
- package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
- package/bin/runners/lib/engines/type-aware-engine.js +39 -263
- package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
- package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
- package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
- package/bin/runners/lib/entitlements-v2.js +73 -97
- package/bin/runners/lib/error-handler.js +44 -3
- package/bin/runners/lib/error-messages.js +289 -0
- package/bin/runners/lib/evidence-pack.js +7 -1
- package/bin/runners/lib/finding-id.js +69 -0
- package/bin/runners/lib/finding-sorter.js +89 -0
- package/bin/runners/lib/html-proof-report.js +700 -350
- package/bin/runners/lib/missions/plan.js +6 -46
- package/bin/runners/lib/missions/templates.js +0 -232
- package/bin/runners/lib/next-action.js +560 -0
- package/bin/runners/lib/prerequisites.js +149 -0
- package/bin/runners/lib/route-detection.js +137 -68
- package/bin/runners/lib/scan-output.js +91 -76
- package/bin/runners/lib/scan-runner.js +135 -0
- package/bin/runners/lib/schemas/ajv-validator.js +464 -0
- package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
- package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
- package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
- package/bin/runners/lib/schemas/run-request.schema.json +108 -0
- package/bin/runners/lib/schemas/validator.js +27 -0
- package/bin/runners/lib/schemas/verdict.schema.json +140 -0
- package/bin/runners/lib/ship-output-enterprise.js +23 -23
- package/bin/runners/lib/ship-output.js +75 -31
- package/bin/runners/lib/terminal-ui.js +6 -113
- package/bin/runners/lib/truth.js +351 -10
- package/bin/runners/lib/unified-cli-output.js +430 -603
- package/bin/runners/lib/unified-output.js +13 -9
- package/bin/runners/runAIAgent.js +10 -5
- package/bin/runners/runAgent.js +0 -3
- package/bin/runners/runAllowlist.js +389 -0
- package/bin/runners/runApprove.js +0 -33
- package/bin/runners/runAuth.js +73 -45
- package/bin/runners/runCheckpoint.js +51 -11
- package/bin/runners/runClassify.js +85 -21
- package/bin/runners/runContext.js +0 -3
- package/bin/runners/runDoctor.js +41 -28
- package/bin/runners/runEvidencePack.js +362 -0
- package/bin/runners/runFirewall.js +0 -3
- package/bin/runners/runFirewallHook.js +0 -3
- package/bin/runners/runFix.js +66 -76
- package/bin/runners/runGuard.js +18 -411
- package/bin/runners/runInit.js +113 -30
- package/bin/runners/runLabs.js +424 -0
- package/bin/runners/runMcp.js +19 -25
- package/bin/runners/runPolish.js +64 -240
- package/bin/runners/runPromptFirewall.js +12 -5
- package/bin/runners/runProve.js +57 -22
- package/bin/runners/runQuickstart.js +531 -0
- package/bin/runners/runReality.js +59 -68
- package/bin/runners/runReport.js +38 -33
- package/bin/runners/runRuntime.js +8 -5
- package/bin/runners/runScan.js +1413 -190
- package/bin/runners/runShip.js +113 -719
- package/bin/runners/runTruth.js +0 -3
- package/bin/runners/runValidate.js +13 -9
- package/bin/runners/runWatch.js +23 -14
- package/bin/scan.js +6 -1
- package/bin/vibecheck.js +204 -185
- package/mcp-server/deprecation-middleware.js +282 -0
- package/mcp-server/handlers/index.ts +15 -0
- package/mcp-server/handlers/tool-handler.ts +554 -0
- package/mcp-server/index-v1.js +698 -0
- package/mcp-server/index.js +210 -238
- package/mcp-server/lib/cache-wrapper.cjs +383 -0
- package/mcp-server/lib/error-envelope.js +138 -0
- package/mcp-server/lib/executor.ts +499 -0
- package/mcp-server/lib/index.ts +19 -0
- package/mcp-server/lib/rate-limiter.js +166 -0
- package/mcp-server/lib/sandbox.test.ts +519 -0
- package/mcp-server/lib/sandbox.ts +395 -0
- package/mcp-server/lib/types.ts +267 -0
- package/mcp-server/package.json +12 -3
- package/mcp-server/registry/tool-registry.js +794 -0
- package/mcp-server/registry/tools.json +605 -0
- package/mcp-server/registry.test.ts +334 -0
- package/mcp-server/tests/tier-gating.test.js +297 -0
- package/mcp-server/tier-auth.js +378 -45
- package/mcp-server/tools-v3.js +353 -442
- package/mcp-server/tsconfig.json +37 -0
- package/mcp-server/vibecheck-2.0-tools.js +14 -1
- package/package.json +1 -1
- package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
- package/bin/runners/lib/audit-logger.js +0 -532
- package/bin/runners/lib/authority/authorities/architecture.js +0 -364
- package/bin/runners/lib/authority/authorities/compliance.js +0 -341
- package/bin/runners/lib/authority/authorities/human.js +0 -343
- package/bin/runners/lib/authority/authorities/quality.js +0 -420
- package/bin/runners/lib/authority/authorities/security.js +0 -228
- package/bin/runners/lib/authority/index.js +0 -293
- package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
- package/bin/runners/lib/cli-charts.js +0 -368
- package/bin/runners/lib/cli-config-display.js +0 -405
- package/bin/runners/lib/cli-demo.js +0 -275
- package/bin/runners/lib/cli-errors.js +0 -438
- package/bin/runners/lib/cli-help-formatter.js +0 -439
- package/bin/runners/lib/cli-interactive-menu.js +0 -509
- package/bin/runners/lib/cli-prompts.js +0 -441
- package/bin/runners/lib/cli-scan-cards.js +0 -362
- package/bin/runners/lib/compliance-reporter.js +0 -710
- package/bin/runners/lib/conductor/index.js +0 -671
- package/bin/runners/lib/easy/README.md +0 -123
- package/bin/runners/lib/easy/index.js +0 -140
- package/bin/runners/lib/easy/interactive-wizard.js +0 -788
- package/bin/runners/lib/easy/one-click-firewall.js +0 -564
- package/bin/runners/lib/easy/zero-config-reality.js +0 -714
- package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
- package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
- package/bin/runners/lib/engines/confidence-scoring.js +0 -276
- package/bin/runners/lib/engines/context-detection.js +0 -264
- package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
- package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
- package/bin/runners/lib/engines/env-variables-engine.js +0 -458
- package/bin/runners/lib/engines/error-handling-engine.js +0 -437
- package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
- package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
- package/bin/runners/lib/engines/framework-detection.js +0 -508
- package/bin/runners/lib/engines/import-order-engine.js +0 -429
- package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
- package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
- package/bin/runners/lib/engines/orchestrator.js +0 -334
- package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
- package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
- package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
- package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
- package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
- package/bin/runners/lib/enhanced-features/index.js +0 -305
- package/bin/runners/lib/enhanced-output.js +0 -631
- package/bin/runners/lib/enterprise.js +0 -300
- package/bin/runners/lib/firewall/command-validator.js +0 -351
- package/bin/runners/lib/firewall/config.js +0 -341
- package/bin/runners/lib/firewall/content-validator.js +0 -519
- package/bin/runners/lib/firewall/index.js +0 -101
- package/bin/runners/lib/firewall/path-validator.js +0 -256
- package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
- package/bin/runners/lib/mcp-utils.js +0 -425
- package/bin/runners/lib/output/index.js +0 -1022
- package/bin/runners/lib/policy-engine.js +0 -652
- package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
- package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
- package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
- package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
- package/bin/runners/lib/polish/autofix/index.js +0 -200
- package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
- package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
- package/bin/runners/lib/polish/backend-checks.js +0 -148
- package/bin/runners/lib/polish/documentation-checks.js +0 -111
- package/bin/runners/lib/polish/frontend-checks.js +0 -168
- package/bin/runners/lib/polish/index.js +0 -71
- package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
- package/bin/runners/lib/polish/library-detection.js +0 -175
- package/bin/runners/lib/polish/performance-checks.js +0 -100
- package/bin/runners/lib/polish/security-checks.js +0 -148
- package/bin/runners/lib/polish/utils.js +0 -203
- package/bin/runners/lib/prompt-builder.js +0 -540
- package/bin/runners/lib/proof-certificate.js +0 -634
- package/bin/runners/lib/reality/accessibility-audit.js +0 -946
- package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
- package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
- package/bin/runners/lib/reality/performance-tracker.js +0 -1077
- package/bin/runners/lib/reality/scenario-generator.js +0 -1404
- package/bin/runners/lib/reality/visual-regression.js +0 -852
- package/bin/runners/lib/reality-profiler.js +0 -717
- package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
- package/bin/runners/lib/review/ai-code-review.js +0 -832
- package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
- package/bin/runners/lib/sbom-generator.js +0 -641
- package/bin/runners/lib/scan-output-enhanced.js +0 -512
- package/bin/runners/lib/security/owasp-scanner.js +0 -939
- package/bin/runners/lib/validators/contract-validator.js +0 -283
- package/bin/runners/lib/validators/dead-export-detector.js +0 -279
- package/bin/runners/lib/validators/dep-audit.js +0 -245
- package/bin/runners/lib/validators/env-validator.js +0 -319
- package/bin/runners/lib/validators/index.js +0 -120
- package/bin/runners/lib/validators/license-checker.js +0 -252
- package/bin/runners/lib/validators/route-validator.js +0 -290
- package/bin/runners/runAuthority.js +0 -528
- package/bin/runners/runConductor.js +0 -772
- package/bin/runners/runContainer.js +0 -366
- package/bin/runners/runEasy.js +0 -410
- package/bin/runners/runIaC.js +0 -372
- package/bin/runners/runVibe.js +0 -791
- package/mcp-server/tools.js +0 -495
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enterprise Audit Logger
|
|
3
|
-
*
|
|
4
|
-
* Comprehensive audit logging for:
|
|
5
|
-
* - Security events
|
|
6
|
-
* - Compliance tracking
|
|
7
|
-
* - User actions
|
|
8
|
-
* - System changes
|
|
9
|
-
* - Evidence generation
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const crypto = require("crypto");
|
|
15
|
-
const fs = require("fs");
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const os = require("os");
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Audit event categories
|
|
21
|
-
*/
|
|
22
|
-
const AUDIT_CATEGORIES = {
|
|
23
|
-
SECURITY: "security",
|
|
24
|
-
COMPLIANCE: "compliance",
|
|
25
|
-
ACCESS: "access",
|
|
26
|
-
CHANGE: "change",
|
|
27
|
-
SYSTEM: "system",
|
|
28
|
-
USER: "user",
|
|
29
|
-
SCAN: "scan",
|
|
30
|
-
DEPLOY: "deploy",
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Audit event severity levels
|
|
35
|
-
*/
|
|
36
|
-
const AUDIT_SEVERITY = {
|
|
37
|
-
CRITICAL: "critical",
|
|
38
|
-
HIGH: "high",
|
|
39
|
-
MEDIUM: "medium",
|
|
40
|
-
LOW: "low",
|
|
41
|
-
INFO: "info",
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Audit event types
|
|
46
|
-
*/
|
|
47
|
-
const AUDIT_EVENTS = {
|
|
48
|
-
// Security events
|
|
49
|
-
SECRET_DETECTED: { category: AUDIT_CATEGORIES.SECURITY, severity: AUDIT_SEVERITY.CRITICAL },
|
|
50
|
-
VULNERABILITY_FOUND: { category: AUDIT_CATEGORIES.SECURITY, severity: AUDIT_SEVERITY.HIGH },
|
|
51
|
-
AUTH_FAILURE: { category: AUDIT_CATEGORIES.SECURITY, severity: AUDIT_SEVERITY.HIGH },
|
|
52
|
-
AUTH_SUCCESS: { category: AUDIT_CATEGORIES.SECURITY, severity: AUDIT_SEVERITY.INFO },
|
|
53
|
-
POLICY_VIOLATION: { category: AUDIT_CATEGORIES.SECURITY, severity: AUDIT_SEVERITY.HIGH },
|
|
54
|
-
|
|
55
|
-
// Compliance events
|
|
56
|
-
SCAN_COMPLETED: { category: AUDIT_CATEGORIES.COMPLIANCE, severity: AUDIT_SEVERITY.INFO },
|
|
57
|
-
COMPLIANCE_CHECK: { category: AUDIT_CATEGORIES.COMPLIANCE, severity: AUDIT_SEVERITY.INFO },
|
|
58
|
-
CERTIFICATE_GENERATED: { category: AUDIT_CATEGORIES.COMPLIANCE, severity: AUDIT_SEVERITY.INFO },
|
|
59
|
-
REPORT_GENERATED: { category: AUDIT_CATEGORIES.COMPLIANCE, severity: AUDIT_SEVERITY.INFO },
|
|
60
|
-
|
|
61
|
-
// Access events
|
|
62
|
-
API_KEY_CREATED: { category: AUDIT_CATEGORIES.ACCESS, severity: AUDIT_SEVERITY.MEDIUM },
|
|
63
|
-
API_KEY_REVOKED: { category: AUDIT_CATEGORIES.ACCESS, severity: AUDIT_SEVERITY.MEDIUM },
|
|
64
|
-
API_KEY_USED: { category: AUDIT_CATEGORIES.ACCESS, severity: AUDIT_SEVERITY.INFO },
|
|
65
|
-
PERMISSION_CHANGED: { category: AUDIT_CATEGORIES.ACCESS, severity: AUDIT_SEVERITY.MEDIUM },
|
|
66
|
-
|
|
67
|
-
// Change events
|
|
68
|
-
CONFIG_CHANGED: { category: AUDIT_CATEGORIES.CHANGE, severity: AUDIT_SEVERITY.MEDIUM },
|
|
69
|
-
POLICY_CHANGED: { category: AUDIT_CATEGORIES.CHANGE, severity: AUDIT_SEVERITY.MEDIUM },
|
|
70
|
-
RULE_ADDED: { category: AUDIT_CATEGORIES.CHANGE, severity: AUDIT_SEVERITY.LOW },
|
|
71
|
-
RULE_REMOVED: { category: AUDIT_CATEGORIES.CHANGE, severity: AUDIT_SEVERITY.MEDIUM },
|
|
72
|
-
|
|
73
|
-
// System events
|
|
74
|
-
CLI_STARTED: { category: AUDIT_CATEGORIES.SYSTEM, severity: AUDIT_SEVERITY.INFO },
|
|
75
|
-
CLI_COMPLETED: { category: AUDIT_CATEGORIES.SYSTEM, severity: AUDIT_SEVERITY.INFO },
|
|
76
|
-
ERROR_OCCURRED: { category: AUDIT_CATEGORIES.SYSTEM, severity: AUDIT_SEVERITY.HIGH },
|
|
77
|
-
|
|
78
|
-
// User events
|
|
79
|
-
FIX_APPLIED: { category: AUDIT_CATEGORIES.USER, severity: AUDIT_SEVERITY.MEDIUM },
|
|
80
|
-
FINDING_SUPPRESSED: { category: AUDIT_CATEGORIES.USER, severity: AUDIT_SEVERITY.LOW },
|
|
81
|
-
OVERRIDE_REQUESTED: { category: AUDIT_CATEGORIES.USER, severity: AUDIT_SEVERITY.MEDIUM },
|
|
82
|
-
OVERRIDE_APPROVED: { category: AUDIT_CATEGORIES.USER, severity: AUDIT_SEVERITY.MEDIUM },
|
|
83
|
-
|
|
84
|
-
// Scan events
|
|
85
|
-
SCAN_STARTED: { category: AUDIT_CATEGORIES.SCAN, severity: AUDIT_SEVERITY.INFO },
|
|
86
|
-
FINDING_DETECTED: { category: AUDIT_CATEGORIES.SCAN, severity: AUDIT_SEVERITY.INFO },
|
|
87
|
-
VERDICT_ISSUED: { category: AUDIT_CATEGORIES.SCAN, severity: AUDIT_SEVERITY.INFO },
|
|
88
|
-
|
|
89
|
-
// Deploy events
|
|
90
|
-
DEPLOY_BLOCKED: { category: AUDIT_CATEGORIES.DEPLOY, severity: AUDIT_SEVERITY.HIGH },
|
|
91
|
-
DEPLOY_APPROVED: { category: AUDIT_CATEGORIES.DEPLOY, severity: AUDIT_SEVERITY.INFO },
|
|
92
|
-
GATE_CHECK_FAILED: { category: AUDIT_CATEGORIES.DEPLOY, severity: AUDIT_SEVERITY.HIGH },
|
|
93
|
-
GATE_CHECK_PASSED: { category: AUDIT_CATEGORIES.DEPLOY, severity: AUDIT_SEVERITY.INFO },
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Audit log entry structure
|
|
98
|
-
*/
|
|
99
|
-
class AuditEntry {
|
|
100
|
-
constructor(eventType, data = {}) {
|
|
101
|
-
const eventConfig = AUDIT_EVENTS[eventType] || {
|
|
102
|
-
category: AUDIT_CATEGORIES.SYSTEM,
|
|
103
|
-
severity: AUDIT_SEVERITY.INFO
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
this.id = crypto.randomUUID();
|
|
107
|
-
this.timestamp = new Date().toISOString();
|
|
108
|
-
this.eventType = eventType;
|
|
109
|
-
this.category = eventConfig.category;
|
|
110
|
-
this.severity = eventConfig.severity;
|
|
111
|
-
this.data = data;
|
|
112
|
-
this.context = this.buildContext();
|
|
113
|
-
this.hash = null;
|
|
114
|
-
|
|
115
|
-
// Generate tamper-evident hash
|
|
116
|
-
this.hash = this.generateHash();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
buildContext() {
|
|
120
|
-
return {
|
|
121
|
-
hostname: os.hostname(),
|
|
122
|
-
platform: os.platform(),
|
|
123
|
-
arch: os.arch(),
|
|
124
|
-
nodeVersion: process.version,
|
|
125
|
-
pid: process.pid,
|
|
126
|
-
cwd: process.cwd(),
|
|
127
|
-
user: os.userInfo().username,
|
|
128
|
-
environment: process.env.NODE_ENV || "development",
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
generateHash() {
|
|
133
|
-
const content = JSON.stringify({
|
|
134
|
-
id: this.id,
|
|
135
|
-
timestamp: this.timestamp,
|
|
136
|
-
eventType: this.eventType,
|
|
137
|
-
category: this.category,
|
|
138
|
-
data: this.data,
|
|
139
|
-
});
|
|
140
|
-
return crypto.createHash("sha256").update(content).digest("hex").substring(0, 16);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
toJSON() {
|
|
144
|
-
return {
|
|
145
|
-
id: this.id,
|
|
146
|
-
timestamp: this.timestamp,
|
|
147
|
-
eventType: this.eventType,
|
|
148
|
-
category: this.category,
|
|
149
|
-
severity: this.severity,
|
|
150
|
-
data: this.data,
|
|
151
|
-
context: this.context,
|
|
152
|
-
hash: this.hash,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Audit logger class
|
|
159
|
-
*/
|
|
160
|
-
class AuditLogger {
|
|
161
|
-
constructor(options = {}) {
|
|
162
|
-
this.options = {
|
|
163
|
-
logDir: options.logDir || path.join(process.cwd(), ".vibecheck", "audit"),
|
|
164
|
-
maxLogSize: options.maxLogSize || 10 * 1024 * 1024, // 10MB
|
|
165
|
-
maxLogFiles: options.maxLogFiles || 30,
|
|
166
|
-
enableConsole: options.enableConsole !== false,
|
|
167
|
-
enableFile: options.enableFile !== false,
|
|
168
|
-
enableRemote: options.enableRemote || false,
|
|
169
|
-
remoteEndpoint: options.remoteEndpoint,
|
|
170
|
-
encryptLogs: options.encryptLogs || false,
|
|
171
|
-
encryptionKey: options.encryptionKey,
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
this.sessionId = crypto.randomUUID();
|
|
175
|
-
this.entryCount = 0;
|
|
176
|
-
this.previousHash = null;
|
|
177
|
-
|
|
178
|
-
if (this.options.enableFile) {
|
|
179
|
-
this.ensureLogDir();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
ensureLogDir() {
|
|
184
|
-
if (!fs.existsSync(this.options.logDir)) {
|
|
185
|
-
fs.mkdirSync(this.options.logDir, { recursive: true });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Log an audit event
|
|
191
|
-
*/
|
|
192
|
-
log(eventType, data = {}) {
|
|
193
|
-
const entry = new AuditEntry(eventType, {
|
|
194
|
-
...data,
|
|
195
|
-
sessionId: this.sessionId,
|
|
196
|
-
entryNumber: ++this.entryCount,
|
|
197
|
-
previousHash: this.previousHash,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
this.previousHash = entry.hash;
|
|
201
|
-
|
|
202
|
-
// Write to various destinations
|
|
203
|
-
if (this.options.enableFile) {
|
|
204
|
-
this.writeToFile(entry);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (this.options.enableRemote) {
|
|
208
|
-
this.sendToRemote(entry);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return entry;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Log security event
|
|
216
|
-
*/
|
|
217
|
-
security(eventType, data = {}) {
|
|
218
|
-
return this.log(eventType, { ...data, _auditCategory: AUDIT_CATEGORIES.SECURITY });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Log compliance event
|
|
223
|
-
*/
|
|
224
|
-
compliance(eventType, data = {}) {
|
|
225
|
-
return this.log(eventType, { ...data, _auditCategory: AUDIT_CATEGORIES.COMPLIANCE });
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Log access event
|
|
230
|
-
*/
|
|
231
|
-
access(eventType, data = {}) {
|
|
232
|
-
return this.log(eventType, { ...data, _auditCategory: AUDIT_CATEGORIES.ACCESS });
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Write entry to log file
|
|
237
|
-
*/
|
|
238
|
-
writeToFile(entry) {
|
|
239
|
-
const date = new Date().toISOString().split("T")[0];
|
|
240
|
-
const logFile = path.join(this.options.logDir, `audit-${date}.jsonl`);
|
|
241
|
-
|
|
242
|
-
let line = JSON.stringify(entry.toJSON()) + "\n";
|
|
243
|
-
|
|
244
|
-
if (this.options.encryptLogs && this.options.encryptionKey) {
|
|
245
|
-
line = this.encryptLine(line);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
fs.appendFileSync(logFile, line);
|
|
250
|
-
this.rotateLogsIfNeeded();
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error("Failed to write audit log:", error.message);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Encrypt a log line
|
|
258
|
-
*/
|
|
259
|
-
encryptLine(line) {
|
|
260
|
-
const iv = crypto.randomBytes(16);
|
|
261
|
-
const cipher = crypto.createCipheriv("aes-256-gcm", this.options.encryptionKey, iv);
|
|
262
|
-
let encrypted = cipher.update(line, "utf8", "hex");
|
|
263
|
-
encrypted += cipher.final("hex");
|
|
264
|
-
const tag = cipher.getAuthTag();
|
|
265
|
-
return JSON.stringify({
|
|
266
|
-
iv: iv.toString("hex"),
|
|
267
|
-
tag: tag.toString("hex"),
|
|
268
|
-
data: encrypted,
|
|
269
|
-
}) + "\n";
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Send entry to remote endpoint
|
|
274
|
-
*/
|
|
275
|
-
async sendToRemote(entry) {
|
|
276
|
-
if (!this.options.remoteEndpoint) return;
|
|
277
|
-
|
|
278
|
-
try {
|
|
279
|
-
const response = await fetch(this.options.remoteEndpoint, {
|
|
280
|
-
method: "POST",
|
|
281
|
-
headers: {
|
|
282
|
-
"Content-Type": "application/json",
|
|
283
|
-
},
|
|
284
|
-
body: JSON.stringify(entry.toJSON()),
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
if (!response.ok) {
|
|
288
|
-
console.error("Failed to send audit log to remote:", response.status);
|
|
289
|
-
}
|
|
290
|
-
} catch (error) {
|
|
291
|
-
console.error("Failed to send audit log to remote:", error.message);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Rotate log files if needed
|
|
297
|
-
*/
|
|
298
|
-
rotateLogsIfNeeded() {
|
|
299
|
-
try {
|
|
300
|
-
const files = fs.readdirSync(this.options.logDir)
|
|
301
|
-
.filter(f => f.startsWith("audit-") && f.endsWith(".jsonl"))
|
|
302
|
-
.sort()
|
|
303
|
-
.reverse();
|
|
304
|
-
|
|
305
|
-
// Remove old files
|
|
306
|
-
while (files.length > this.options.maxLogFiles) {
|
|
307
|
-
const oldFile = files.pop();
|
|
308
|
-
fs.unlinkSync(path.join(this.options.logDir, oldFile));
|
|
309
|
-
}
|
|
310
|
-
} catch (error) {
|
|
311
|
-
// Ignore rotation errors
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Query audit logs
|
|
317
|
-
*/
|
|
318
|
-
query(options = {}) {
|
|
319
|
-
const {
|
|
320
|
-
startDate,
|
|
321
|
-
endDate,
|
|
322
|
-
eventTypes,
|
|
323
|
-
categories,
|
|
324
|
-
severities,
|
|
325
|
-
limit = 1000,
|
|
326
|
-
} = options;
|
|
327
|
-
|
|
328
|
-
const results = [];
|
|
329
|
-
const files = fs.readdirSync(this.options.logDir)
|
|
330
|
-
.filter(f => f.startsWith("audit-") && f.endsWith(".jsonl"))
|
|
331
|
-
.sort()
|
|
332
|
-
.reverse();
|
|
333
|
-
|
|
334
|
-
for (const file of files) {
|
|
335
|
-
const filePath = path.join(this.options.logDir, file);
|
|
336
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
337
|
-
const lines = content.trim().split("\n");
|
|
338
|
-
|
|
339
|
-
for (const line of lines) {
|
|
340
|
-
if (results.length >= limit) break;
|
|
341
|
-
|
|
342
|
-
try {
|
|
343
|
-
const entry = JSON.parse(line);
|
|
344
|
-
|
|
345
|
-
// Apply filters
|
|
346
|
-
if (startDate && new Date(entry.timestamp) < new Date(startDate)) continue;
|
|
347
|
-
if (endDate && new Date(entry.timestamp) > new Date(endDate)) continue;
|
|
348
|
-
if (eventTypes && !eventTypes.includes(entry.eventType)) continue;
|
|
349
|
-
if (categories && !categories.includes(entry.category)) continue;
|
|
350
|
-
if (severities && !severities.includes(entry.severity)) continue;
|
|
351
|
-
|
|
352
|
-
results.push(entry);
|
|
353
|
-
} catch {
|
|
354
|
-
// Skip malformed lines
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (results.length >= limit) break;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return results;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Verify audit log integrity
|
|
366
|
-
*/
|
|
367
|
-
verifyIntegrity() {
|
|
368
|
-
const results = {
|
|
369
|
-
verified: 0,
|
|
370
|
-
failed: 0,
|
|
371
|
-
gaps: 0,
|
|
372
|
-
issues: [],
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
const files = fs.readdirSync(this.options.logDir)
|
|
376
|
-
.filter(f => f.startsWith("audit-") && f.endsWith(".jsonl"))
|
|
377
|
-
.sort();
|
|
378
|
-
|
|
379
|
-
let previousHash = null;
|
|
380
|
-
|
|
381
|
-
for (const file of files) {
|
|
382
|
-
const filePath = path.join(this.options.logDir, file);
|
|
383
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
384
|
-
const lines = content.trim().split("\n");
|
|
385
|
-
|
|
386
|
-
for (const line of lines) {
|
|
387
|
-
try {
|
|
388
|
-
const entry = JSON.parse(line);
|
|
389
|
-
|
|
390
|
-
// Verify hash
|
|
391
|
-
const expectedHash = crypto.createHash("sha256")
|
|
392
|
-
.update(JSON.stringify({
|
|
393
|
-
id: entry.id,
|
|
394
|
-
timestamp: entry.timestamp,
|
|
395
|
-
eventType: entry.eventType,
|
|
396
|
-
category: entry.category,
|
|
397
|
-
data: entry.data,
|
|
398
|
-
}))
|
|
399
|
-
.digest("hex")
|
|
400
|
-
.substring(0, 16);
|
|
401
|
-
|
|
402
|
-
if (entry.hash !== expectedHash) {
|
|
403
|
-
results.failed++;
|
|
404
|
-
results.issues.push({
|
|
405
|
-
id: entry.id,
|
|
406
|
-
issue: "hash_mismatch",
|
|
407
|
-
expected: expectedHash,
|
|
408
|
-
actual: entry.hash,
|
|
409
|
-
});
|
|
410
|
-
} else {
|
|
411
|
-
results.verified++;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Verify chain
|
|
415
|
-
if (entry.data?.previousHash && entry.data.previousHash !== previousHash) {
|
|
416
|
-
results.gaps++;
|
|
417
|
-
results.issues.push({
|
|
418
|
-
id: entry.id,
|
|
419
|
-
issue: "chain_break",
|
|
420
|
-
expected: previousHash,
|
|
421
|
-
actual: entry.data.previousHash,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
previousHash = entry.hash;
|
|
426
|
-
} catch {
|
|
427
|
-
results.failed++;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
return results;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Export audit logs for compliance
|
|
437
|
-
*/
|
|
438
|
-
exportForCompliance(options = {}) {
|
|
439
|
-
const { format = "json", startDate, endDate } = options;
|
|
440
|
-
const entries = this.query({ startDate, endDate, limit: Infinity });
|
|
441
|
-
|
|
442
|
-
if (format === "json") {
|
|
443
|
-
return JSON.stringify(entries, null, 2);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (format === "csv") {
|
|
447
|
-
const headers = ["id", "timestamp", "eventType", "category", "severity", "hash"];
|
|
448
|
-
const rows = entries.map(e => [
|
|
449
|
-
e.id,
|
|
450
|
-
e.timestamp,
|
|
451
|
-
e.eventType,
|
|
452
|
-
e.category,
|
|
453
|
-
e.severity,
|
|
454
|
-
e.hash,
|
|
455
|
-
]);
|
|
456
|
-
return [headers.join(","), ...rows.map(r => r.join(","))].join("\n");
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (format === "siem") {
|
|
460
|
-
// Common Event Format (CEF) for SIEM integration
|
|
461
|
-
return entries.map(e => {
|
|
462
|
-
const severity = { critical: 10, high: 7, medium: 4, low: 2, info: 1 }[e.severity] || 1;
|
|
463
|
-
return `CEF:0|VibeCheck|CLI|1.0|${e.eventType}|${e.eventType}|${severity}|rt=${new Date(e.timestamp).getTime()} src=${e.context?.hostname} suser=${e.context?.user}`;
|
|
464
|
-
}).join("\n");
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return JSON.stringify(entries);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Get audit statistics
|
|
472
|
-
*/
|
|
473
|
-
getStatistics(days = 30) {
|
|
474
|
-
const startDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString();
|
|
475
|
-
const entries = this.query({ startDate });
|
|
476
|
-
|
|
477
|
-
const stats = {
|
|
478
|
-
totalEvents: entries.length,
|
|
479
|
-
byCategory: {},
|
|
480
|
-
bySeverity: {},
|
|
481
|
-
byEventType: {},
|
|
482
|
-
dailyTrend: {},
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
for (const entry of entries) {
|
|
486
|
-
// By category
|
|
487
|
-
stats.byCategory[entry.category] = (stats.byCategory[entry.category] || 0) + 1;
|
|
488
|
-
|
|
489
|
-
// By severity
|
|
490
|
-
stats.bySeverity[entry.severity] = (stats.bySeverity[entry.severity] || 0) + 1;
|
|
491
|
-
|
|
492
|
-
// By event type
|
|
493
|
-
stats.byEventType[entry.eventType] = (stats.byEventType[entry.eventType] || 0) + 1;
|
|
494
|
-
|
|
495
|
-
// Daily trend
|
|
496
|
-
const date = entry.timestamp.split("T")[0];
|
|
497
|
-
stats.dailyTrend[date] = (stats.dailyTrend[date] || 0) + 1;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
return stats;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Singleton instance
|
|
505
|
-
let _instance = null;
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Get or create audit logger instance
|
|
509
|
-
*/
|
|
510
|
-
function getAuditLogger(options = {}) {
|
|
511
|
-
if (!_instance) {
|
|
512
|
-
_instance = new AuditLogger(options);
|
|
513
|
-
}
|
|
514
|
-
return _instance;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Quick log helper
|
|
519
|
-
*/
|
|
520
|
-
function auditLog(eventType, data = {}) {
|
|
521
|
-
return getAuditLogger().log(eventType, data);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
module.exports = {
|
|
525
|
-
AuditLogger,
|
|
526
|
-
AuditEntry,
|
|
527
|
-
getAuditLogger,
|
|
528
|
-
auditLog,
|
|
529
|
-
AUDIT_CATEGORIES,
|
|
530
|
-
AUDIT_SEVERITY,
|
|
531
|
-
AUDIT_EVENTS,
|
|
532
|
-
};
|