@yagyeshvyas/vibeguard 1.13.0 → 1.13.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +18 -2
  3. package/bin/cli.js +2753 -2753
  4. package/ci/vibeguard.yml +42 -42
  5. package/package.json +1 -1
  6. package/scripts/counts.js +93 -93
  7. package/scripts/postinstall.js +26 -26
  8. package/src/auto.js +427 -427
  9. package/src/daemon.js +343 -343
  10. package/src/dashboard.js +278 -278
  11. package/src/engine.js +297 -297
  12. package/src/hook.js +151 -151
  13. package/src/install.js +298 -298
  14. package/src/integrity.json +1 -1
  15. package/src/plugin.js +182 -182
  16. package/src/privacy-audit.js +272 -272
  17. package/src/repl.js +150 -150
  18. package/src/report.js +331 -331
  19. package/src/rules-pack.js +3068 -3068
  20. package/src/rules.js +1822 -1822
  21. package/src/sbom.js +193 -193
  22. package/src/scanner.js +1032 -1032
  23. package/src/shell-guard.js +302 -302
  24. package/src/slopsquat.js +144 -144
  25. package/src/trace.js +220 -220
  26. package/src/.vibeguard/cache/file-hashes.json +0 -60
  27. package/src/.vibeguard/latest-snapshot.json +0 -36
  28. package/src/.vibeguard/mcp-pins.json +0 -1
  29. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +0 -428
  30. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +0 -344
  31. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +0 -279
  32. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +0 -297
  33. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +0 -151
  34. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +0 -299
  35. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +0 -65
  36. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +0 -2051
  37. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +0 -168
  38. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +0 -362
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +0 -150
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +0 -1611
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +0 -164
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +0 -292
  43. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +0 -144
  44. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +0 -220
  45. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +0 -428
  46. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +0 -344
  47. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +0 -297
  48. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +0 -299
  49. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +0 -37
  50. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +0 -2055
  51. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +0 -168
  52. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +0 -362
  53. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +0 -220
  54. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +0 -428
  55. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +0 -344
  56. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +0 -279
  57. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +0 -297
  58. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +0 -151
  59. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +0 -299
  60. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +0 -65
  61. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +0 -2055
  62. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +0 -168
  63. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +0 -362
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +0 -150
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +0 -1611
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +0 -164
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +0 -292
  68. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +0 -144
  69. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +0 -220
  70. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +0 -428
  71. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +0 -344
  72. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +0 -279
  73. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +0 -297
  74. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +0 -151
  75. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +0 -299
  76. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +0 -65
  77. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +0 -2054
  78. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +0 -168
  79. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +0 -362
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +0 -150
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +0 -1611
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +0 -164
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +0 -292
  84. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +0 -144
  85. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +0 -220
  86. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +0 -428
  87. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +0 -344
  88. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +0 -297
  89. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +0 -299
  90. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +0 -37
  91. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +0 -2055
  92. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +0 -168
  93. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +0 -362
  94. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +0 -220
  95. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +0 -428
  96. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +0 -344
  97. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +0 -297
  98. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +0 -33
  99. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +0 -2055
  100. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +0 -1611
  101. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +0 -292
  102. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +0 -220
  103. package/src/.vibeguard-baseline.json +0 -5226
@@ -1,273 +1,273 @@
1
- 'use strict';
2
-
3
- /*
4
- * VibeGuard Privacy Audit.
5
- *
6
- * Scans the codebase for all data collection, storage, and transmission points.
7
- * Builds a privacy inventory showing:
8
- * - What PII is collected (forms, inputs, API params)
9
- * - Where PII is stored (DB, localStorage, cookies, files)
10
- * - Where PII is sent (external APIs, analytics, AI providers)
11
- * - What consent mechanisms exist (or are missing)
12
- * - What data retention policies exist (or are missing)
13
- * - What encryption exists (or is missing)
14
- *
15
- * 100% local. Zero network. Zero dependencies.
16
- */
17
-
18
- const fs = require('fs');
19
- const path = require('path');
20
-
21
- const PII_FIELDS = /\b(?:email|phone|ssn|social_security|creditcard|credit_card|card_number|cvv|cvc|passport|dob|date_of_birth|bank_account|routing_number|address|zip|postal|first_name|last_name|fullname|birth|gender|nationality|ip_address|mac_address|device_id|biometric|fingerprint|location|latitude|longitude|avatar|profile_pic)\b/gi;
22
-
23
- const STORAGE_SINKS = [
24
- { re: /localStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'localStorage', risk: 'high', reason: 'XSS can read localStorage. Use HTTP-only cookies for auth tokens.' },
25
- { re: /sessionStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'sessionStorage', risk: 'high', reason: 'XSS can read sessionStorage. Use HTTP-only cookies.' },
26
- { re: /document\.cookie\s*=\s*['"]?([^=;'"]+)/gi, type: 'cookie', risk: 'medium', reason: 'Verify Secure, HttpOnly, SameSite flags are set.' },
27
- { re: /IndexedDB|indexedDB\.open/gi, type: 'IndexedDB', risk: 'medium', reason: 'Persistent browser storage. XSS accessible. Do not store PII here.' },
28
- { re: /SharedPreferences|getSharedPreferences/gi, type: 'SharedPreferences (Android)', risk: 'high', reason: 'Unencrypted on disk. Use EncryptedSharedPreferences.' },
29
- { re: /UserDefaults\.standard/gi, type: 'UserDefaults (iOS)', risk: 'high', reason: 'Unencrypted plist. Use Keychain for secrets.' },
30
- { re: /AsyncStorage\.setItem/gi, type: 'AsyncStorage (React Native)', risk: 'high', reason: 'Unencrypted on device. Use expo-secure-store or Keychain.' },
31
- { re: /fs\.writeFile|fs\.writeFileSync|fs\.appendFile/gi, type: 'file', risk: 'medium', reason: 'Verify file permissions and encryption at rest.' },
32
- { re: /CREATE\s+TABLE|createCollection|createTable|schema\.model|schema\.define/gi, type: 'database', risk: 'medium', reason: 'Verify RLS, field-level encryption, and retention policy.' },
33
- ];
34
-
35
- const TRANSMISSION_SINKS = [
36
- { re: /fetch\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'fetch', label: 'HTTP fetch to external URL' },
37
- { re: /axios\.(?:get|post|put|patch|delete)\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'axios', label: 'Axios request to external URL' },
38
- { re: /XMLHttpRequest|xhr\.open/gi, type: 'XHR', label: 'XMLHttpRequest to external URL' },
39
- { re: /(?:sendBeacon|navigator\.sendBeacon)\s*\(/gi, type: 'beacon', label: 'Analytics beacon sent to external URL' },
40
- { re: /https?:\/\/api\.(?:openai|anthropic|googleapis|gemini)\.com/gi, type: 'AI API', label: 'Data sent to AI/LLM provider' },
41
- { re: /https?:\/\/www\.google-analytics\.com|gtag\(|dataLayer\.push/gi, type: 'Google Analytics', label: 'Data sent to Google Analytics' },
42
- { re: /https?:\/\/api\.mixpanel\.com|mixpanel\.(?:track|identify)/gi, type: 'Mixpanel', label: 'Data sent to Mixpanel' },
43
- { re: /https?:\/\/t\.co|https?:\/\/connect\.facebook\.net|fbq\(/gi, type: 'Social tracking', label: 'Data sent to social media tracking pixel' },
44
- { re: /https?:\/\/sentry\.io|Sentry\.capture/gi, type: 'Sentry', label: 'Error data sent to Sentry' },
45
- { re: /https?:\/\/api\.amplitude\.com|amplitude\.(?:logEvent|setUserId)/gi, type: 'Amplitude', label: 'Data sent to Amplitude analytics' },
46
- { re: /https?:\/\/api\.segment\.com|analytics\.(?:track|identify|page)/gi, type: 'Segment', label: 'Data sent to Segment' },
47
- { re: /posthog\.(?:capture|identify)/gi, type: 'PostHog', label: 'Data sent to PostHog' },
48
- ];
49
-
50
- const CONSENT_PATTERNS = [
51
- /consent|gdpr|ccpa|opt.?in|opt.?out|cookie.?banner|privacy.?policy|do.?not.?track|dnt|permission/i,
52
- ];
53
-
54
- const ENCRYPTION_PATTERNS = [
55
- /encrypt|decrypt|cipher|aes|rsa|bcrypt|argon2|scrypt|pbkdf2|crypto\.(?:createCipher|createDecipher|randomBytes)/i,
56
- ];
57
-
58
- const RETENTION_PATTERNS = [
59
- /retention|ttl|expire|expir(?:e|ation|y)|purge|cleanup|delete\s+after|drop\s+after|max.?age/i,
60
- ];
61
-
62
- function auditPrivacy(dir, files) {
63
- const inventory = {
64
- piiFields: new Set(),
65
- storage: [],
66
- transmission: [],
67
- consent: [],
68
- encryption: [],
69
- retention: [],
70
- risks: [],
71
- summary: {},
72
- };
73
-
74
- for (const file of files) {
75
- let content;
76
- try { content = fs.readFileSync(file, 'utf8'); } catch { continue; }
77
- const rel = path.relative(dir, file).split(path.sep).join('/');
78
- const lines = content.split(/\r?\n/);
79
-
80
- for (let i = 0; i < lines.length; i++) {
81
- const line = lines[i];
82
-
83
- // PII fields
84
- let m;
85
- PII_FIELDS.lastIndex = 0;
86
- while ((m = PII_FIELDS.exec(line)) !== null) {
87
- inventory.piiFields.add(m[0].toLowerCase());
88
- }
89
-
90
- // Storage sinks
91
- for (const sink of STORAGE_SINKS) {
92
- sink.re.lastIndex = 0;
93
- while ((m = sink.re.exec(line)) !== null) {
94
- inventory.storage.push({
95
- file: rel, line: i + 1, type: sink.type,
96
- target: m[1] || 'unknown', risk: sink.risk, reason: sink.reason,
97
- });
98
- }
99
- }
100
-
101
- // Transmission sinks
102
- for (const sink of TRANSMISSION_SINKS) {
103
- sink.re.lastIndex = 0;
104
- while ((m = sink.re.exec(line)) !== null) {
105
- inventory.transmission.push({
106
- file: rel, line: i + 1, type: sink.type, label: sink.label,
107
- });
108
- }
109
- }
110
-
111
- // Consent patterns
112
- for (const re of CONSENT_PATTERNS) {
113
- if (re.test(line)) {
114
- inventory.consent.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
115
- break;
116
- }
117
- }
118
-
119
- // Encryption patterns
120
- for (const re of ENCRYPTION_PATTERNS) {
121
- if (re.test(line)) {
122
- inventory.encryption.push({ file: rel, line: i + 1 });
123
- break;
124
- }
125
- }
126
-
127
- // Retention patterns
128
- for (const re of RETENTION_PATTERNS) {
129
- if (re.test(line)) {
130
- inventory.retention.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
131
- break;
132
- }
133
- }
134
- }
135
- }
136
-
137
- // Assess risks
138
- if (inventory.piiFields.size > 0 && inventory.encryption.length === 0) {
139
- inventory.risks.push({ severity: 'high', message: 'PII fields detected but no encryption found in the codebase' });
140
- }
141
- if (inventory.piiFields.size > 0 && inventory.consent.length === 0) {
142
- inventory.risks.push({ severity: 'high', message: 'PII fields detected but no consent mechanism found — GDPR/CCPA violation risk' });
143
- }
144
- if (inventory.piiFields.size > 0 && inventory.retention.length === 0) {
145
- inventory.risks.push({ severity: 'medium', message: 'PII fields detected but no data retention policy found' });
146
- }
147
- if (inventory.storage.some(s => s.type === 'localStorage' || s.type === 'sessionStorage' || s.type === 'AsyncStorage (React Native)' || s.type === 'SharedPreferences (Android)')) {
148
- inventory.risks.push({ severity: 'high', message: 'PII or sensitive data stored in client-side storage (localStorage/sessionStorage/AsyncStorage) — XSS accessible' });
149
- }
150
- if (inventory.transmission.some(t => t.type === 'AI API')) {
151
- const hasRedactionNearAI = inventory.transmission.some(t => {
152
- if (t.type !== 'AI API') return false;
153
- return /encrypt|redact|anonym/i.test(''); // simplified - just check if any redaction exists in codebase
154
- });
155
- if (!hasRedactionNearAI && inventory.encryption.length === 0) {
156
- inventory.risks.push({ severity: 'high', message: 'Data sent to AI/LLM providers — verify PII is redacted before sending' });
157
- }
158
- }
159
- if (inventory.transmission.some(t => t.type === 'Google Analytics' || t.type === 'Mixpanel' || t.type === 'Amplitude' || t.type === 'Segment' || t.type === 'PostHog')) {
160
- if (inventory.consent.length === 0) {
161
- inventory.risks.push({ severity: 'high', message: 'Analytics tracking detected but no consent mechanism — GDPR violation' });
162
- }
163
- }
164
-
165
- // Summary
166
- inventory.summary = {
167
- piiFieldsDetected: [...inventory.piiFields],
168
- piiFieldCount: inventory.piiFields.size,
169
- storagePoints: inventory.storage.length,
170
- transmissionPoints: inventory.transmission.length,
171
- consentMechanisms: inventory.consent.length,
172
- encryptionPoints: inventory.encryption.length,
173
- retentionPolicies: inventory.retention.length,
174
- riskCount: inventory.risks.length,
175
- overallRisk: inventory.risks.filter(r => r.severity === 'high').length > 0 ? 'HIGH' :
176
- inventory.risks.filter(r => r.severity === 'medium').length > 0 ? 'MEDIUM' : 'LOW',
177
- };
178
-
179
- return inventory;
180
- }
181
-
182
- function renderPrivacyReport(inventory) {
183
- const C = {
184
- red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
185
- cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m',
186
- };
187
-
188
- const lines = [];
189
- lines.push(`${C.bold}VibeGuard Privacy Audit${C.reset}`);
190
- lines.push(`${C.dim}${'─'.repeat(60)}${C.reset}`);
191
- lines.push('');
192
-
193
- // PII fields
194
- lines.push(`${C.bold}PII Fields Detected${C.reset} (${inventory.summary.piiFieldCount})`);
195
- if (inventory.summary.piiFieldCount === 0) {
196
- lines.push(` ${C.green}No PII fields detected${C.reset}`);
197
- } else {
198
- lines.push(` ${inventory.summary.piiFieldsDetected.map(f => C.cyan + f + C.reset).join(', ')}`);
199
- }
200
- lines.push('');
201
-
202
- // Storage
203
- lines.push(`${C.bold}Data Storage Points${C.reset} (${inventory.summary.storagePoints})`);
204
- if (inventory.summary.storagePoints === 0) {
205
- lines.push(` ${C.green}No storage sinks detected${C.reset}`);
206
- } else {
207
- for (const s of inventory.storage.slice(0, 10)) {
208
- const color = s.risk === 'high' ? C.red : s.risk === 'medium' ? C.yellow : C.dim;
209
- lines.push(` ${color}[${s.risk}]${C.reset} ${s.type} — ${s.file}:${s.line}`);
210
- }
211
- if (inventory.storage.length > 10) lines.push(` ${C.dim}... and ${inventory.storage.length - 10} more${C.reset}`);
212
- }
213
- lines.push('');
214
-
215
- // Transmission
216
- lines.push(`${C.bold}Data Transmission Points${C.reset} (${inventory.summary.transmissionPoints})`);
217
- if (inventory.summary.transmissionPoints === 0) {
218
- lines.push(` ${C.green}No external transmission detected${C.reset}`);
219
- } else {
220
- const byType = {};
221
- for (const t of inventory.transmission) {
222
- byType[t.type] = (byType[t.type] || 0) + 1;
223
- }
224
- for (const [type, count] of Object.entries(byType)) {
225
- lines.push(` ${C.yellow}${type}${C.reset}: ${count} endpoint(s)`);
226
- }
227
- }
228
- lines.push('');
229
-
230
- // Consent
231
- lines.push(`${C.bold}Consent Mechanisms${C.reset} (${inventory.summary.consentMechanisms})`);
232
- if (inventory.summary.consentMechanisms === 0) {
233
- lines.push(` ${C.red}No consent mechanism detected — GDPR/CCPA risk${C.reset}`);
234
- } else {
235
- lines.push(` ${C.green}Consent mechanism found${C.reset}`);
236
- }
237
- lines.push('');
238
-
239
- // Encryption
240
- lines.push(`${C.bold}Encryption${C.reset} (${inventory.summary.encryptionPoints})`);
241
- if (inventory.summary.encryptionPoints === 0) {
242
- lines.push(` ${C.red}No encryption detected${C.reset}`);
243
- } else {
244
- lines.push(` ${C.green}Encryption found in ${inventory.summary.encryptionPoints} location(s)${C.reset}`);
245
- }
246
- lines.push('');
247
-
248
- // Retention
249
- lines.push(`${C.bold}Data Retention${C.reset} (${inventory.summary.retentionPolicies})`);
250
- if (inventory.summary.retentionPolicies === 0) {
251
- lines.push(` ${C.yellow}No retention policy detected${C.reset}`);
252
- } else {
253
- lines.push(` ${C.green}Retention policy found${C.reset}`);
254
- }
255
- lines.push('');
256
-
257
- // Risks
258
- lines.push(`${C.bold}Privacy Risks${C.reset} (${inventory.summary.riskCount})`);
259
- if (inventory.summary.riskCount === 0) {
260
- lines.push(` ${C.green}No privacy risks detected${C.reset}`);
261
- } else {
262
- for (const r of inventory.risks) {
263
- const color = r.severity === 'high' ? C.red : r.severity === 'medium' ? C.yellow : C.dim;
264
- lines.push(` ${color}[${r.severity}]${C.reset} ${r.message}`);
265
- }
266
- }
267
- lines.push('');
268
- lines.push(`${C.dim}Overall Privacy Risk: ${inventory.summary.overallRisk}${C.reset}`);
269
-
270
- return lines.join('\n');
271
- }
272
-
1
+ 'use strict';
2
+
3
+ /*
4
+ * VibeGuard Privacy Audit.
5
+ *
6
+ * Scans the codebase for all data collection, storage, and transmission points.
7
+ * Builds a privacy inventory showing:
8
+ * - What PII is collected (forms, inputs, API params)
9
+ * - Where PII is stored (DB, localStorage, cookies, files)
10
+ * - Where PII is sent (external APIs, analytics, AI providers)
11
+ * - What consent mechanisms exist (or are missing)
12
+ * - What data retention policies exist (or are missing)
13
+ * - What encryption exists (or is missing)
14
+ *
15
+ * 100% local. Zero network. Zero dependencies.
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+
21
+ const PII_FIELDS = /\b(?:email|phone|ssn|social_security|creditcard|credit_card|card_number|cvv|cvc|passport|dob|date_of_birth|bank_account|routing_number|address|zip|postal|first_name|last_name|fullname|birth|gender|nationality|ip_address|mac_address|device_id|biometric|fingerprint|location|latitude|longitude|avatar|profile_pic)\b/gi;
22
+
23
+ const STORAGE_SINKS = [
24
+ { re: /localStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'localStorage', risk: 'high', reason: 'XSS can read localStorage. Use HTTP-only cookies for auth tokens.' },
25
+ { re: /sessionStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'sessionStorage', risk: 'high', reason: 'XSS can read sessionStorage. Use HTTP-only cookies.' },
26
+ { re: /document\.cookie\s*=\s*['"]?([^=;'"]+)/gi, type: 'cookie', risk: 'medium', reason: 'Verify Secure, HttpOnly, SameSite flags are set.' },
27
+ { re: /IndexedDB|indexedDB\.open/gi, type: 'IndexedDB', risk: 'medium', reason: 'Persistent browser storage. XSS accessible. Do not store PII here.' },
28
+ { re: /SharedPreferences|getSharedPreferences/gi, type: 'SharedPreferences (Android)', risk: 'high', reason: 'Unencrypted on disk. Use EncryptedSharedPreferences.' },
29
+ { re: /UserDefaults\.standard/gi, type: 'UserDefaults (iOS)', risk: 'high', reason: 'Unencrypted plist. Use Keychain for secrets.' },
30
+ { re: /AsyncStorage\.setItem/gi, type: 'AsyncStorage (React Native)', risk: 'high', reason: 'Unencrypted on device. Use expo-secure-store or Keychain.' },
31
+ { re: /fs\.writeFile|fs\.writeFileSync|fs\.appendFile/gi, type: 'file', risk: 'medium', reason: 'Verify file permissions and encryption at rest.' },
32
+ { re: /CREATE\s+TABLE|createCollection|createTable|schema\.model|schema\.define/gi, type: 'database', risk: 'medium', reason: 'Verify RLS, field-level encryption, and retention policy.' },
33
+ ];
34
+
35
+ const TRANSMISSION_SINKS = [
36
+ { re: /fetch\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'fetch', label: 'HTTP fetch to external URL' },
37
+ { re: /axios\.(?:get|post|put|patch|delete)\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'axios', label: 'Axios request to external URL' },
38
+ { re: /XMLHttpRequest|xhr\.open/gi, type: 'XHR', label: 'XMLHttpRequest to external URL' },
39
+ { re: /(?:sendBeacon|navigator\.sendBeacon)\s*\(/gi, type: 'beacon', label: 'Analytics beacon sent to external URL' },
40
+ { re: /https?:\/\/api\.(?:openai|anthropic|googleapis|gemini)\.com/gi, type: 'AI API', label: 'Data sent to AI/LLM provider' },
41
+ { re: /https?:\/\/www\.google-analytics\.com|gtag\(|dataLayer\.push/gi, type: 'Google Analytics', label: 'Data sent to Google Analytics' },
42
+ { re: /https?:\/\/api\.mixpanel\.com|mixpanel\.(?:track|identify)/gi, type: 'Mixpanel', label: 'Data sent to Mixpanel' },
43
+ { re: /https?:\/\/t\.co|https?:\/\/connect\.facebook\.net|fbq\(/gi, type: 'Social tracking', label: 'Data sent to social media tracking pixel' },
44
+ { re: /https?:\/\/sentry\.io|Sentry\.capture/gi, type: 'Sentry', label: 'Error data sent to Sentry' },
45
+ { re: /https?:\/\/api\.amplitude\.com|amplitude\.(?:logEvent|setUserId)/gi, type: 'Amplitude', label: 'Data sent to Amplitude analytics' },
46
+ { re: /https?:\/\/api\.segment\.com|analytics\.(?:track|identify|page)/gi, type: 'Segment', label: 'Data sent to Segment' },
47
+ { re: /posthog\.(?:capture|identify)/gi, type: 'PostHog', label: 'Data sent to PostHog' },
48
+ ];
49
+
50
+ const CONSENT_PATTERNS = [
51
+ /consent|gdpr|ccpa|opt.?in|opt.?out|cookie.?banner|privacy.?policy|do.?not.?track|dnt|permission/i,
52
+ ];
53
+
54
+ const ENCRYPTION_PATTERNS = [
55
+ /encrypt|decrypt|cipher|aes|rsa|bcrypt|argon2|scrypt|pbkdf2|crypto\.(?:createCipher|createDecipher|randomBytes)/i,
56
+ ];
57
+
58
+ const RETENTION_PATTERNS = [
59
+ /retention|ttl|expire|expir(?:e|ation|y)|purge|cleanup|delete\s+after|drop\s+after|max.?age/i,
60
+ ];
61
+
62
+ function auditPrivacy(dir, files) {
63
+ const inventory = {
64
+ piiFields: new Set(),
65
+ storage: [],
66
+ transmission: [],
67
+ consent: [],
68
+ encryption: [],
69
+ retention: [],
70
+ risks: [],
71
+ summary: {},
72
+ };
73
+
74
+ for (const file of files) {
75
+ let content;
76
+ try { content = fs.readFileSync(file, 'utf8'); } catch { continue; }
77
+ const rel = path.relative(dir, file).split(path.sep).join('/');
78
+ const lines = content.split(/\r?\n/);
79
+
80
+ for (let i = 0; i < lines.length; i++) {
81
+ const line = lines[i];
82
+
83
+ // PII fields
84
+ let m;
85
+ PII_FIELDS.lastIndex = 0;
86
+ while ((m = PII_FIELDS.exec(line)) !== null) {
87
+ inventory.piiFields.add(m[0].toLowerCase());
88
+ }
89
+
90
+ // Storage sinks
91
+ for (const sink of STORAGE_SINKS) {
92
+ sink.re.lastIndex = 0;
93
+ while ((m = sink.re.exec(line)) !== null) {
94
+ inventory.storage.push({
95
+ file: rel, line: i + 1, type: sink.type,
96
+ target: m[1] || 'unknown', risk: sink.risk, reason: sink.reason,
97
+ });
98
+ }
99
+ }
100
+
101
+ // Transmission sinks
102
+ for (const sink of TRANSMISSION_SINKS) {
103
+ sink.re.lastIndex = 0;
104
+ while ((m = sink.re.exec(line)) !== null) {
105
+ inventory.transmission.push({
106
+ file: rel, line: i + 1, type: sink.type, label: sink.label,
107
+ });
108
+ }
109
+ }
110
+
111
+ // Consent patterns
112
+ for (const re of CONSENT_PATTERNS) {
113
+ if (re.test(line)) {
114
+ inventory.consent.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
115
+ break;
116
+ }
117
+ }
118
+
119
+ // Encryption patterns
120
+ for (const re of ENCRYPTION_PATTERNS) {
121
+ if (re.test(line)) {
122
+ inventory.encryption.push({ file: rel, line: i + 1 });
123
+ break;
124
+ }
125
+ }
126
+
127
+ // Retention patterns
128
+ for (const re of RETENTION_PATTERNS) {
129
+ if (re.test(line)) {
130
+ inventory.retention.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ // Assess risks
138
+ if (inventory.piiFields.size > 0 && inventory.encryption.length === 0) {
139
+ inventory.risks.push({ severity: 'high', message: 'PII fields detected but no encryption found in the codebase' });
140
+ }
141
+ if (inventory.piiFields.size > 0 && inventory.consent.length === 0) {
142
+ inventory.risks.push({ severity: 'high', message: 'PII fields detected but no consent mechanism found — GDPR/CCPA violation risk' });
143
+ }
144
+ if (inventory.piiFields.size > 0 && inventory.retention.length === 0) {
145
+ inventory.risks.push({ severity: 'medium', message: 'PII fields detected but no data retention policy found' });
146
+ }
147
+ if (inventory.storage.some(s => s.type === 'localStorage' || s.type === 'sessionStorage' || s.type === 'AsyncStorage (React Native)' || s.type === 'SharedPreferences (Android)')) {
148
+ inventory.risks.push({ severity: 'high', message: 'PII or sensitive data stored in client-side storage (localStorage/sessionStorage/AsyncStorage) — XSS accessible' });
149
+ }
150
+ if (inventory.transmission.some(t => t.type === 'AI API')) {
151
+ const hasRedactionNearAI = inventory.transmission.some(t => {
152
+ if (t.type !== 'AI API') return false;
153
+ return /encrypt|redact|anonym/i.test(''); // simplified - just check if any redaction exists in codebase
154
+ });
155
+ if (!hasRedactionNearAI && inventory.encryption.length === 0) {
156
+ inventory.risks.push({ severity: 'high', message: 'Data sent to AI/LLM providers — verify PII is redacted before sending' });
157
+ }
158
+ }
159
+ if (inventory.transmission.some(t => t.type === 'Google Analytics' || t.type === 'Mixpanel' || t.type === 'Amplitude' || t.type === 'Segment' || t.type === 'PostHog')) {
160
+ if (inventory.consent.length === 0) {
161
+ inventory.risks.push({ severity: 'high', message: 'Analytics tracking detected but no consent mechanism — GDPR violation' });
162
+ }
163
+ }
164
+
165
+ // Summary
166
+ inventory.summary = {
167
+ piiFieldsDetected: [...inventory.piiFields],
168
+ piiFieldCount: inventory.piiFields.size,
169
+ storagePoints: inventory.storage.length,
170
+ transmissionPoints: inventory.transmission.length,
171
+ consentMechanisms: inventory.consent.length,
172
+ encryptionPoints: inventory.encryption.length,
173
+ retentionPolicies: inventory.retention.length,
174
+ riskCount: inventory.risks.length,
175
+ overallRisk: inventory.risks.filter(r => r.severity === 'high').length > 0 ? 'HIGH' :
176
+ inventory.risks.filter(r => r.severity === 'medium').length > 0 ? 'MEDIUM' : 'LOW',
177
+ };
178
+
179
+ return inventory;
180
+ }
181
+
182
+ function renderPrivacyReport(inventory) {
183
+ const C = {
184
+ red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
185
+ cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m',
186
+ };
187
+
188
+ const lines = [];
189
+ lines.push(`${C.bold}VibeGuard Privacy Audit${C.reset}`);
190
+ lines.push(`${C.dim}${'─'.repeat(60)}${C.reset}`);
191
+ lines.push('');
192
+
193
+ // PII fields
194
+ lines.push(`${C.bold}PII Fields Detected${C.reset} (${inventory.summary.piiFieldCount})`);
195
+ if (inventory.summary.piiFieldCount === 0) {
196
+ lines.push(` ${C.green}No PII fields detected${C.reset}`);
197
+ } else {
198
+ lines.push(` ${inventory.summary.piiFieldsDetected.map(f => C.cyan + f + C.reset).join(', ')}`);
199
+ }
200
+ lines.push('');
201
+
202
+ // Storage
203
+ lines.push(`${C.bold}Data Storage Points${C.reset} (${inventory.summary.storagePoints})`);
204
+ if (inventory.summary.storagePoints === 0) {
205
+ lines.push(` ${C.green}No storage sinks detected${C.reset}`);
206
+ } else {
207
+ for (const s of inventory.storage.slice(0, 10)) {
208
+ const color = s.risk === 'high' ? C.red : s.risk === 'medium' ? C.yellow : C.dim;
209
+ lines.push(` ${color}[${s.risk}]${C.reset} ${s.type} — ${s.file}:${s.line}`);
210
+ }
211
+ if (inventory.storage.length > 10) lines.push(` ${C.dim}... and ${inventory.storage.length - 10} more${C.reset}`);
212
+ }
213
+ lines.push('');
214
+
215
+ // Transmission
216
+ lines.push(`${C.bold}Data Transmission Points${C.reset} (${inventory.summary.transmissionPoints})`);
217
+ if (inventory.summary.transmissionPoints === 0) {
218
+ lines.push(` ${C.green}No external transmission detected${C.reset}`);
219
+ } else {
220
+ const byType = {};
221
+ for (const t of inventory.transmission) {
222
+ byType[t.type] = (byType[t.type] || 0) + 1;
223
+ }
224
+ for (const [type, count] of Object.entries(byType)) {
225
+ lines.push(` ${C.yellow}${type}${C.reset}: ${count} endpoint(s)`);
226
+ }
227
+ }
228
+ lines.push('');
229
+
230
+ // Consent
231
+ lines.push(`${C.bold}Consent Mechanisms${C.reset} (${inventory.summary.consentMechanisms})`);
232
+ if (inventory.summary.consentMechanisms === 0) {
233
+ lines.push(` ${C.red}No consent mechanism detected — GDPR/CCPA risk${C.reset}`);
234
+ } else {
235
+ lines.push(` ${C.green}Consent mechanism found${C.reset}`);
236
+ }
237
+ lines.push('');
238
+
239
+ // Encryption
240
+ lines.push(`${C.bold}Encryption${C.reset} (${inventory.summary.encryptionPoints})`);
241
+ if (inventory.summary.encryptionPoints === 0) {
242
+ lines.push(` ${C.red}No encryption detected${C.reset}`);
243
+ } else {
244
+ lines.push(` ${C.green}Encryption found in ${inventory.summary.encryptionPoints} location(s)${C.reset}`);
245
+ }
246
+ lines.push('');
247
+
248
+ // Retention
249
+ lines.push(`${C.bold}Data Retention${C.reset} (${inventory.summary.retentionPolicies})`);
250
+ if (inventory.summary.retentionPolicies === 0) {
251
+ lines.push(` ${C.yellow}No retention policy detected${C.reset}`);
252
+ } else {
253
+ lines.push(` ${C.green}Retention policy found${C.reset}`);
254
+ }
255
+ lines.push('');
256
+
257
+ // Risks
258
+ lines.push(`${C.bold}Privacy Risks${C.reset} (${inventory.summary.riskCount})`);
259
+ if (inventory.summary.riskCount === 0) {
260
+ lines.push(` ${C.green}No privacy risks detected${C.reset}`);
261
+ } else {
262
+ for (const r of inventory.risks) {
263
+ const color = r.severity === 'high' ? C.red : r.severity === 'medium' ? C.yellow : C.dim;
264
+ lines.push(` ${color}[${r.severity}]${C.reset} ${r.message}`);
265
+ }
266
+ }
267
+ lines.push('');
268
+ lines.push(`${C.dim}Overall Privacy Risk: ${inventory.summary.overallRisk}${C.reset}`);
269
+
270
+ return lines.join('\n');
271
+ }
272
+
273
273
  module.exports = { auditPrivacy, renderPrivacyReport };