@yagyeshvyas/vibeguard 0.1.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 (52) hide show
  1. package/README.md +600 -0
  2. package/bin/cli.js +1640 -0
  3. package/ci/vibeguard.yml +41 -0
  4. package/ci-templates/Jenkinsfile +26 -0
  5. package/ci-templates/azure-pipelines.yml +29 -0
  6. package/ci-templates/circleci.yml +24 -0
  7. package/ci-templates/gitlab.yml +19 -0
  8. package/hooks/pre-commit +31 -0
  9. package/package.json +94 -0
  10. package/src/ai-guard.js +205 -0
  11. package/src/ast.js +319 -0
  12. package/src/audit-trail.js +154 -0
  13. package/src/autofix.js +524 -0
  14. package/src/badge.js +42 -0
  15. package/src/behavior.js +205 -0
  16. package/src/compliance.js +151 -0
  17. package/src/crosstaint.js +324 -0
  18. package/src/cve-intel.js +136 -0
  19. package/src/dashboard.js +279 -0
  20. package/src/deps.js +159 -0
  21. package/src/doctor.js +111 -0
  22. package/src/engine.js +234 -0
  23. package/src/external.js +160 -0
  24. package/src/firewall.js +517 -0
  25. package/src/history.js +87 -0
  26. package/src/hook.js +151 -0
  27. package/src/install.js +248 -0
  28. package/src/interceptor.js +476 -0
  29. package/src/mcp-server.js +1804 -0
  30. package/src/net-audit.js +208 -0
  31. package/src/pii.js +212 -0
  32. package/src/plugin.js +80 -0
  33. package/src/policy-gen.js +288 -0
  34. package/src/pre-deploy.js +282 -0
  35. package/src/presets.js +113 -0
  36. package/src/privacy-audit.js +273 -0
  37. package/src/repl.js +150 -0
  38. package/src/report.js +312 -0
  39. package/src/rules-pack.js +2753 -0
  40. package/src/rules.js +1446 -0
  41. package/src/sandbox.js +139 -0
  42. package/src/scanner.js +651 -0
  43. package/src/secure-prompt.js +140 -0
  44. package/src/slopsquat.js +144 -0
  45. package/src/supply-firewall.js +243 -0
  46. package/src/suppress.js +89 -0
  47. package/src/taint.js +168 -0
  48. package/src/trace.js +220 -0
  49. package/src/urlscan.js +142 -0
  50. package/src/vault.js +145 -0
  51. package/src/verify.js +98 -0
  52. package/src/verifykeys.js +87 -0
package/src/report.js ADDED
@@ -0,0 +1,312 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Rendering: human report (colored), JSON, SARIF, and the copy-paste fix prompt.
5
+ * No dependencies — colors are raw ANSI, disabled when not a TTY or NO_COLOR set.
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ const useColor =
11
+ process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== 'dumb';
12
+
13
+ const C = {
14
+ reset: useColor ? '\x1b[0m' : '',
15
+ bold: useColor ? '\x1b[1m' : '',
16
+ dim: useColor ? '\x1b[2m' : '',
17
+ red: useColor ? '\x1b[31m' : '',
18
+ green: useColor ? '\x1b[32m' : '',
19
+ yellow: useColor ? '\x1b[33m' : '',
20
+ blue: useColor ? '\x1b[34m' : '',
21
+ magenta: useColor ? '\x1b[35m' : '',
22
+ cyan: useColor ? '\x1b[36m' : '',
23
+ gray: useColor ? '\x1b[90m' : '',
24
+ };
25
+
26
+ const SEV_STYLE = {
27
+ critical: { color: C.red, label: 'CRITICAL' },
28
+ high: { color: C.magenta, label: 'HIGH' },
29
+ medium: { color: C.yellow, label: 'MEDIUM' },
30
+ low: { color: C.blue, label: 'LOW' },
31
+ };
32
+
33
+ const GRADE_COLOR = {
34
+ A: C.green, B: C.green, C: C.yellow, D: C.yellow, F: C.red,
35
+ };
36
+
37
+ function severityBadge(sev) {
38
+ const s = SEV_STYLE[sev] || { color: C.gray, label: sev.toUpperCase() };
39
+ return `${s.color}${C.bold}${s.label.padEnd(8)}${C.reset}`;
40
+ }
41
+
42
+ // -------- Human report -----------------------------------------------------
43
+
44
+ function renderHuman(result) {
45
+ const lines = [];
46
+ lines.push('');
47
+ lines.push(`${C.bold}${C.cyan}VibeGuard${C.reset} ${C.dim}security scan${C.reset}`);
48
+ lines.push(`${C.dim}${result.root}${C.reset}`);
49
+ lines.push('');
50
+
51
+ if (result.findings.length === 0) {
52
+ lines.push(`${C.green}${C.bold}No issues found across ${result.scannedFiles} files.${C.reset}`);
53
+ } else {
54
+ for (const f of result.findings) {
55
+ const loc = `${f.file}:${f.line}:${f.column}`;
56
+ const conf =
57
+ f.confidence === 'low'
58
+ ? ` ${C.yellow}⚑ review${C.reset}`
59
+ : f.confidence === 'medium'
60
+ ? ` ${C.dim}⚑ likely${C.reset}`
61
+ : '';
62
+ lines.push(
63
+ `${severityBadge(f.severity)} ${C.bold}${loc}${C.reset}${conf} ${C.dim}[${f.ruleId}]${C.reset}`
64
+ );
65
+ lines.push(` ${f.message}`);
66
+ if (f.snippet) lines.push(` ${C.gray}${f.snippet}${C.reset}`);
67
+ lines.push(` ${C.green}fix:${C.reset} ${f.fix}`);
68
+ lines.push('');
69
+ }
70
+ }
71
+
72
+ lines.push(renderSummaryLine(result));
73
+ lines.push('');
74
+ lines.push(
75
+ `${C.dim}VibeGuard checks high-frequency, well-defined issues (secrets, injection, misconfig).`
76
+ );
77
+ lines.push(
78
+ `It does not prove an app is safe and cannot catch every logic bug or backdoor.${C.reset}`
79
+ );
80
+ lines.push('');
81
+ return lines.join('\n');
82
+ }
83
+
84
+ function renderSummaryLine(result) {
85
+ const { counts, grade } = result;
86
+ const gc = GRADE_COLOR[grade] || C.gray;
87
+ const parts = [
88
+ `${C.red}${counts.critical} critical${C.reset}`,
89
+ `${C.magenta}${counts.high} high${C.reset}`,
90
+ `${C.yellow}${counts.medium} medium${C.reset}`,
91
+ `${C.blue}${counts.low} low${C.reset}`,
92
+ ];
93
+ return (
94
+ `${C.bold}Grade ${gc}${grade}${C.reset} ` +
95
+ `${C.dim}(${result.scannedFiles} files)${C.reset} ` +
96
+ parts.join(' ')
97
+ );
98
+ }
99
+
100
+ // -------- JSON -------------------------------------------------------------
101
+
102
+ function renderJson(result) {
103
+ return JSON.stringify(
104
+ {
105
+ tool: 'vibeguard',
106
+ version: require('../package.json').version,
107
+ root: result.root,
108
+ generatedAt: result.generatedAt,
109
+ grade: result.grade,
110
+ counts: result.counts,
111
+ scannedFiles: result.scannedFiles,
112
+ depsInfo: result.depsInfo || null,
113
+ externalInfo: result.externalInfo || null,
114
+ findings: result.findings,
115
+ },
116
+ null,
117
+ 2
118
+ );
119
+ }
120
+
121
+ // -------- SARIF 2.1.0 ------------------------------------------------------
122
+
123
+ const SARIF_LEVEL = {
124
+ critical: 'error',
125
+ high: 'error',
126
+ medium: 'warning',
127
+ low: 'note',
128
+ };
129
+
130
+ function renderSarif(result) {
131
+ const ruleIndex = new Map();
132
+ const rules = [];
133
+ for (const f of result.findings) {
134
+ if (!ruleIndex.has(f.ruleId)) {
135
+ ruleIndex.set(f.ruleId, rules.length);
136
+ rules.push({
137
+ id: f.ruleId,
138
+ name: f.title || f.ruleId,
139
+ shortDescription: { text: f.title || f.ruleId },
140
+ fullDescription: { text: f.message },
141
+ helpUri: 'https://github.com/vibeguard/vibeguard#rules',
142
+ properties: {
143
+ security_severity: f.severity,
144
+ tags: [
145
+ f.cwe ? f.cwe : null,
146
+ f.owasp ? f.owasp : null,
147
+ f.confidence ? 'confidence:' + f.confidence : null,
148
+ ].filter(Boolean),
149
+ },
150
+ defaultConfiguration: { level: SARIF_LEVEL[f.severity] || 'warning' },
151
+ });
152
+ }
153
+ }
154
+
155
+ const results = result.findings.map((f) => ({
156
+ ruleId: f.ruleId,
157
+ ruleIndex: ruleIndex.get(f.ruleId),
158
+ level: SARIF_LEVEL[f.severity] || 'warning',
159
+ properties: { severity: f.severity, confidence: f.confidence },
160
+ partialFingerprints: f.fingerprint ? { vibeguard: f.fingerprint } : undefined,
161
+ message: { text: `${f.message} Fix: ${f.fix}` },
162
+ locations: [
163
+ {
164
+ physicalLocation: {
165
+ artifactLocation: { uri: f.file },
166
+ region: { startLine: f.line, startColumn: f.column },
167
+ },
168
+ },
169
+ ],
170
+ }));
171
+
172
+ return JSON.stringify(
173
+ {
174
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
175
+ version: '2.1.0',
176
+ runs: [
177
+ {
178
+ tool: {
179
+ driver: {
180
+ name: 'VibeGuard',
181
+ informationUri: 'https://github.com/vibeguard/vibeguard',
182
+ version: require('../package.json').version,
183
+ rules,
184
+ },
185
+ },
186
+ results,
187
+ },
188
+ ],
189
+ },
190
+ null,
191
+ 2
192
+ );
193
+ }
194
+
195
+ // -------- Fix prompt (paste back into your AI tool) ------------------------
196
+
197
+ function renderFixPrompt(result) {
198
+ if (result.findings.length === 0) {
199
+ return 'VibeGuard found no issues — nothing to fix.';
200
+ }
201
+ const lines = [];
202
+ lines.push(
203
+ 'You are fixing security issues found by VibeGuard. Apply the minimal, safe change for each item below. Do not change unrelated code. For any leaked secret, also tell me to rotate it.'
204
+ );
205
+ lines.push('');
206
+ lines.push(`Overall grade: ${result.grade}.`);
207
+ lines.push('');
208
+
209
+ const actNow = result.findings.filter((f) => f.confidence !== 'low');
210
+ const review = result.findings.filter((f) => f.confidence === 'low');
211
+
212
+ let n = 1;
213
+ if (actNow.length) {
214
+ lines.push('APPLY THESE FIXES (high/medium confidence):');
215
+ for (const f of actNow) {
216
+ lines.push(`${n}. [${f.severity.toUpperCase()}] ${f.file}:${f.line} — ${f.message}`);
217
+ lines.push(` Fix: ${f.fix}`);
218
+ n++;
219
+ }
220
+ lines.push('');
221
+ }
222
+ if (review.length) {
223
+ lines.push(
224
+ 'REVIEW THESE — heuristic hints, verify before changing (do NOT blindly rewrite):'
225
+ );
226
+ for (const f of review) {
227
+ lines.push(`${n}. [${f.severity.toUpperCase()}, review] ${f.file}:${f.line} — ${f.message}`);
228
+ lines.push(` Suggested: ${f.fix}`);
229
+ n++;
230
+ }
231
+ lines.push('');
232
+ }
233
+ lines.push(
234
+ 'After applying fixes, I will re-run `vibeguard verify` to confirm each issue is resolved.'
235
+ );
236
+ return lines.join('\n');
237
+ }
238
+
239
+ function renderHtml(result) {
240
+ const c = result.counts;
241
+ const findings = result.findings || [];
242
+ const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
243
+ for (const f of findings) bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
244
+
245
+ const gradeColor = { A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444' };
246
+ const sevColor = { critical: '#ef4444', high: '#f97316', medium: '#eab308', low: '#3b82f6' };
247
+
248
+ const rows = findings.map(f => ` <tr>
249
+ <td><span class="sev sev-${f.severity}">${f.severity}</span></td>
250
+ <td><code>${esc(f.ruleId)}</code></td>
251
+ <td><code>${esc(f.file)}:${f.line}</code></td>
252
+ <td>${esc(f.message || '')}</td>
253
+ <td>${esc(f.fix || '')}</td>
254
+ </tr>`).join('\n');
255
+
256
+ return `<!DOCTYPE html>
257
+ <html lang="en">
258
+ <head>
259
+ <meta charset="utf-8">
260
+ <meta name="viewport" content="width=device-width, initial-scale=1">
261
+ <title>VibeGuard Security Report</title>
262
+ <style>
263
+ body { font-family: -apple-system, system-ui, sans-serif; max-width: 1100px; margin: 0 auto; padding: 20px; color: #1a1a1a; }
264
+ .grade { font-size: 72px; font-weight: 800; text-align: center; padding: 20px; border-radius: 12px; color: white; width: 120px; height: 120px; line-height: 120px; margin: 0 auto; }
265
+ .summary { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }
266
+ .stat { text-align: center; padding: 12px 24px; border-radius: 8px; background: #f3f4f6; }
267
+ .stat .num { font-size: 28px; font-weight: 700; }
268
+ .stat .label { font-size: 12px; color: #6b7280; text-transform: uppercase; }
269
+ table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 13px; }
270
+ th { text-align: left; padding: 8px 12px; background: #f9fafb; border-bottom: 2px solid #e5e7eb; }
271
+ td { padding: 8px 12px; border-bottom: 1px solid #f3f4f6; }
272
+ .sev { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; color: white; }
273
+ .sev-critical { background: #ef4444; }
274
+ .sev-high { background: #f97316; }
275
+ .sev-medium { background: #eab308; }
276
+ .sev-low { background: #3b82f6; }
277
+ code { background: #f3f4f6; padding: 2px 4px; border-radius: 3px; font-size: 12px; }
278
+ h1 { text-align: center; }
279
+ .meta { text-align: center; color: #6b7280; font-size: 13px; margin-bottom: 20px; }
280
+ </style>
281
+ </head>
282
+ <body>
283
+ <h1>VibeGuard Security Report</h1>
284
+ <div class="meta">${esc(result.root || '')} — ${result.scannedFiles} files scanned — ${result.generatedAt || new Date().toISOString()}</div>
285
+ <div class="grade" style="background:${gradeColor[result.grade] || '#6b7280'}">${result.grade}</div>
286
+ <div class="summary">
287
+ <div class="stat"><div class="num" style="color:#ef4444">${bySeverity.critical}</div><div class="label">Critical</div></div>
288
+ <div class="stat"><div class="num" style="color:#f97316">${bySeverity.high}</div><div class="label">High</div></div>
289
+ <div class="stat"><div class="num" style="color:#eab308">${bySeverity.medium}</div><div class="label">Medium</div></div>
290
+ <div class="stat"><div class="num" style="color:#3b82f6">${bySeverity.low}</div><div class="label">Low</div></div>
291
+ </div>
292
+ ${findings.length > 0 ? `<table>
293
+ <thead><tr><th>Severity</th><th>Rule</th><th>Location</th><th>Message</th><th>Fix</th></tr></thead>
294
+ <tbody>
295
+ ${rows}
296
+ </tbody>
297
+ </table>` : '<p style="text-align:center;color:#22c55e;font-size:18px;">No findings. Clean!</p>'}
298
+ </body>
299
+ </html>`;
300
+ }
301
+
302
+ function esc(s) { return String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); }
303
+
304
+ module.exports = {
305
+ renderHuman,
306
+ renderJson,
307
+ renderSarif,
308
+ renderHtml,
309
+ renderFixPrompt,
310
+ renderSummaryLine,
311
+ C,
312
+ };