@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/entropy.js ADDED
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Entropy-based high-entropy secret detection (TruffleHog-style).
5
+ *
6
+ * Pure functions, zero runtime deps. The idea: secrets are random-looking, so
7
+ * a long string with unusually high Shannon entropy that sits on a key-like
8
+ * line is a strong signal even when NO known scheme matches. The context gate
9
+ * (a key-like identifier on the line / ±2 lines) is the FP killer — without it
10
+ * every minified blob or hash would fire.
11
+ *
12
+ * Exposed:
13
+ * shannonEntropy(str) -> bits/char (H = -Σ p(x) log2 p(x))
14
+ * findHighEntropyTokens(content) -> [{ index, match, entropy, reason, line }]
15
+ * (line = 1-based, index = char offset)
16
+ */
17
+
18
+ // Shannon entropy in bits/char over the string's character alphabet.
19
+ // A 32-char random alnum token ≈ 4.5-5.0+ bits/char; normal English ≈ 3.5-4.0.
20
+ function shannonEntropy(str) {
21
+ const freq = Object.create(null);
22
+ for (const c of str) freq[c] = (freq[c] || 0) + 1;
23
+ let e = 0;
24
+ const n = str.length;
25
+ if (n === 0) return 0;
26
+ for (const k in freq) {
27
+ const p = freq[k] / n;
28
+ e -= p * Math.log2(p);
29
+ }
30
+ return e;
31
+ }
32
+
33
+ const MIN_ENTROPY = 4.0;
34
+
35
+ // A key-like identifier that makes a high-entropy string look like a secret.
36
+ const KEY_CONTEXT_RE =
37
+ /api[_-]?key|secret|token|password|passwd|credential|auth|bearer|private[_-]?key|access[_-]?key|client[_-]?secret|session[_-]?id/i;
38
+
39
+ // Token candidates: bare [A-Za-z0-9_-] runs, 24-80 chars, word-boundaried.
40
+ const TOKEN_RE = /\b[A-Za-z0-9_\-]{24,80}\b/g;
41
+
42
+ // Checksum-length hex (md5/sha1/sha256/sha512) — hashes, not secrets.
43
+ const CHECKSUM_HEX_RE = /^(?:[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64})$/i;
44
+ // UUIDs (8-4-4-4-12 hex) — structured ids, not secrets.
45
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
46
+ // Pure hex 24-64 (ambiguous) — only flagged when the context gate passes.
47
+ const PURE_HEX_RE = /^[0-9a-f]+$/i;
48
+ // Version strings (semver-ish) — split on dots, so defensive only.
49
+ const SEMVER_RE = /^\d+\.\d+\.\d+/;
50
+ // JWT-shaped header.payload.signature — covered by the dedicated rule.
51
+ const JWT_RE = /^[A-Za-z0-9_\-]{4,}\.[A-Za-z0-9_\-]{4,}\.[A-Za-z0-9_\-]{4,}/;
52
+ // URLs — path segments inside them are not secrets.
53
+ const URL_RE = /https?:\/\/\S+/g;
54
+ const BASE64_CHAR = /[A-Za-z0-9+/=]/;
55
+
56
+ // Expand to the maximal base64-ish run surrounding [start, end) on the line.
57
+ function base64RunOf(line, start, end) {
58
+ let s = start;
59
+ let e = end;
60
+ while (s > 0 && BASE64_CHAR.test(line[s - 1])) s--;
61
+ while (e < line.length && BASE64_CHAR.test(line[e])) e++;
62
+ return line.slice(s, e);
63
+ }
64
+
65
+ // base64 of normal text: decode and re-check. If the decoded payload is mostly
66
+ // printable ASCII with LOW entropy (< 3.5), it is base64 of prose — not a
67
+ // secret. Binary or high-entropy payloads are kept (real secrets).
68
+ function isBase64OfPlainText(run) {
69
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(run)) return false;
70
+ if (run.length < 16) return false;
71
+ let buf;
72
+ try {
73
+ buf = Buffer.from(run, 'base64');
74
+ } catch {
75
+ return false;
76
+ }
77
+ if (!buf || buf.length < 8) return false;
78
+ let printable = 0;
79
+ for (let i = 0; i < buf.length; i++) {
80
+ const c = buf[i];
81
+ if (c === 9 || c === 10 || c === 13 || (c >= 32 && c < 127)) printable++;
82
+ }
83
+ if (printable / buf.length < 0.9) return false; // binary payload — keep
84
+ return shannonEntropy(buf.toString('latin1')) < 3.5;
85
+ }
86
+
87
+ // Does any line in [i-2, i+2] carry a key-like identifier? The candidate token
88
+ // itself is removed first so a random string can't smuggle in its own context.
89
+ function contextPasses(lines, i, token) {
90
+ const from = Math.max(0, i - 2);
91
+ const to = Math.min(lines.length - 1, i + 2);
92
+ for (let j = from; j <= to; j++) {
93
+ if (KEY_CONTEXT_RE.test(lines[j].split(token).join(''))) return true;
94
+ }
95
+ return false;
96
+ }
97
+
98
+ // Find high-entropy tokens that look like hardcoded secrets.
99
+ // Returns [{ index, match, entropy, reason, line }]:
100
+ // index — char offset of the token in `content`
101
+ // match — the raw token string
102
+ // entropy— shannonEntropy(match)
103
+ // reason — why it was flagged
104
+ // line — 1-based line number (used by the rule for double-report suppression)
105
+ function findHighEntropyTokens(content) {
106
+ const out = [];
107
+ const lines = content.split(/\r?\n/);
108
+ let lineStart = 0; // char offset of the current line inside `content`
109
+ for (let i = 0; i < lines.length; i++) {
110
+ const line = lines[i];
111
+ if (line.length > 2000) {
112
+ // Minified/embedded blob line — same guard as the sibling rule.
113
+ const nl = content.indexOf('\n', lineStart);
114
+ lineStart = nl === -1 ? content.length : nl + 1;
115
+ continue;
116
+ }
117
+ URL_RE.lastIndex = 0;
118
+ TOKEN_RE.lastIndex = 0;
119
+ let m;
120
+ while ((m = TOKEN_RE.exec(line)) !== null) {
121
+ const token = m[0];
122
+ const absIndex = lineStart + m.index;
123
+ const entropy = shannonEntropy(token);
124
+ if (entropy < MIN_ENTROPY) continue;
125
+
126
+ // Checksum-length hex and UUIDs — structured ids, not secrets.
127
+ if (CHECKSUM_HEX_RE.test(token)) continue;
128
+ if (UUID_RE.test(token)) continue;
129
+
130
+ // JWT-shaped (header.payload.signature) — dedicated rule owns it.
131
+ let s = m.index;
132
+ let e = m.index + token.length;
133
+ while (s > 0 && /[A-Za-z0-9_\-.]/.test(line[s - 1])) s--;
134
+ while (e < line.length && /[A-Za-z0-9_\-.]/.test(line[e])) e++;
135
+ if (JWT_RE.test(line.slice(s, e))) continue;
136
+
137
+ // Inside a URL — path segments and query strings are not secrets.
138
+ let um;
139
+ let insideUrl = false;
140
+ while ((um = URL_RE.exec(line)) !== null) {
141
+ if (m.index >= um.index && m.index + token.length <= um.index + um[0].length) {
142
+ insideUrl = true;
143
+ break;
144
+ }
145
+ }
146
+ if (insideUrl) continue;
147
+
148
+ // File-path segment — slash or backslash adjacent to the token.
149
+ if (
150
+ (m.index > 0 && (line[m.index - 1] === '/' || line[m.index - 1] === '\\')) ||
151
+ (m.index + token.length < line.length &&
152
+ (line[m.index + token.length] === '/' || line[m.index + token.length] === '\\'))
153
+ ) {
154
+ continue;
155
+ }
156
+
157
+ // Semver / version-ish strings (defensive — dots split tokens anyway).
158
+ if (SEMVER_RE.test(token)) continue;
159
+
160
+ // base64 of plain text — decode and re-check.
161
+ if (isBase64OfPlainText(base64RunOf(line, m.index, m.index + token.length))) continue;
162
+
163
+ // Pure-hex 24-64 (non-checksum) is ambiguous: only flag it when the
164
+ // context gate below ALSO passes (it must pass for every token anyway).
165
+ const isAmbiguousHex = PURE_HEX_RE.test(token) && token.length >= 24 && token.length <= 64;
166
+
167
+ // CONTEXT GATE — the FP killer: a key-like identifier on this line or
168
+ // within ±2 lines.
169
+ if (!contextPasses(lines, i, token)) continue;
170
+
171
+ out.push({
172
+ index: absIndex,
173
+ match: token,
174
+ entropy,
175
+ reason: isAmbiguousHex
176
+ ? 'high-entropy hex token on a key-like line'
177
+ : 'high-entropy token on a key-like line',
178
+ line: i + 1,
179
+ });
180
+ }
181
+ const nl = content.indexOf('\n', lineStart);
182
+ lineStart = nl === -1 ? content.length : nl + 1;
183
+ }
184
+ return out;
185
+ }
186
+
187
+ module.exports = { shannonEntropy, findHighEntropyTokens };
package/src/firewall.js CHANGED
@@ -24,6 +24,7 @@
24
24
  */
25
25
 
26
26
  const { detectPII, redactText } = require('./pii');
27
+ const { scanTextForInjection } = require('./mcp-audit');
27
28
 
28
29
  // Threat patterns — each is a category of attack
29
30
  const THREATS = [
@@ -47,7 +48,7 @@ const THREATS = [
47
48
  {
48
49
  id: 'INJECT.REVEAL_SYSTEM',
49
50
  severity: 'high',
50
- re: /(?:show|reveal|display|print|output|dump|tell\s+me|what\s+(?:are|is))\s+(?:your\s+)?(?:system\s+)?(?:prompt|instructions?|rules?|guidelines?|directives?|system\s+message|initial\s+message)/i,
51
+ re: /(?:show|reveal|display|print|output|dump|tell\s+me|what\s+(?:are|is))\s+(?:your\s+|the\s+)?(?:system\s+)?(?:prompt|instructions?|rules?|guidelines?|directives?|system\s+message|initial\s+message)/i,
51
52
  action: 'block',
52
53
  reason: 'Prompt extraction: attempting to reveal system prompt',
53
54
  fix: 'This request tries to extract the system prompt. Block it.',
@@ -97,7 +98,7 @@ const THREATS = [
97
98
  {
98
99
  id: 'CAP.ACCESS_SECRETS',
99
100
  severity: 'critical',
100
- re: /(?:show|read|display|output|print|get|access|fetch|tell\s+me)\s+(?:me\s+)?(?:my\s+|the\s+|all\s+)?(?:secrets?|\.env|environment\s+variables?|API\s+keys?|tokens?|passwords?|credentials?|private\s+keys?)/i,
101
+ re: /(?:show|read|display|output|print|get|access|fetch|tell\s+me)\s+(?:me\s+)?(?:my\s+|the\s+|all\s+)?(?:secrets?|\.env(?!\.example)|environment\s+variables?|API\s+keys?|tokens?|passwords?|credentials?|private\s+keys?)/i,
101
102
  action: 'block',
102
103
  reason: 'Secret access request: asking AI to reveal secrets or env vars',
103
104
  fix: 'Never allow AI to access or reveal secrets. This is a data breach risk.',
@@ -139,7 +140,7 @@ const THREATS = [
139
140
  {
140
141
  id: 'JAILBREAK.DAN',
141
142
  severity: 'high',
142
- re: /DAN|do\s+anything\s+now|jailbreak|developer\s+mode|unrestricted\s+mode|god\s+mode/i,
143
+ re: /\bDAN\b|do\s+anything\s+now|jailbreak|developer\s+mode|unrestricted\s+mode|god\s+mode/i,
143
144
  action: 'block',
144
145
  reason: 'Jailbreak attempt: DAN or similar jailbreak pattern',
145
146
  fix: 'This is a known jailbreak pattern. Block it.',
@@ -345,6 +346,21 @@ function inspectPrompt(prompt, context = {}) {
345
346
  }
346
347
  }
347
348
 
349
+ // Layer 1b: Shared deep detector (normalization, decoders, natural-language
350
+ // secret-disclosure/hijack patterns). This closes the gap where the legacy
351
+ // firewall regex list and the MCP content scanner disagreed.
352
+ const deepHits = scanTextForInjection(prompt);
353
+ if (deepHits.length && maxAction !== 'block') {
354
+ findings.push({
355
+ threat: 'INJECT.DEEP_DETECTOR',
356
+ severity: 'high',
357
+ action: 'block',
358
+ reason: `Prompt injection detected by normalized/decoded analysis: ${deepHits.slice(0, 4).join(', ')}`,
359
+ fix: 'Block this prompt; do not let it reach the model or tool.',
360
+ });
361
+ maxAction = 'block';
362
+ }
363
+
348
364
  // Layer 2: Semantic classifier (catches paraphrased injections that evade regex)
349
365
  // Only runs if no regex block was triggered — adds a warning for suspicious prompts
350
366
  if (maxAction !== 'block') {
package/src/gif.js ADDED
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * gif.js — keyless, open GIF/memes for VibeGuard celebrations.
5
+ *
6
+ * Zero API keys required. Uses only open services that work WITHOUT auth,
7
+ * byte-verified before returning. Consistent with VibeGuard's offline-first
8
+ * privacy model: no account, no tracking, no paid tier, no key leakage.
9
+ *
10
+ * Verified backends (live-tested on this machine):
11
+ * - cataas — https://cataas.com (open "Cat as a Service": cat GIFs,
12
+ * optional text overlay via /cat/gif/says/<text>)
13
+ * - yesno.wtf — https://yesno.wtf (yes/no reaction GIFs, JSON API)
14
+ *
15
+ * Dead/rejected backends (do NOT re-add as primary):
16
+ * - Tenor (needs key, returns INVALID_ARGUMENT otherwise — tested)
17
+ * - GIPHY demo key (now 401 Unauthorized — tested)
18
+ * - Klipy (api.klipy.com auth-walled / 404 on keyless — tested)
19
+ * - Reddit JSON (blocks datacenter IPs with HTML — tested)
20
+ */
21
+
22
+ const https = require('https');
23
+ const http = require('http');
24
+ const fs = require('fs');
25
+
26
+ const UA = 'VibeGuard/1.3 (open gif showcase; https://github.com/yagyeshVyas/VibeGuard)';
27
+
28
+ function fetchJson(url) {
29
+ return new Promise((resolve, reject) => {
30
+ const client = url.startsWith('https') ? https : http;
31
+ const req = client.get(url, { headers: { 'User-Agent': UA, Accept: 'application/json' } }, (res) => {
32
+ // follow a single redirect (cataas sometimes 301s)
33
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
34
+ res.resume();
35
+ return resolve(fetchJson(res.headers.location));
36
+ }
37
+ let body = '';
38
+ res.on('data', (c) => (body += c));
39
+ res.on('end', () => {
40
+ try {
41
+ if (res.statusCode !== 200) return reject(new Error(`http ${res.statusCode}`));
42
+ resolve(JSON.parse(body));
43
+ } catch (e) {
44
+ reject(new Error('parse error: ' + e.message));
45
+ }
46
+ });
47
+ });
48
+ req.on('error', reject);
49
+ req.setTimeout(15000, () => req.destroy(new Error('timeout')));
50
+ });
51
+ }
52
+
53
+ function fetchBytes(url) {
54
+ return new Promise((resolve, reject) => {
55
+ const client = url.startsWith('https') ? https : http;
56
+ const req = client.get(url, { headers: { 'User-Agent': UA } }, (res) => {
57
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
58
+ res.resume();
59
+ return resolve(fetchBytes(res.headers.location));
60
+ }
61
+ const chunks = [];
62
+ res.on('data', (c) => chunks.push(c));
63
+ res.on('end', () => {
64
+ if (res.statusCode !== 200) return reject(new Error(`http ${res.statusCode}`));
65
+ resolve(Buffer.concat(chunks));
66
+ });
67
+ });
68
+ req.on('error', reject);
69
+ req.setTimeout(20000, () => req.destroy(new Error('timeout')));
70
+ });
71
+ }
72
+
73
+ // Map a free-text query to the working keyless backends. Generic GIF search
74
+ // needs an API key (see header comment) — so we route by intent to the open
75
+ // services that actually deliver.
76
+ function backendFor(query) {
77
+ const q = String(query || '').toLowerCase();
78
+ if (/\b(cat|cats|kitten|kittens|kitty|meow)\b/.test(q)) {
79
+ const says = q.match(/\bsays?\s+(.+)/);
80
+ const base = 'https://cataas.com/cat/gif';
81
+ const url = says ? `${base}/says/${encodeURIComponent(says[1].trim())}` : base;
82
+ // cataas sometimes 500s on the bare endpoint; fall back to the says variant.
83
+ const fallbackUrl = says ? base : `${base}/says/cat`;
84
+ return { source: 'cataas', url, fallbackUrl, title: says ? `cat gif: ${says[1].trim()}` : 'cat gif', license: 'open' };
85
+ }
86
+ if (/\b(yes|no|maybe|agree|disagree|approve|deny)\b/.test(q)) {
87
+ return { source: 'yesno', url: 'https://yesno.wtf/api', title: 'yes/no reaction', license: 'open' };
88
+ }
89
+ // Default to cataas with text overlay when the query is a phrase (meme-like),
90
+ // else to cataas plain cat gif (mood default: cat is the internet's universal one).
91
+ if (String(query || '').trim().length > 3) {
92
+ return { source: 'cataas', url: `https://cataas.com/cat/gif/says/${encodeURIComponent(String(query).trim())}`, title: String(query).trim(), license: 'open' };
93
+ }
94
+ return { source: 'cataas', url: 'https://cataas.com/cat/gif', title: 'cat gif', license: 'open' };
95
+ }
96
+
97
+ /**
98
+ * searchGifs(query, opts) — resolve a keyless open GIF for a query.
99
+ * Returns { title, url, source, license, bytes? } — url of the actual GIF.
100
+ * Throws if every backend fails.
101
+ */
102
+ async function searchGifs(query) {
103
+ const b = backendFor(query);
104
+ if (b.source === 'yesno') {
105
+ const j = await fetchJson(b.url);
106
+ if (j && j.image) return { title: j.answer || b.title, url: j.image, source: 'yesno', license: 'open' };
107
+ throw new Error('yesno.wtf returned no image');
108
+ }
109
+ // cataas returns the binary directly; capture it if requested.
110
+ let buf;
111
+ try {
112
+ buf = await fetchBytes(b.url);
113
+ } catch (e) {
114
+ if (!b.fallbackUrl) throw e;
115
+ b.url = b.fallbackUrl;
116
+ buf = await fetchBytes(b.url);
117
+ }
118
+ const isGif = buf.slice(0, 3).toString() === 'GIF';
119
+ if (!isGif) throw new Error('backend did not return a GIF');
120
+ return { ...b, bytes: buf.length, valid: true, buffer: buf };
121
+ }
122
+
123
+ /**
124
+ * downloadGif(query, outPath) — fetch + verify + write to disk.
125
+ */
126
+ async function downloadGif(query, outPath) {
127
+ const g = await searchGifs(query);
128
+ let buf = g.buffer;
129
+ if (!buf) buf = await fetchBytes(g.url);
130
+ fs.writeFileSync(outPath, buf);
131
+ return { path: outPath, bytes: buf.length, url: g.url, source: g.source, valid: true };
132
+ }
133
+
134
+ module.exports = { searchGifs, downloadGif, backendFor, fetchJson, fetchBytes };
package/src/gitscan.js ADDED
@@ -0,0 +1,282 @@
1
+ 'use strict';
2
+
3
+ // gitscan — scan a git repository's ENTIRE commit history for leaked secrets
4
+ // (Gitleaks / TruffleHog parity). A secret committed months ago and since
5
+ // deleted is still found: it lives in history.
6
+ //
7
+ // const { scanGitHistory } = require('../src/gitscan');
8
+ // const { findings, stats } = await scanGitHistory('.', { since: '2024-01-01' });
9
+ //
10
+ // Strategy:
11
+ // 1. Enumerate every blob ever committed: `git rev-list --objects --all`
12
+ // (honoring --since / --max-commits passthroughs), deduped by blob sha.
13
+ // 2. Stream blob contents via `git cat-file --batch` (one long-lived process,
14
+ // NUL-byte check on the first 8KB skips binary blobs).
15
+ // 3. Run the existing secret.* regex rules over every line (same rules +
16
+ // filters as the working-tree scanner; matches are masked before they
17
+ // ever reach a report).
18
+ // 4. Attribute each finding to the earliest commit that introduced its blob
19
+ // (`git log --reverse -- <path>`, --find-object fallback).
20
+
21
+ const { spawn, execFile } = require('child_process');
22
+ const { matchAll } = require('./rules');
23
+
24
+ const MAX_BLOB_BYTES = 8 * 1024 * 1024; // bigger blobs are scanned but not buffered whole
25
+ const MAX_BLOBS_DEFAULT = 20000;
26
+
27
+ function runGit(dir, args, maxBuffer) {
28
+ return new Promise((resolve, reject) => {
29
+ execFile('git', args, {
30
+ cwd: dir,
31
+ maxBuffer: maxBuffer || 64 * 1024 * 1024,
32
+ windowsHide: true,
33
+ timeout: 300000,
34
+ }, (err, stdout, stderr) => {
35
+ if (err) {
36
+ const e = new Error((stderr || '').trim() || err.message);
37
+ e.code = err.code; // ENOENT = git missing, 128 = git itself failed
38
+ reject(e);
39
+ } else {
40
+ resolve(stdout);
41
+ }
42
+ });
43
+ });
44
+ }
45
+
46
+ // Earliest commit that introduced the blob: first line of `git log --reverse`
47
+ // for its path (oldest first). Falls back to --find-object=<sha> when the
48
+ // path-based query comes up empty.
49
+ async function earliestCommit(dir, path, sha) {
50
+ try {
51
+ const out = await runGit(dir, ['log', '--all', '--format=%H', '--reverse', '--', path]);
52
+ const first = out.split('\n').map((s) => s.trim()).find((s) => s.length > 0);
53
+ if (first) return first;
54
+ } catch { /* fall through to --find-object */ }
55
+ try {
56
+ const out = await runGit(dir, ['log', '--all', '--format=%H', '--reverse', `--find-object=${sha}`]);
57
+ const first = out.split('\n').map((s) => s.trim()).find((s) => s.length > 0);
58
+ return first || null;
59
+ } catch {
60
+ return null;
61
+ }
62
+ }
63
+
64
+ // Mask a secret exactly like src/scanner.js's redactSnippet: first4****last2.
65
+ // Never echo a full secret into a report.
66
+ function maskMatch(match) {
67
+ if (!match) return '';
68
+ if (match.length < 8) return '****';
69
+ return match.slice(0, 4) + '****' + match.slice(-2);
70
+ }
71
+
72
+ // Run the secret rules over one blob's content.
73
+ function scanContent(content, blob, rules) {
74
+ const findings = [];
75
+ const nul = content.indexOf(0);
76
+ if (nul !== -1 && nul < 8192) return findings; // binary blob — skip
77
+ const text = content.toString('utf8');
78
+ const lines = text.split(/\r?\n/);
79
+ for (let i = 0; i < lines.length; i++) {
80
+ const line = lines[i];
81
+ if (line.length > 4000) continue; // minified blob line — skip
82
+ for (const rule of rules) {
83
+ for (const hit of matchAll(rule.re, line)) {
84
+ if (rule.filter && !rule.filter(line, hit)) continue;
85
+ findings.push({
86
+ ruleId: rule.id,
87
+ title: rule.title,
88
+ severity: rule.severity || 'critical',
89
+ path: blob.path,
90
+ blobSha: blob.sha,
91
+ line: i + 1,
92
+ column: hit.index + 1,
93
+ match: maskMatch(hit.match),
94
+ });
95
+ }
96
+ }
97
+ }
98
+ return findings;
99
+ }
100
+
101
+ // Stream every blob through `git cat-file --batch`: write "<sha>\n", read
102
+ // "<sha> blob <size>\n<content>\n". One request in flight at a time.
103
+ function forEachBlobContent(dir, blobs, fn) {
104
+ return new Promise((resolve, reject) => {
105
+ if (blobs.length === 0) return resolve();
106
+ const child = spawn('git', ['cat-file', '--batch'], {
107
+ cwd: dir,
108
+ stdio: ['pipe', 'pipe', 'pipe'],
109
+ windowsHide: true,
110
+ });
111
+ let stderr = '';
112
+ child.stderr.on('data', (d) => { stderr += d; });
113
+
114
+ let buf = Buffer.alloc(0);
115
+ let phase = 'header'; // 'header' | 'content' | 'skip'
116
+ let curSize = 0;
117
+ let skipRemaining = 0;
118
+ let idx = 0;
119
+ let current = null;
120
+ let done = false;
121
+ let scanErr = null;
122
+
123
+ const timer = setTimeout(() => {
124
+ done = true;
125
+ child.kill();
126
+ reject(new Error('git cat-file timed out'));
127
+ }, 300000);
128
+
129
+ const requestNext = () => {
130
+ if (done) return;
131
+ current = blobs[idx++];
132
+ if (!current) {
133
+ child.stdin.end();
134
+ return;
135
+ }
136
+ child.stdin.write(current.sha + '\n');
137
+ };
138
+ requestNext();
139
+
140
+ child.stdout.on('data', (chunk) => {
141
+ if (done) return;
142
+ buf = buf.length === 0 ? chunk : Buffer.concat([buf, chunk]);
143
+ while (true) {
144
+ if (phase === 'header') {
145
+ const nl = buf.indexOf(10);
146
+ if (nl === -1) break;
147
+ const header = buf.slice(0, nl).toString('utf8');
148
+ buf = buf.slice(nl + 1);
149
+ const parts = header.split(' ');
150
+ if (parts.length === 3 && parts[1] === 'blob') {
151
+ curSize = parseInt(parts[2], 10) || 0;
152
+ phase = curSize > MAX_BLOB_BYTES ? 'skip' : 'content';
153
+ skipRemaining = curSize;
154
+ } else {
155
+ // "<sha> missing" or a non-blob object — skip and move on.
156
+ current = null;
157
+ requestNext();
158
+ }
159
+ } else if (phase === 'content') {
160
+ if (buf.length >= curSize + 1) {
161
+ const content = buf.slice(0, curSize);
162
+ buf = buf.slice(curSize + 1); // trailing newline after content
163
+ phase = 'header';
164
+ if (current) {
165
+ const b = current;
166
+ current = null;
167
+ try { fn(b, content); } catch (err) { if (!scanErr) scanErr = err; }
168
+ }
169
+ requestNext();
170
+ } else {
171
+ break;
172
+ }
173
+ } else {
174
+ // 'skip' — oversized blob: consume and discard without buffering.
175
+ if (buf.length >= skipRemaining + 1) {
176
+ buf = buf.slice(skipRemaining + 1);
177
+ phase = 'header';
178
+ current = null;
179
+ requestNext();
180
+ } else {
181
+ skipRemaining -= buf.length;
182
+ buf = Buffer.alloc(0);
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ });
188
+
189
+ child.on('error', (err) => {
190
+ clearTimeout(timer);
191
+ if (!done) {
192
+ done = true;
193
+ reject(err);
194
+ }
195
+ });
196
+ child.on('close', (code) => {
197
+ clearTimeout(timer);
198
+ if (done) return;
199
+ done = true;
200
+ if (scanErr) reject(scanErr);
201
+ else if (code !== 0) reject(new Error(`git cat-file failed (${code}): ${stderr.trim()}`));
202
+ else resolve();
203
+ });
204
+ });
205
+ }
206
+
207
+ async function scanGitHistory(dir, opts) {
208
+ opts = opts || {};
209
+ const t0 = Date.now();
210
+ const maxBlobs = Math.max(1, parseInt(opts.maxBlobs, 10) || MAX_BLOBS_DEFAULT);
211
+
212
+ const revArgs = ['rev-list', '--objects', '--all'];
213
+ if (opts.since) revArgs.push(`--since=${opts.since}`);
214
+ if (opts.maxCommits) revArgs.push(`--max-count=${Math.max(1, parseInt(opts.maxCommits, 10) || 1)}`);
215
+
216
+ let out;
217
+ try {
218
+ out = await runGit(dir, revArgs, 128 * 1024 * 1024);
219
+ } catch {
220
+ const e = new Error(`not a git repository: ${dir}`);
221
+ e.code = 'NOT_A_REPO';
222
+ throw e;
223
+ }
224
+
225
+ // Parse "<blobSha> <path>" lines; commit/tree lines have no path (skip).
226
+ const blobs = [];
227
+ const seen = new Set();
228
+ for (const line of out.split('\n')) {
229
+ const sp = line.indexOf(' ');
230
+ if (sp === -1) continue;
231
+ const sha = line.slice(0, sp);
232
+ const p = line.slice(sp + 1).trim();
233
+ if (!/^[0-9a-f]{40}$/.test(sha) || !p || seen.has(sha)) continue;
234
+ seen.add(sha);
235
+ blobs.push({ sha, path: p });
236
+ if (blobs.length >= maxBlobs) break;
237
+ }
238
+
239
+ // Commit count for stats (honors --since so the numbers stay consistent).
240
+ let commits = 0;
241
+ try {
242
+ const countArgs = ['rev-list', '--all', '--count'];
243
+ if (opts.since) countArgs.push(`--since=${opts.since}`);
244
+ commits = parseInt((await runGit(dir, countArgs)).trim(), 10) || 0;
245
+ } catch { /* best-effort */ }
246
+
247
+ const rules = require('./rules');
248
+ const secretRules = rules.secretRules.filter((r) => r.re);
249
+
250
+ const findings = [];
251
+ let scanned = 0;
252
+ await forEachBlobContent(dir, blobs, (blob, content) => {
253
+ scanned++;
254
+ for (const f of scanContent(content, blob, secretRules)) findings.push(f);
255
+ });
256
+
257
+ // Attribution: earliest commit per path (only runs for blobs with findings).
258
+ const commitCache = new Map();
259
+ for (const f of findings) {
260
+ if (!commitCache.has(f.path)) {
261
+ commitCache.set(f.path, await earliestCommit(dir, f.path, f.blobSha));
262
+ }
263
+ f.commit = commitCache.get(f.path);
264
+ }
265
+
266
+ // Dedupe identical hits (same rule, path, line, match) across history.
267
+ const unique = [];
268
+ const keys = new Set();
269
+ for (const f of findings) {
270
+ const k = `${f.ruleId}:${f.path}:${f.line}:${f.match}`;
271
+ if (keys.has(k)) continue;
272
+ keys.add(k);
273
+ unique.push(f);
274
+ }
275
+
276
+ return {
277
+ findings: unique,
278
+ stats: { blobs: scanned, commits, durationMs: Date.now() - t0 },
279
+ };
280
+ }
281
+
282
+ module.exports = { scanGitHistory, maskMatch };