@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
package/src/rules.js CHANGED
@@ -157,7 +157,7 @@ const secretRules = [
157
157
  id: 'secret.github-token',
158
158
  severity: 'critical',
159
159
  confidence: 'high',
160
- title: 'GitHub token',
160
+ cwe: 'CWE-798', owasp: 'A07', title: 'GitHub token',
161
161
  re: /\bgh[posur]_[A-Za-z0-9]{36,}\b/,
162
162
  message: 'Hardcoded GitHub token (personal access / OAuth / app token).',
163
163
  fix: 'Remove it, load from an environment variable, and revoke it in GitHub settings.',
@@ -166,7 +166,7 @@ const secretRules = [
166
166
  id: 'secret.slack-token',
167
167
  severity: 'critical',
168
168
  confidence: 'high',
169
- title: 'Slack token',
169
+ cwe: 'CWE-798', owasp: 'A07', title: 'Slack token',
170
170
  re: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/,
171
171
  message: 'Hardcoded Slack token.',
172
172
  fix: 'Remove it, load from an environment variable, and rotate it in the Slack app settings.',
@@ -175,7 +175,7 @@ const secretRules = [
175
175
  id: 'secret.gitlab-token',
176
176
  severity: 'critical',
177
177
  confidence: 'high',
178
- title: 'GitLab personal access token',
178
+ cwe: 'CWE-798', owasp: 'A07', title: 'GitLab personal access token',
179
179
  re: /\bglpat-[A-Za-z0-9_\-]{20,}\b/,
180
180
  message: 'Hardcoded GitLab personal access token.',
181
181
  fix: 'Remove it, load from an environment variable, and revoke it in GitLab.',
@@ -184,7 +184,7 @@ const secretRules = [
184
184
  id: 'secret.twilio-key',
185
185
  severity: 'critical',
186
186
  confidence: 'high',
187
- title: 'Twilio API key',
187
+ cwe: 'CWE-798', owasp: 'A07', title: 'Twilio API key',
188
188
  re: /\bSK[0-9a-f]{32}\b/,
189
189
  message: 'Hardcoded Twilio API key.',
190
190
  fix: 'Remove it, load from an environment variable, and rotate it in the Twilio console.',
@@ -193,7 +193,7 @@ const secretRules = [
193
193
  id: 'secret.sendgrid-key',
194
194
  severity: 'critical',
195
195
  confidence: 'high',
196
- title: 'SendGrid API key',
196
+ cwe: 'CWE-798', owasp: 'A07', title: 'SendGrid API key',
197
197
  re: /\bSG\.[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{16,}\b/,
198
198
  message: 'Hardcoded SendGrid API key.',
199
199
  fix: 'Remove it, load from an environment variable, and rotate it in SendGrid.',
@@ -202,25 +202,35 @@ const secretRules = [
202
202
  id: 'secret.mailgun-key',
203
203
  severity: 'critical',
204
204
  confidence: 'high',
205
- title: 'Mailgun API key',
205
+ cwe: 'CWE-798', owasp: 'A07', title: 'Mailgun API key',
206
206
  re: /\bkey-[0-9a-f]{32}\b/,
207
207
  message: 'Hardcoded Mailgun API key.',
208
208
  fix: 'Remove it, load from an environment variable, and rotate it in Mailgun.',
209
209
  },
210
210
  {
211
- id: 'secret.telegram-bot-token',
212
- severity: 'critical',
213
- confidence: 'high',
214
- title: 'Telegram bot token',
215
- re: /\b\d{8,10}:[A-Za-z0-9_-]{35}\b/,
216
- message: 'Hardcoded Telegram bot token.',
217
- fix: 'Remove it, load from an environment variable, and revoke it via BotFather.',
218
- },
211
+ id: 'secret.telegram-bot-token',
212
+ severity: 'critical',
213
+ confidence: 'high',
214
+ title: 'Telegram bot token',
215
+ // Bot tokens: <bot_id>:<base64url body>. The body is 35 chars, but tokens
216
+ // with hyphens/underscores quoted in code can render shorter — accept 32-35.
217
+ re: /\b\d{8,10}:[A-Za-z0-9_-]{32,35}\b/,
218
+ message: 'Hardcoded Telegram bot token.',
219
+ fix: 'Remove it, load from an environment variable, and revoke it via BotFather.',
220
+ filter(line, m) {
221
+ // Bot token bodies are base64url — mixed case plus digits. Requiring both
222
+ // letter cases (and a digit) rejects look-alike timestamps (e.g.
223
+ // "20240101:abcdefghijklmnop") and hex hashes that match the shape but
224
+ // are not tokens.
225
+ const body = m ? String(m.match).split(':')[1] || '' : line;
226
+ return /[A-Z]/.test(body) && /[a-z]/.test(body) && /[0-9]/.test(body);
227
+ },
228
+ },
219
229
  {
220
230
  id: 'secret.npm-token',
221
231
  severity: 'critical',
222
232
  confidence: 'high',
223
- title: 'npm access token',
233
+ cwe: 'CWE-798', owasp: 'A07', title: 'npm access token',
224
234
  re: /\bnpm_[A-Za-z0-9]{36}\b/,
225
235
  message: 'Hardcoded npm access token (also flagged in .npmrc).',
226
236
  fix: 'Remove it, use an environment variable / CI secret, and revoke it on npmjs.com.',
@@ -229,7 +239,7 @@ const secretRules = [
229
239
  id: 'secret.resend-key',
230
240
  severity: 'critical',
231
241
  confidence: 'high',
232
- title: 'Resend API key',
242
+ cwe: 'CWE-798', owasp: 'A07', title: 'Resend API key',
233
243
  re: /\bre_[A-Za-z0-9]{20,}\b/,
234
244
  message: 'Hardcoded Resend API key.',
235
245
  fix: 'Remove it, load from an environment variable, and rotate it in Resend.',
@@ -242,20 +252,28 @@ const secretRules = [
242
252
  id: 'secret.connection-string',
243
253
  severity: 'critical',
244
254
  confidence: 'high',
245
- title: 'Connection string with embedded credentials',
255
+ cwe: 'CWE-798', owasp: 'A07', title: 'Connection string with embedded credentials',
246
256
  re: /\b(?:mongodb(?:\+srv)?|postgres(?:ql)?|mysql|mariadb|redis|amqps?):\/\/[^\s:@/]+:[^\s:@/]+@/,
247
257
  message: 'A database/broker connection string embeds a username and password.',
248
258
  fix: 'Load the connection string from an environment variable; never commit credentials.',
249
259
  filter(line, m) {
250
- // Ignore obvious placeholders like user:pass@ / user:password@host.
251
- return !/:\/\/(?:user|username|root|admin):(?:pass|password|changeme|xxx+|\.\.\.)@/i.test(m.match);
252
- },
260
+ const url = m ? m.match : line;
261
+ // Ignore obvious placeholders like user:pass@ / user:password@host.
262
+ if (/:\/\/(?:user|username|root|admin):(?:pass|password|changeme|xxx+|\.\.\.)@/i.test(url)) return false;
263
+ // The standard schemes below are already covered by the dedicated
264
+ // secret.conn-string-password rule in the extended pack — this rule
265
+ // deliberately stays quiet on them to avoid double-reporting the same
266
+ // line. It keeps the schemes that rule alone handles: mariadb, amqp(s),
267
+ // and the mongodb+srv form (the pack only matches plain mongodb://).
268
+ if (/^(?:mongodb|postgres(?:ql)?|mysql|redis):\/\//i.test(url)) return false;
269
+ return true;
270
+ },
253
271
  },
254
272
  {
255
273
  id: 'secret.public-llm-key',
256
274
  severity: 'critical',
257
275
  confidence: 'high',
258
- title: 'AI/secret key exposed to the browser via a public env prefix',
276
+ cwe: 'CWE-798', owasp: 'A07', title: 'AI/secret key exposed to the browser via a public env prefix',
259
277
  // NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_ on an LLM provider key or anything named *SECRET*.
260
278
  re: /\b(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|REACT_APP_|PUBLIC_)[A-Z0-9_]*(?:OPENAI|ANTHROPIC|GROQ|MISTRAL|COHERE|GEMINI|HUGGINGFACE|REPLICATE|TOGETHER|OPENROUTER|PERPLEXITY|DEEPSEEK)[A-Z0-9_]*|\b(?:NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_)[A-Z0-9_]*SECRET[A-Z0-9_]*/i,
261
279
  message: 'A public env prefix exposes an AI provider key or a secret to the browser bundle — anyone can read it.',
@@ -264,7 +282,8 @@ const secretRules = [
264
282
  {
265
283
  id: 'secret.anthropic-key',
266
284
  severity: 'critical',
267
- title: 'Anthropic API key',
285
+ confidence: 'high',
286
+ cwe: 'CWE-798', owasp: 'A07', title: 'Anthropic API key',
268
287
  // Must be checked before the OpenAI rule (sk- prefix overlap).
269
288
  re: /\bsk-ant-[A-Za-z0-9_\-]{20,}\b/,
270
289
  message: 'Hardcoded Anthropic API key.',
@@ -273,7 +292,8 @@ const secretRules = [
273
292
  {
274
293
  id: 'secret.openai-key',
275
294
  severity: 'critical',
276
- title: 'OpenAI API key',
295
+ confidence: 'high',
296
+ cwe: 'CWE-798', owasp: 'A07', title: 'OpenAI API key',
277
297
  // sk- or sk-proj-, but NOT sk-ant- (Anthropic) and NOT sk_live_ (Stripe uses _).
278
298
  re: /\bsk-(?!ant-)(?:proj-)?[A-Za-z0-9_\-]{20,}\b/,
279
299
  message: 'Hardcoded OpenAI API key.',
@@ -282,15 +302,20 @@ const secretRules = [
282
302
  {
283
303
  id: 'secret.stripe-live-key',
284
304
  severity: 'critical',
285
- title: 'Stripe live secret key',
286
- re: /\b(?:sk|rk)_live_[A-Za-z0-9]{16,}\b/,
305
+ confidence: 'high',
306
+ cwe: 'CWE-798', owasp: 'A07', title: 'Stripe live secret key',
307
+ // Live secret keys start sk_live_ (full account access). Restricted keys
308
+ // (rk_live_) are a separate, less-privileged class covered by
309
+ // secret.stripe-restricted-key — don't double-report them as full live keys.
310
+ re: /\bsk_live_[A-Za-z0-9]{16,}\b/,
287
311
  message: 'Hardcoded Stripe LIVE secret key. This can move real money.',
288
312
  fix: 'Remove the key, load it from process.env.STRIPE_SECRET_KEY, and roll it in the Stripe dashboard now.',
289
313
  },
290
314
  {
291
315
  id: 'secret.aws-access-key',
292
316
  severity: 'critical',
293
- title: 'AWS access key id',
317
+ confidence: 'high',
318
+ cwe: 'CWE-798', owasp: 'A07', title: 'AWS access key id',
294
319
  re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,
295
320
  message: 'Hardcoded AWS access key id.',
296
321
  fix: 'Remove it, use an IAM role or environment variables, and deactivate/rotate the key in AWS IAM.',
@@ -606,6 +631,8 @@ const BASE_SHAPING = [
606
631
  'toSafe\\w*', 'toPublic\\w*', 'serialize\\w*', 'toJSON', 'select', 'only', 'except',
607
632
  ];
608
633
  let extraShaping = [];
634
+ // User-defined rules from .vibeguardrc.json { "customRules": [...] } — see configure().
635
+ let customRules = [];
609
636
 
610
637
  function buildRedactRe() {
611
638
  return new RegExp('\\b(?:' + [...BASE_SHAPING, ...extraShaping].join('|') + ')\\s*\\(', 'i');
@@ -619,6 +646,45 @@ function configure(cfg) {
619
646
  .filter((s) => typeof s === 'string' && /^[\w\\*]+$/.test(s));
620
647
  extraShaping = fns;
621
648
  REDACT_RE = buildRedactRe();
649
+ // User-defined regex rules (Semgrep-style custom rules, zero code changes):
650
+ // .vibeguardrc.json { "customRules": [{ "id": "mycorp.no-eval", "severity": "high",
651
+ // "title": "...", "re": "pattern", "message": "...", "fix": "..." }] }
652
+ if (customRules.length) {
653
+ fileRules.length -= customRules.length; // drop previous customs before re-adding
654
+ customRules = [];
655
+ }
656
+ if (cfg && Array.isArray(cfg.customRules)) {
657
+ for (const r of cfg.customRules) {
658
+ if (!r || typeof r.id !== 'string' || typeof r.re !== 'string' || !r.re) continue;
659
+ let compiled;
660
+ try { compiled = new RegExp(r.re, 'gi'); } catch { continue; } // bad regex = skip, never crash
661
+ const rule = {
662
+ id: String(r.id).slice(0, 64).replace(/[^A-Za-z0-9._-]/g, '-'),
663
+ severity: ['critical', 'high', 'medium', 'low'].includes(r.severity) ? r.severity : 'high',
664
+ confidence: r.confidence || 'medium',
665
+ title: String(r.title || r.id),
666
+ re: compiled,
667
+ // The fileRules loop only executes run()/match() rules — wrap the regex
668
+ // so custom rules ride the same hook (no scanner changes needed).
669
+ match(content) {
670
+ const out = [];
671
+ compiled.lastIndex = 0;
672
+ let mm;
673
+ while ((mm = compiled.exec(content)) !== null) {
674
+ out.push({ index: mm.index, match: mm[0] });
675
+ if (mm.index === compiled.lastIndex) compiled.lastIndex++;
676
+ }
677
+ return out;
678
+ },
679
+ message: String(r.message || 'Custom rule matched.'),
680
+ fix: String(r.fix || 'Review this match.'),
681
+ cwe: String(r.cwe || 'CWE-710'), owasp: String(r.owasp || 'A09'),
682
+ custom: true,
683
+ };
684
+ customRules.push(rule);
685
+ fileRules.push(rule);
686
+ }
687
+ }
622
688
  }
623
689
 
624
690
  function isRedacted(line) {
@@ -673,7 +739,7 @@ const piiRules = [
673
739
  id: 'pii.secret-in-log',
674
740
  severity: 'high',
675
741
  confidence: 'medium',
676
- title: 'Secret written to logs',
742
+ cwe: 'CWE-359', owasp: 'A01', title: 'Secret written to logs',
677
743
  re: LOG_SINK,
678
744
  skipComments: true,
679
745
  message: 'A secret/credential is written to logs. Logs get shipped to files, consoles, and log aggregators — this leaks it.',
@@ -684,7 +750,7 @@ const piiRules = [
684
750
  id: 'pii.personal-data-in-log',
685
751
  severity: 'medium',
686
752
  confidence: 'low',
687
- title: 'Personal data written to logs',
753
+ cwe: 'CWE-359', owasp: 'A01', title: 'Personal data written to logs',
688
754
  re: LOG_SINK,
689
755
  skipComments: true,
690
756
  message: 'Personal data (PII) is written to logs. Confirm this is intended and compliant — logs are often less protected than your DB.',
@@ -695,7 +761,7 @@ const piiRules = [
695
761
  id: 'pii.secret-in-response',
696
762
  severity: 'high',
697
763
  confidence: 'medium',
698
- title: 'Secret/credential sent in an HTTP response',
764
+ cwe: 'CWE-359', owasp: 'A01', title: 'Secret/credential sent in an HTTP response',
699
765
  re: RES_SINK,
700
766
  skipComments: true,
701
767
  message: 'A secret/credential field is included in an HTTP response body — it will be sent to the client.',
@@ -706,7 +772,7 @@ const piiRules = [
706
772
  id: 'pii.request-body-echoed',
707
773
  severity: 'medium',
708
774
  confidence: 'low',
709
- title: 'Raw request body returned to the client',
775
+ cwe: 'CWE-359', owasp: 'A01', title: 'Raw request body returned to the client',
710
776
  re: /\bres\.(?:json|send)\s*\(\s*req\.body\s*\)/i,
711
777
  skipComments: true,
712
778
  message: 'The raw request body is echoed back in the response. Combined with mass-assignment this can reflect or expose unintended fields.',
@@ -853,7 +919,7 @@ const aiRules = [
853
919
  id: 'ai.browser-api-key',
854
920
  severity: 'critical',
855
921
  confidence: 'high',
856
- title: 'AI SDK configured to run in the browser',
922
+ cwe: 'CWE-94', owasp: 'A03', title: 'AI SDK configured to run in the browser',
857
923
  re: /dangerouslyAllowBrowser\s*:\s*true/,
858
924
  skipComments: true,
859
925
  message: 'dangerouslyAllowBrowser: true ships your AI provider API key to the browser, where anyone can steal it.',
@@ -863,7 +929,7 @@ const aiRules = [
863
929
  id: 'ai.disabled-sandbox',
864
930
  severity: 'high',
865
931
  confidence: 'high',
866
- title: 'AI agent sandbox / permission check disabled',
932
+ cwe: 'CWE-94', owasp: 'A03', title: 'AI agent sandbox / permission check disabled',
867
933
  re: /dangerouslyDisableSandbox\s*:\s*true|dangerouslySkipPermissions|--dangerously-skip-permissions|bypassPermissions\s*:\s*true/,
868
934
  skipComments: true,
869
935
  message: 'A sandbox or permission gate for an AI agent/tool is disabled — the model can run unrestricted actions.',
@@ -873,7 +939,7 @@ const aiRules = [
873
939
  id: 'ai.eval-llm-output',
874
940
  severity: 'high',
875
941
  confidence: 'medium',
876
- title: 'Executing LLM output as code',
942
+ cwe: 'CWE-94', owasp: 'A03', title: 'Executing LLM output as code',
877
943
  re: /\b(?:eval|Function)\s*\(\s*[^)]*(?:completion|response|llmOutput|aiResponse|message\.content|choices\[0\]|\.text\b|generatedCode)/i,
878
944
  skipComments: true,
879
945
  message: 'Model output is executed as code (eval/Function). A prompt-injected response becomes remote code execution.',
@@ -883,7 +949,7 @@ const aiRules = [
883
949
  id: 'ai.prompt-injection-marker',
884
950
  severity: 'medium',
885
951
  confidence: 'low',
886
- title: 'Prompt-injection phrase in code / tool description',
952
+ cwe: 'CWE-94', owasp: 'A03', title: 'Prompt-injection phrase in code / tool description',
887
953
  re: /ignore\s+(?:all\s+)?(?:previous|prior|above)\s+instructions|disregard\s+(?:the\s+)?(?:above|previous)|jailbreak\s+mode|\bDAN\s+mode\b|you\s+are\s+now\s+(?:in\s+)?developer\s+mode/i,
888
954
  skipComments: false,
889
955
  message: 'A classic prompt-injection phrase appears here (e.g. in an MCP tool description or system prompt). If this text can reach an LLM, it can hijack it.',
@@ -900,7 +966,7 @@ const injectionRules = [
900
966
  id: 'injection.prototype-pollution',
901
967
  severity: 'high',
902
968
  confidence: 'medium',
903
- title: 'Prototype pollution via deep merge of request data',
969
+ cwe: 'CWE-94', owasp: 'A03', title: 'Prototype pollution via deep merge of request data',
904
970
  re: /\b(?:_\.)?(?:merge|mergeWith|defaultsDeep|extend|set|setWith)\s*\([^)]*\breq\.(?:body|query|params)\b|deepmerge\s*\([^)]*\breq\.(?:body|query|params)\b|Object\.assign\s*\([^)]*\breq\.(?:body|query|params)\b/i,
905
971
  skipComments: true,
906
972
  message: 'A deep-merge/set of request data can set __proto__/constructor keys — prototype pollution.',
@@ -910,7 +976,7 @@ const injectionRules = [
910
976
  id: 'injection.redos-user-regex',
911
977
  severity: 'high',
912
978
  confidence: 'high',
913
- title: 'RegExp built from user input (ReDoS)',
979
+ cwe: 'CWE-94', owasp: 'A03', title: 'RegExp built from user input (ReDoS)',
914
980
  re: /new\s+RegExp\s*\(\s*[^)]*\breq\.(?:body|query|params)\b/,
915
981
  skipComments: true,
916
982
  message: 'A RegExp is constructed from user input — a crafted pattern causes catastrophic backtracking (ReDoS) and can DoS the process.',
@@ -920,7 +986,7 @@ const injectionRules = [
920
986
  id: 'injection.xxe',
921
987
  severity: 'high',
922
988
  confidence: 'medium',
923
- title: 'XML parser with external entities enabled',
989
+ cwe: 'CWE-94', owasp: 'A03', title: 'XML parser with external entities enabled',
924
990
  re: /noent\s*:\s*true|resolveExternalEntities\s*:\s*true|expandEntities\s*:\s*true|XMLParser\([^)]*processEntities\s*:\s*true/i,
925
991
  skipComments: true,
926
992
  message: 'XML external entity expansion is enabled — XXE lets attackers read files and reach internal services.',
@@ -930,7 +996,7 @@ const injectionRules = [
930
996
  id: 'injection.crlf',
931
997
  severity: 'medium',
932
998
  confidence: 'low',
933
- title: 'User input written to a response header',
999
+ cwe: 'CWE-94', owasp: 'A03', title: 'User input written to a response header',
934
1000
  re: /\bres\.(?:setHeader|writeHead|header)\s*\([^)]*\breq\.(?:body|query|params|headers)\b/,
935
1001
  skipComments: true,
936
1002
  message: 'User input is used in a response header — CRLF injection can split headers or set arbitrary cookies.',
@@ -972,34 +1038,52 @@ const ENTROPY_SKIP_FILE = /(?:package-lock\.json|yarn\.lock|pnpm-lock\.yaml|Carg
972
1038
  // known-public tokens.
973
1039
  const ENTROPY_SKIP_PREFIX = /^(?:sk-|sk_live_|sk_test_|rk_live_|pk_live_|pk_test_|AKIA|ASIA|AIza|eyJ|ghp_|gho_|xox[baprs]-)/;
974
1040
 
1041
+ // Entropy engine for the high-entropy-token rule (pure functions, see src/entropy.js).
1042
+ const { findHighEntropyTokens } = require('./entropy');
1043
+
975
1044
  const fileRules = [
976
1045
  {
977
1046
  id: 'secret.high-entropy',
978
1047
  severity: 'high',
979
1048
  confidence: 'medium',
980
1049
  title: 'High-entropy string (possible hardcoded secret)',
981
- run(content, lines, relPath) {
982
- if (ENTROPY_SKIP_FILE.test(relPath || '')) return [];
983
- const out = [];
984
- const strRe = /['"`]([A-Za-z0-9+/=_\-]{24,120})['"`]/g;
985
- for (let i = 0; i < lines.length; i++) {
986
- const line = lines[i];
987
- if (line.length > 2000) continue;
988
- let m;
989
- strRe.lastIndex = 0;
990
- while ((m = strRe.exec(line)) !== null) {
991
- const val = m[1];
992
- if (ENTROPY_SKIP_PREFIX.test(val)) continue;
993
- if (looksLikePlaceholder(val)) continue;
994
- if (isPublicBaaSKey(line, val)) continue;
995
- // UUID — structured, not a secret.
996
- if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(val)) continue;
997
- // Pure-hex of checksum lengths (md5/sha1/sha256) — usually a hash, not a secret.
998
- if (/^[0-9a-f]+$/i.test(val) && [32, 40, 64].includes(val.length)) continue;
999
- // Must have digit+letter mix (avoids long English identifiers / base64 words).
1000
- if (!/[0-9]/.test(val) || !/[A-Za-z]/.test(val)) continue;
1001
- if (shannonEntropy(val) < 4.0) continue;
1002
- out.push({
1050
+ run(content, lines, relPath, priorFindings) {
1051
+ if (ENTROPY_SKIP_FILE.test(relPath || '')) return [];
1052
+ const out = [];
1053
+ // Lines already reported by a specific secret.* line rule. The
1054
+ // high-entropy hint is meant to catch *unclassified* tokens; firing it
1055
+ // again on the same line a specific rule already flagged (at any
1056
+ // confidence) is pure noise, e.g. AWS env keys which are 'low'.
1057
+ const priorSecretLines = new Set();
1058
+ if (Array.isArray(priorFindings)) {
1059
+ for (const f of priorFindings) {
1060
+ if (f && typeof f.ruleId === 'string' && f.ruleId.startsWith('secret.') &&
1061
+ typeof f.line === 'number') {
1062
+ priorSecretLines.add(f.line);
1063
+ }
1064
+ }
1065
+ }
1066
+ const strRe = /['"`]([A-Za-z0-9+/=_\-]{24,120})['"`]/g;
1067
+ for (let i = 0; i < lines.length; i++) {
1068
+ const line = lines[i];
1069
+ if (line.length > 2000) continue;
1070
+ let m;
1071
+ strRe.lastIndex = 0;
1072
+ while ((m = strRe.exec(line)) !== null) {
1073
+ const val = m[1];
1074
+ if (ENTROPY_SKIP_PREFIX.test(val)) continue;
1075
+ if (looksLikePlaceholder(val)) continue;
1076
+ if (isPublicBaaSKey(line, val)) continue;
1077
+ // UUID — structured, not a secret.
1078
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(val)) continue;
1079
+ // Pure-hex of checksum lengths (md5/sha1/sha256) — usually a hash, not a secret.
1080
+ if (/^[0-9a-f]+$/i.test(val) && [32, 40, 64].includes(val.length)) continue;
1081
+ // Must have digit+letter mix (avoids long English identifiers / base64 words).
1082
+ if (!/[0-9]/.test(val) || !/[A-Za-z]/.test(val)) continue;
1083
+ if (shannonEntropy(val) < 4.0) continue;
1084
+ // Skip if a specific secret rule already raised this exact line.
1085
+ if (priorSecretLines.has(i + 1)) continue;
1086
+ out.push({
1003
1087
  line: i + 1,
1004
1088
  column: (m.index || 0) + 1,
1005
1089
  snippet: (val.slice(0, 4) + '****' + val.slice(-2)),
@@ -1012,6 +1096,40 @@ const fileRules = [
1012
1096
  return out;
1013
1097
  },
1014
1098
  },
1099
+ {
1100
+ id: 'secret.high-entropy-token',
1101
+ severity: 'high',
1102
+ confidence: 'medium',
1103
+ title: 'High-entropy secret-like token',
1104
+ // Function-based rule: no `re`, a `match(content, ctx)` instead (the scanner
1105
+ // calls it in the fileRules loop). Catches random-looking tokens (24-80
1106
+ // chars, entropy >= 4.0) assigned to key-like names — schemes NO known
1107
+ // regex rule owns. Lines a specific secret.* rule (or the sibling
1108
+ // high-entropy rule) already flagged are suppressed so it never
1109
+ // double-reports; ctx.findings is the scanner's live accumulator.
1110
+ match(content, ctx) {
1111
+ const priorSecretLines = new Set();
1112
+ if (ctx && Array.isArray(ctx.findings)) {
1113
+ for (const f of ctx.findings) {
1114
+ if (f && typeof f.ruleId === 'string' && f.ruleId.startsWith('secret.') && typeof f.line === 'number') {
1115
+ priorSecretLines.add(f.line);
1116
+ }
1117
+ }
1118
+ }
1119
+ const hits = [];
1120
+ for (const t of findHighEntropyTokens(content)) {
1121
+ if (priorSecretLines.has(t.line)) continue;
1122
+ // Public-by-design BaaS keys (Firebase AIza..., anon/publishable-named)
1123
+ // must never fire — same FP guard the sibling rule applies.
1124
+ const line = (ctx && ctx.lines && ctx.lines[t.line - 1]) || '';
1125
+ if (isPublicBaaSKey(line, t.match)) continue;
1126
+ hits.push({ index: t.index, match: t.match });
1127
+ }
1128
+ return hits;
1129
+ },
1130
+ message: 'High-entropy string assigned to a key-like name — possible hardcoded API key or token.',
1131
+ fix: 'Remove it, load from an environment variable, and rotate the key if real.',
1132
+ },
1015
1133
  {
1016
1134
  id: 'pii.full-record-response',
1017
1135
  severity: 'medium',
@@ -1285,6 +1403,12 @@ const fileRules = [
1285
1403
  if (/permissions:\s*write-all/i.test(l)) {
1286
1404
  out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'permissions: write-all grants the token full write access to the repo.', fix: 'Set least-privilege permissions per job (e.g. contents: read).' });
1287
1405
  }
1406
+ if (/pull_request_target/i.test(l)) {
1407
+ out.push({ line: i + 1, column: 1, severity: 'high', confidence: 'medium', snippet: l.trim().slice(0, 100), message: 'pull_request_target runs the target-repo workflow with a writable GITHUB_TOKEN against PR code — a classic CI take-over when combined with untrusted checkout or script injection.', fix: 'Prefer pull_request, or add an explicit environment/approval gate and never checkout the PR head with a writable token.' });
1408
+ }
1409
+ if (/curl[^|\n]*\|\s*(?:bash|sh)\b|wget[^|\n]*-O-[^|\n]*\|\s*(?:bash|sh)\b/i.test(l)) {
1410
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'Piping a remote installer into a shell executes unverifiable code on the runner (supply-chain risk).', fix: 'Download the installer to a file, verify its signature/checksum, then run it — or use a maintained package manager action.' });
1411
+ }
1288
1412
  const uses = /^\s*-?\s*uses:\s*([\w.\-]+\/[\w.\-]+)@([\w.\-]+)\s*$/.exec(l);
1289
1413
  if (uses && !/^[0-9a-f]{40}$/.test(uses[2])) {
1290
1414
  out.push({ line: i + 1, column: 1, severity: 'low', snippet: l.trim().slice(0, 100), message: `Action ${uses[1]} is pinned to a tag/branch (@${uses[2]}), not a commit SHA — a moved tag can inject malicious code.`, fix: 'Pin third-party actions to a full commit SHA.' });
@@ -1316,6 +1440,63 @@ const fileRules = [
1316
1440
  return out;
1317
1441
  },
1318
1442
  },
1443
+ {
1444
+ id: 'iac.kubernetes',
1445
+ severity: 'high',
1446
+ confidence: 'high',
1447
+ title: 'Kubernetes manifest security context',
1448
+ run(content, lines, relPath) {
1449
+ if (!/\.(?:ya?ml)$/.test(relPath || '')) return [];
1450
+ if (!/\b(?:apiVersion|kind):\s*(?:Deployment|Pod|StatefulSet|DaemonSet|Job|CronJob)\b/.test(content)) return [];
1451
+ const out = [];
1452
+ const blockUntil = /^\s{0,6}\S/;
1453
+ for (let i = 0; i < lines.length; i++) {
1454
+ const l = lines[i];
1455
+ if (/privileged:\s*true/i.test(l)) {
1456
+ out.push({ line: i + 1, column: 1, severity: 'high', snippet: l.trim().slice(0, 100), message: 'Container runs privileged — it can escape the sandbox and touch the host kernel/devices (the classic K8s container-escape).', fix: 'Set securityContext.privileged: false (or omit it) and drop capabilities instead of running privileged.' });
1457
+ }
1458
+ if (/runAsUser:\s*0\b/i.test(l)) {
1459
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'runAsUser: 0 runs the container as root — a compromise gets immediate root in the pod.', fix: 'Use a non-zero runAsUser plus runAsNonRoot: true to force a non-root container UID.' });
1460
+ }
1461
+ if (/hostNetwork:\s*true|hostPID:\s*true|hostIPC:\s*true/i.test(l)) {
1462
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'hostNetwork/hostPID/hostIPC: true shares the host network/process/IPC namespace — the pod can sniff traffic and see host processes.', fix: 'Remove these unless the workload truly needs host namespaces (most do not).' });
1463
+ }
1464
+ if (/allowPrivilegeEscalation:\s*true/i.test(l)) {
1465
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'allowPrivilegeEscalation: true lets a setuid binary inside the container gain more privileges than its parent.', fix: 'Set allowPrivilegeEscalation: false.' });
1466
+ }
1467
+ if (/default-token|automountServiceAccountToken:\s*true/i.test(l)) {
1468
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'A service-account token is auto-mounted into the pod — code in the pod can talk to the K8s API as that account.', fix: 'Set automountServiceAccountToken: false unless the pod really needs API access, and use a minimal RBAC role.' });
1469
+ }
1470
+ if (/capabilities:[\s\S]{0,80}?add:[\s\S]{0,40}?(?:ALL|SYS_ADMIN|NET_ADMIN)/.test(l) || /add:\s*\[\s*(?:ALL|SYS_ADMIN|NET_ADMIN)/.test(l)) {
1471
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'A dangerous Linux capability (ALL / SYS_ADMIN / NET_ADMIN) is added — near-privileged without the flag.', fix: 'Drop all capabilities and add back only the specific ones the workload needs.' });
1472
+ }
1473
+ }
1474
+ return out;
1475
+ },
1476
+ },
1477
+ {
1478
+ id: 'iac.docker-compose',
1479
+ severity: 'high',
1480
+ confidence: 'high',
1481
+ title: 'Docker Compose security misconfiguration',
1482
+ run(content, lines, relPath) {
1483
+ if (!/(?:^|\/)(?:docker-)?compose\.(?:ya?ml)$/.test(relPath || '') && !/docker-compose\.(?:ya?ml|yml)/.test(relPath || '')) return [];
1484
+ const out = [];
1485
+ for (let i = 0; i < lines.length; i++) {
1486
+ const l = lines[i];
1487
+ if (/(?:^|[\s"':])v[^\s"']*\/var\/run\/docker\.sock|docker\.sock/i.test(l)) {
1488
+ out.push({ line: i + 1, column: 1, severity: 'high', snippet: l.trim().slice(0, 100), message: 'Mounting /var/run/docker.sock gives the container full root control of the Docker daemon (host take-over).', fix: 'Do not mount the Docker socket into containers; use a rootless builder or a dedicated, least-privileged service.' });
1489
+ }
1490
+ if (/network_mode:\s*["']?host["']?/i.test(l)) {
1491
+ out.push({ line: i + 1, column: 1, severity: 'medium', snippet: l.trim().slice(0, 100), message: 'network_mode: host removes network isolation — the container shares the host network stack and can sniff host traffic.', fix: 'Use a bridge or overlay network unless the workload truly needs host networking.' });
1492
+ }
1493
+ if (/\b(?:[A-Z_]*?(?:PASSWORD|SECRET|TOKEN|API_?KEY|PRIVATE_?KEY|CREDENTIAL)[A-Z_]*?)\s*[:=]\s*[^$"'*\s]/.test(l) && !/^\s*#/.test(l)) {
1494
+ out.push({ line: i + 1, column: 1, severity: 'high', snippet: l.trim().slice(0, 100), message: 'A hardcoded secret/credential sits in docker-compose — it ends up in the image, the Compose spec, and often version control.', fix: 'Move secrets to an env_file, Docker secrets, or a .env file that is gitignored.' });
1495
+ }
1496
+ }
1497
+ return out;
1498
+ },
1499
+ },
1319
1500
  {
1320
1501
  id: 'nextjs.missing-security-headers',
1321
1502
  severity: 'low',
@@ -1393,6 +1574,116 @@ const fileRules = [
1393
1574
  return out;
1394
1575
  },
1395
1576
  },
1577
+ {
1578
+ id: 'injection.xss-vue-v-html',
1579
+ severity: 'high',
1580
+ confidence: 'high',
1581
+ title: 'Vue v-html with user data — XSS',
1582
+ run(content, lines, relPath) {
1583
+ const ext = (relPath || '').toLowerCase();
1584
+ if (!/\.(?:vue|js|jsx|ts|tsx|html|mjs|cjs)$/.test(ext)) return [];
1585
+ const REQ_SRC = /\b(?:req|request|event|ctx)\s*\.\s*[A-Za-z_$][\w$]*|\b(?:location\.search|location\.hash|window\.location|document\.URL|document\.location)\b|\b(?:searchParams|URLSearchParams)\b/i;
1586
+ const ASSIGN = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(.+?)\s*;?\s*$/;
1587
+ const derived = new Set();
1588
+ let changed = true;
1589
+ for (let pass = 0; pass < 6 && changed; pass++) {
1590
+ changed = false;
1591
+ for (const line of lines) {
1592
+ const m = ASSIGN.exec(line);
1593
+ if (!m || derived.has(m[1])) continue;
1594
+ const rhs = m[2];
1595
+ if (REQ_SRC.test(rhs)) { derived.add(m[1]); changed = true; continue; }
1596
+ for (const v of derived) {
1597
+ if (new RegExp(`\\b${v.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(rhs)) {
1598
+ derived.add(m[1]); changed = true; break;
1599
+ }
1600
+ }
1601
+ }
1602
+ }
1603
+ const VHTML = /v-html\s*=\s*["']([^"']+)["']/gi;
1604
+ const out = [];
1605
+ for (let i = 0; i < lines.length; i++) {
1606
+ const line = lines[i];
1607
+ let m;
1608
+ VHTML.lastIndex = 0;
1609
+ while ((m = VHTML.exec(line)) !== null) {
1610
+ const bound = m[1];
1611
+ // Collect identifiers bound into v-html — supports `${var}` (ES template),
1612
+ // `{{ var }}` (Vue interpolation), and a bare `var` — then check whether any
1613
+ // is a request-derived variable, or the binding itself references a source.
1614
+ const ids = [];
1615
+ let mm;
1616
+ const tRe = /\$\{([A-Za-z_$][\w$]*)\}/g;
1617
+ while ((mm = tRe.exec(bound))) ids.push(mm[1]);
1618
+ const vRe = /\{\{\s*([A-Za-z_$][\w$]*)/g;
1619
+ while ((mm = vRe.exec(bound))) ids.push(mm[1]);
1620
+ const bare = /^([A-Za-z_$][\w$]*)$/.exec(bound);
1621
+ if (bare) ids.push(bare[1]);
1622
+ const dangerous =
1623
+ REQ_SRC.test(bound) ||
1624
+ ids.some((id) => derived.has(id.split('.')[0]));
1625
+ if (dangerous) {
1626
+ out.push({
1627
+ ruleId: 'injection.xss-vue-v-html', severity: 'high', confidence: 'high',
1628
+ title: 'Vue v-html with user data — XSS',
1629
+ message: 'v-html is bound to request-derived data — XSS.',
1630
+ fix: 'Never use v-html with user input. Use v-text or sanitize with DOMPurify.',
1631
+ line: i + 1, column: (m.index || 0) + 1,
1632
+ snippet: line.trim().slice(0, 120),
1633
+ });
1634
+ }
1635
+ }
1636
+ }
1637
+ return out;
1638
+ },
1639
+ },
1640
+ {
1641
+ id: 'ai.prompt-injection-encoded-base64',
1642
+ severity: 'high',
1643
+ confidence: 'medium',
1644
+ title: 'Base64-encoded prompt-injection payload',
1645
+ match(content) {
1646
+ return require('./injection-decode').matchBase64Encoded(content);
1647
+ },
1648
+ message: 'A base64-encoded prompt-injection payload is hidden here — the decoded text contains a classic instruction-override phrase. If this text can reach an LLM, the decode defeats naive filters.',
1649
+ fix: 'Remove the encoded payload; treat tool descriptions and external content as data, not instructions.',
1650
+ cwe: 'CWE-94', owasp: 'A03',
1651
+ },
1652
+ {
1653
+ id: 'ai.prompt-injection-encoded-escapes',
1654
+ severity: 'high',
1655
+ confidence: 'medium',
1656
+ title: 'Hex/unicode-escaped prompt-injection payload',
1657
+ match(content) {
1658
+ return require('./injection-decode').matchEscapedEncoded(content);
1659
+ },
1660
+ message: 'A \\xNN / \\uNNNN-escaped prompt-injection phrase is hidden here. Escapes are a classic evasion against plain-text filters.',
1661
+ fix: 'Remove the escaped payload; treat tool descriptions and external content as data, not instructions.',
1662
+ cwe: 'CWE-94', owasp: 'A03',
1663
+ },
1664
+ {
1665
+ id: 'ai.prompt-injection-encoded-rot13',
1666
+ severity: 'high',
1667
+ confidence: 'medium',
1668
+ title: 'ROT13-obfuscated prompt-injection payload',
1669
+ match(content) {
1670
+ return require('./injection-decode').matchRot13Encoded(content);
1671
+ },
1672
+ message: 'A ROT13-obfuscated prompt-injection payload is hidden here — the rotated text contains a classic instruction-override phrase.',
1673
+ fix: 'Remove the obfuscated payload; treat tool descriptions and external content as data, not instructions.',
1674
+ cwe: 'CWE-94', owasp: 'A03',
1675
+ },
1676
+ {
1677
+ id: 'ai.prompt-injection-obfuscated',
1678
+ severity: 'high',
1679
+ confidence: 'medium',
1680
+ title: 'Obfuscated prompt-injection (zero-width/homoglyph)',
1681
+ match(content, ctx) {
1682
+ return require('./injection-decode').matchObfuscated(content, ctx);
1683
+ },
1684
+ message: 'A prompt-injection payload obfuscated with zero-width characters or homoglyphs (digit-substituted words) appears here.',
1685
+ fix: 'Remove the obfuscated payload; treat tool descriptions and external content as data, not instructions.',
1686
+ },
1396
1687
  ];
1397
1688
 
1398
1689
  // ---------------------------------------------------------------------------
@@ -1452,7 +1743,32 @@ const crossFileRules = [
1452
1743
  },
1453
1744
  ];
1454
1745
 
1746
+ // ---------------------------------------------------------------------------
1747
+ // 2026 pack — the AI-code-specific classes (authz/IDOR, Next.js, RLS
1748
+ // correctness, LLM output handling, crypto, log injection, supply chain, MCP).
1749
+ // Kept in its own module: it is the research-driven layer and grows fastest.
1750
+ // ---------------------------------------------------------------------------
1751
+ try {
1752
+ const pack2026 = require('./rules-2026');
1753
+ const seenIds = new Set([...lineRules, ...fileRules, ...crossFileRules].map((r) => r.id));
1754
+ for (const r of pack2026.lineRules || []) {
1755
+ if (r && r.id && !seenIds.has(r.id)) { lineRules.push(r); seenIds.add(r.id); }
1756
+ }
1757
+ for (const r of pack2026.fileRules || []) {
1758
+ if (r && r.id && !seenIds.has(r.id)) { fileRules.push(r); seenIds.add(r.id); }
1759
+ }
1760
+ for (const r of pack2026.crossFileRules || []) {
1761
+ if (r && r.id && !seenIds.has(r.id)) { crossFileRules.push(r); seenIds.add(r.id); }
1762
+ }
1763
+ } catch (err) {
1764
+ // A broken optional pack must never take the scanner down; it simply does not
1765
+ // load, and VIBEGUARD_DEBUG_RULES surfaces why during development.
1766
+ if (process.env.VIBEGUARD_DEBUG_RULES) process.stderr.write(`rules-2026 load failed: ${err.message}\n`);
1767
+ }
1768
+
1455
1769
  // Flat registry of every rule (for `vibeguard rules` / `explain`). File/cross
1770
+
1771
+ // Flat registry of every rule (for `vibeguard rules` / `explain`). File/cross
1456
1772
  // rules carry dynamic messages, so message/fix may be empty there — title covers it.
1457
1773
  function allRules() {
1458
1774
  const out = [];