@yagyeshvyas/vibeguard 1.3.0 → 1.11.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 (167) hide show
  1. package/.vibeguard-mcp.example.json +51 -0
  2. package/CHANGELOG.md +604 -216
  3. package/MCP-FIREWALL.md +296 -0
  4. package/README.md +355 -31
  5. package/bin/cli.js +355 -27
  6. package/bin/cmd-agent-monitor.js +45 -0
  7. package/bin/cmd-agent-risk.js +64 -0
  8. package/bin/cmd-gif.js +62 -0
  9. package/bin/cmd-git-scan.js +74 -0
  10. package/bin/cmd-llm-proxy.js +164 -0
  11. package/bin/cmd-mcp-firewall.js +191 -0
  12. package/bin/cmd-pentest.js +103 -0
  13. package/bin/cmd-platform.js +137 -0
  14. package/bin/cmd-pr-scan.js +135 -0
  15. package/bin/cmd-sbom-diff.js +38 -0
  16. package/bin/cmd-skill-scan.js +35 -0
  17. package/docs/AISVS.md +25 -0
  18. package/docs/ARCHITECTURE.md +81 -0
  19. package/docs/INSTALLATION.md +139 -0
  20. package/docs/WINDOWS.md +74 -0
  21. package/docs/security-policy.strict.example.json +134 -0
  22. package/docs/security-policy.strict.example.pub.pem +3 -0
  23. package/package.json +45 -7
  24. package/src/.vibeguard/cache/file-hashes.json +60 -0
  25. package/src/.vibeguard/latest-snapshot.json +36 -0
  26. package/src/.vibeguard/mcp-pins.json +1 -0
  27. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
  28. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
  29. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
  30. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
  31. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
  32. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
  33. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
  34. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
  35. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
  36. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
  37. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
  38. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
  43. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
  44. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
  45. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
  46. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
  47. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
  48. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
  49. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
  50. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
  51. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
  52. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
  53. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
  54. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
  55. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
  56. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
  57. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
  58. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
  59. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
  60. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
  61. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
  62. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
  63. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
  68. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
  69. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
  70. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
  71. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
  72. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
  73. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
  74. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
  75. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
  76. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
  77. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
  78. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
  79. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
  84. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
  85. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
  86. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
  87. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
  88. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
  89. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
  90. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
  91. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
  92. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
  93. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
  94. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
  95. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
  96. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
  97. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
  98. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
  99. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
  100. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
  101. package/src/.vibeguard-baseline.json +5226 -0
  102. package/src/action-guard.js +84 -6
  103. package/src/agent-monitor.js +262 -0
  104. package/src/agent-policy.js +642 -0
  105. package/src/agent-risk.js +271 -0
  106. package/src/agentic.js +1513 -0
  107. package/src/ast.js +165 -7
  108. package/src/audit-trail.js +212 -67
  109. package/src/auto.js +427 -427
  110. package/src/autofix.js +11 -4
  111. package/src/bundles.js +198 -0
  112. package/src/daemon.js +343 -343
  113. package/src/dashboard.js +278 -278
  114. package/src/engine.js +3 -0
  115. package/src/entropy.js +187 -0
  116. package/src/firewall.js +19 -3
  117. package/src/gif.js +134 -0
  118. package/src/gitscan.js +282 -0
  119. package/src/hook.js +151 -151
  120. package/src/injection-decode.js +136 -0
  121. package/src/install.js +298 -280
  122. package/src/integrity.js +16 -1
  123. package/src/integrity.json +43 -13
  124. package/src/interceptor.js +12 -9
  125. package/src/llm-proxy.js +986 -0
  126. package/src/mcp-audit.js +61 -5
  127. package/src/mcp-firewall.js +971 -0
  128. package/src/mcp-server.js +2500 -2047
  129. package/src/obfuscation.js +315 -0
  130. package/src/owasp-agentic.js +314 -0
  131. package/src/pentest.js +589 -0
  132. package/src/pii.js +4 -0
  133. package/src/platform/aisvs.js +38 -0
  134. package/src/platform/approval.js +187 -0
  135. package/src/platform/canonical.js +73 -0
  136. package/src/platform/contracts.js +158 -0
  137. package/src/platform/delegation.js +73 -0
  138. package/src/platform/http-gateway.js +177 -0
  139. package/src/platform/identity.js +253 -0
  140. package/src/platform/jwt.js +86 -0
  141. package/src/platform/mcp-http-bridge.js +199 -0
  142. package/src/platform/memory-guard.js +64 -0
  143. package/src/platform/os-sandbox.js +144 -0
  144. package/src/platform/policy.js +332 -0
  145. package/src/platform/sandbox-manager.js +92 -0
  146. package/src/platform/signed-audit.js +357 -0
  147. package/src/platform/ssrf.js +129 -0
  148. package/src/plugin.js +182 -168
  149. package/src/pre-deploy.js +170 -55
  150. package/src/privacy-audit.js +272 -272
  151. package/src/repl.js +150 -150
  152. package/src/report.js +7 -1
  153. package/src/routes.js +1210 -0
  154. package/src/rules-2026.js +1407 -0
  155. package/src/rules-pack.js +3068 -3019
  156. package/src/rules.js +376 -60
  157. package/src/sandbox.js +200 -10
  158. package/src/sbom.js +193 -164
  159. package/src/scanner.js +189 -33
  160. package/src/shell-guard.js +11 -0
  161. package/src/skill-scan.js +477 -0
  162. package/src/slopsquat.js +144 -144
  163. package/src/surface.js +408 -0
  164. package/src/taint-ast.js +204 -37
  165. package/src/taint.js +15 -3
  166. package/src/tokenlean.js +579 -0
  167. package/src/trace.js +220 -220
@@ -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.piiFields.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 };