@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
@@ -0,0 +1,477 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * src/skill-scan.js — malicious skill / plugin / instruction-file scanner.
5
+ *
6
+ * Skills are the new supply chain. A SKILL.md, a CLAUDE.md, an AGENTS.md, a
7
+ * Cursor rule, a Claude plugin manifest or a marketplace entry is text that
8
+ * gets injected into an agent's context with high trust. An attacker who can
9
+ * land one line in that text owns the agent's behavior without touching code.
10
+ *
11
+ * This scanner reads those files before the agent does and flags:
12
+ *
13
+ * - prompt injection and role hijacking
14
+ * - invisible Unicode / bidi smuggling
15
+ * - data-exfiltration instructions (send secrets/webhooks, base64 .env)
16
+ * - credential-store access (~/.ssh, .aws, .env, browser cookies)
17
+ * - destructive commands (rm -rf /, del C:\, diskpart, shadow copies)
18
+ * - remote code loaders (curl|sh, iwr|iex, powershell -enc)
19
+ * - obfuscated payloads (base64 + eval, fromCharCode, hex blobs)
20
+ * - excessive / self-granted permissions and security-disabling text
21
+ * - self-modification of the agent's own instructions
22
+ * - malicious / typosquatted / unpinned packages named in install commands
23
+ * - secrets committed inside skill text
24
+ * - dangerous embedded MCP server definitions (sh, curl|sh, unpinned npx)
25
+ *
26
+ * 100% local. Zero network. Zero dependencies.
27
+ */
28
+
29
+ const fs = require('fs');
30
+ const path = require('path');
31
+ const { scanForLeaks } = require('./action-guard');
32
+ const { checkPackage } = require('./firewall');
33
+ const { scanTextForInjection, auditServer } = require('./mcp-audit');
34
+ const { matchesAny } = require('./agent-policy');
35
+
36
+ const SKIP_DIRS = new Set([
37
+ 'node_modules', '.git', '.hg', '.svn', 'dist', 'build', 'out', 'coverage',
38
+ '.next', '.nuxt', '.turbo', '.cache', 'vendor', '__pycache__', '.venv', 'venv',
39
+ ]);
40
+ const MAX_FILE_BYTES = 1024 * 1024;
41
+ const MAX_FILES = 4000;
42
+
43
+ const SEVERITY_WEIGHT = { critical: 25, high: 10, medium: 4, low: 1 };
44
+ const SEVERITY_ORDER = { critical: 0, high: 1, medium: 2, low: 3 };
45
+
46
+ function normalize(p) {
47
+ return String(p).replace(/\\/g, '/');
48
+ }
49
+
50
+ function lineOf(text, index) {
51
+ let line = 1;
52
+ for (let i = 0; i < index && i < text.length; i++) if (text.charCodeAt(i) === 10) line++;
53
+ return line;
54
+ }
55
+
56
+ function snippetAt(text, index, len = 120) {
57
+ const start = Math.max(0, index - 20);
58
+ const end = Math.min(text.length, index + len);
59
+ return text.slice(start, end).replace(/\s+/g, ' ').trim();
60
+ }
61
+
62
+ function isSkillFileName(rel, base) {
63
+ const p = normalize(rel);
64
+ const b = base.toLowerCase();
65
+ if (b === 'skill.md' || b === 'skills.md') return true;
66
+ if (['agents.md', 'claude.md', '.cursorrules', '.windsurfrules', '.clinerules'].includes(b)) return true;
67
+ if (b === 'copilot-instructions.md') return true;
68
+ if (b === 'plugin.json' || b === 'claude-plugin.json' || b === 'marketplace.json') return true;
69
+ if (/(^|\/)\.claude-plugin\//.test(p)) return true;
70
+ if (/(^|\/)\.claude\/(agents|commands|skills)\/.*\.(md|json)$/i.test(p)) return true;
71
+ if (/(^|\/)\.cursor\/rules\/.*\.(md|mdc)$/i.test(p)) return true;
72
+ if (/(^|\/)\.github\/instructions\/.*\.md$/i.test(p)) return true;
73
+ if (/(^|\/)skills?\/[^/]+\/.*\.(md|json|ya?ml)$/i.test(p)) return true;
74
+ if (/\.(skill|prompt|agent|mdc)$/i.test(b)) return true;
75
+ return false;
76
+ }
77
+
78
+ function loadIgnorePaths(root) {
79
+ try {
80
+ const config = JSON.parse(fs.readFileSync(path.join(root, '.vibeguardrc.json'), 'utf8'));
81
+ return Array.isArray(config.ignorePaths) ? config.ignorePaths : [];
82
+ } catch {
83
+ return [];
84
+ }
85
+ }
86
+
87
+ function collectSkillFiles(root, opts = {}) {
88
+ const files = [];
89
+ const seen = new Set();
90
+ const explicit = Array.isArray(opts.paths) ? opts.paths : [];
91
+ const maxDepth = Number(opts.maxDepth || 12);
92
+ const ignorePaths = opts.ignorePaths || loadIgnorePaths(root);
93
+
94
+ function push(file) {
95
+ const resolved = path.resolve(file);
96
+ if (seen.has(resolved)) return;
97
+ let stat;
98
+ try { stat = fs.statSync(resolved); } catch { return; }
99
+ if (!stat.isFile()) return;
100
+ if (stat.size > MAX_FILE_BYTES) return;
101
+ seen.add(resolved);
102
+ files.push(resolved);
103
+ }
104
+
105
+ function walk(dir, depth) {
106
+ if (depth > maxDepth || files.length >= MAX_FILES) return;
107
+ let entries;
108
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
109
+ for (const entry of entries) {
110
+ if (files.length >= MAX_FILES) return;
111
+ const full = path.join(dir, entry.name);
112
+ if (entry.isSymbolicLink()) continue;
113
+ if (entry.isDirectory()) {
114
+ if (SKIP_DIRS.has(entry.name)) continue;
115
+ walk(full, depth + 1);
116
+ continue;
117
+ }
118
+ const rel = path.relative(root, full);
119
+ if (!entry.isDirectory() && ignorePaths.length > 0 && matchesAny(normalize(rel), ignorePaths)) continue;
120
+ if (isSkillFileName(rel, entry.name)) push(full);
121
+ }
122
+ }
123
+
124
+ for (const item of explicit) {
125
+ const full = path.resolve(root, item);
126
+ let stat;
127
+ try { stat = fs.statSync(full); } catch { continue; }
128
+ if (stat.isDirectory()) {
129
+ if (opts.all) {
130
+ // Explicit directory with --all: scan every text-ish file in it.
131
+ (function walkAll(dir, depth) {
132
+ if (depth > maxDepth || files.length >= MAX_FILES) return;
133
+ let entries;
134
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
135
+ for (const entry of entries) {
136
+ const child = path.join(dir, entry.name);
137
+ if (entry.isSymbolicLink()) continue;
138
+ if (entry.isDirectory()) {
139
+ if (SKIP_DIRS.has(entry.name)) continue;
140
+ walkAll(child, depth + 1);
141
+ } else if (/\.(md|mdc|json|ya?ml|txt|sh|ps1|py|js|ts)$/i.test(entry.name)) {
142
+ push(child);
143
+ }
144
+ }
145
+ })(full, 0);
146
+ } else {
147
+ walk(full, 0);
148
+ }
149
+ } else {
150
+ push(full);
151
+ }
152
+ }
153
+
154
+ if (!explicit.length) walk(root, 0);
155
+
156
+ return files;
157
+ }
158
+
159
+ // ─── Rules ──────────────────────────────────────────────────────────────────
160
+
161
+ const RULES = [
162
+ {
163
+ id: 'skill.prompt-injection',
164
+ severity: 'critical',
165
+ test: (t) => {
166
+ const hits = scanTextForInjection(t);
167
+ return hits.length ? { at: 0, detail: hits.join(', ') } : null;
168
+ },
169
+ message: (d) => `Prompt injection in agent-facing text (${d}) — the skill can hijack the agent's instructions.`,
170
+ fix: 'Remove the injected instruction. Skills must describe a capability, never override the agent system prompt.',
171
+ },
172
+ {
173
+ id: 'skill.hidden-unicode',
174
+ severity: 'high',
175
+ test: (t) => {
176
+ const m = /[\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF\u00AD]/g;
177
+ const hits = [];
178
+ let match;
179
+ while ((match = m.exec(t)) !== null) hits.push(match.index);
180
+ return hits.length ? { at: hits[0], detail: `${hits.length} invisible/control character(s)` } : null;
181
+ },
182
+ message: (d) => `Hidden Unicode / bidi control characters in skill text (${d}) — a Trojan-Source smuggling technique.`,
183
+ fix: 'Strip invisible characters and re-review the text in a raw editor.',
184
+ },
185
+ {
186
+ id: 'skill.exfil-instruction',
187
+ severity: 'critical',
188
+ test: (t) => {
189
+ const patterns = [
190
+ /(?:send|post|upload|transmit|exfiltrate|forward|webhook|curl|invoke-webrequest|iwr)[^\n]{0,140}(?:https?:\/\/|webhook|requestbin|pipedream|ngrok|discord\.com\/api|api\.telegram\.org)/i,
191
+ /(?:base64|btoa|atob|encode)[^\n]{0,100}(?:\.env|secret|token|credential|password|api[_-]?key)/i,
192
+ /(?:collect|gather|read|dump|extract)[^\n]{0,100}(?:\.env|\.ssh|\.aws|id_rsa|credentials|browser\s+cookies|cookies\.sqlite)[^\n]{0,140}(?:send|post|upload|https?:\/\/)/i,
193
+ /!\[[^\]]*\]\(\s*https?:\/\/[^)]*(?:data|secret|token|env)=/i,
194
+ ];
195
+ for (const re of patterns) {
196
+ const m = re.exec(t);
197
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
198
+ }
199
+ return null;
200
+ },
201
+ message: () => 'Skill instructs the agent to gather sensitive data and send it out — exfiltration text.',
202
+ fix: 'Remove the exfiltration instruction. A skill should never ask the agent to transmit credentials or collected local data.',
203
+ },
204
+ {
205
+ id: 'skill.credential-access',
206
+ severity: 'high',
207
+ test: (t) => {
208
+ const patterns = [
209
+ /(?:~\/\.ssh|\/\.ssh\/|id_rsa|id_ed25519|\.aws\/credentials|\.config\/gh|\.npmrc|\.netrc|keychain|credential\s+manager|cmdkey|security\s+find-(?:generic|internet)-password)/i,
210
+ /(?:read|open|cat|type|get-content|dump|print|show|expose)[^\n]{0,80}(?:\.env|environment\s+variables?|process\.env)/i,
211
+ ];
212
+ for (const re of patterns) {
213
+ const m = re.exec(t);
214
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
215
+ }
216
+ return null;
217
+ },
218
+ message: () => 'Skill instructs the agent to read credential stores or dump environment secrets.',
219
+ fix: 'Remove the credential-access instruction. Skills must not ask for secrets.',
220
+ },
221
+ {
222
+ id: 'skill.destructive-command',
223
+ severity: 'critical',
224
+ test: (t) => {
225
+ const patterns = [
226
+ /\brm\s+-rf\s+(?:\/|~|\$HOME|C:\\|\*)/i,
227
+ /\b(?:del|erase)\s+\/[fsq][^\n]{0,40}[A-Za-z]:\\/i,
228
+ /\b(?:format|diskpart|mkfs(?:\.\w+)?|dd\s+if=)/i,
229
+ /\bRemove-Item\b[^\n]{0,80}-Recurse[^\n]{0,40}-Force/i,
230
+ /\b(?:vssadmin\s+delete\s+shadows|cipher\s+\/w|bcdedit|shutdown\s+\/[rs]|reg\s+delete\s+HKLM)/i,
231
+ /:\s*\(\s*\)\s*\{\s*:\s*\|\s*:\s*&\s*\}\s*;/,
232
+ ];
233
+ for (const re of patterns) {
234
+ const m = re.exec(t);
235
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
236
+ }
237
+ return null;
238
+ },
239
+ message: () => 'Skill contains a destructive command (disk wipe, shadow-copy deletion, recursive delete).',
240
+ fix: 'Remove the destructive command. A skill should not delete system or user data.',
241
+ },
242
+ {
243
+ id: 'skill.remote-code-execution',
244
+ severity: 'critical',
245
+ test: (t) => {
246
+ const patterns = [
247
+ /(?:curl|wget)\b[^\n|]{0,160}\|\s*(?:sudo\s+)?(?:sh|bash|zsh|python|node)\b/i,
248
+ /\b(?:iwr|invoke-webrequest)\b[^\n]{0,160}\|\s*(?:iex|invoke-expression)/i,
249
+ /\b(?:iex|invoke-expression)\b[^\n]{0,120}(?:downloadstring|invoke-webrequest|iwr|http)/i,
250
+ /\bpowershell(?:\.exe)?\b[^\n]{0,80}-(?:enc|encodedcommand)\b/i,
251
+ /\bnode\s+-e\s+["'][^"']{0,40}https?:/i,
252
+ /\b(?:bash|sh)\s+<\(\s*(?:curl|wget)/i,
253
+ ];
254
+ for (const re of patterns) {
255
+ const m = re.exec(t);
256
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
257
+ }
258
+ return null;
259
+ },
260
+ message: () => 'Skill pipes remote content into an interpreter (curl|sh / iwr|iex / powershell -enc) — remote code execution.',
261
+ fix: 'Pin and vendor the code. Never execute a downloaded script as part of a skill.',
262
+ },
263
+ {
264
+ id: 'skill.obfuscated-payload',
265
+ severity: 'high',
266
+ test: (t) => {
267
+ const longB64 = /[A-Za-z0-9+/]{120,}={0,2}/.exec(t);
268
+ const evasive = /\b(?:eval|Function\s*\(|atob\s*\(|fromCharCode|unescape\s*\(|Buffer\.from\s*\([^)]*base64)/i.exec(t);
269
+ if (longB64 && evasive) return { at: longB64.index, detail: 'encoded blob + dynamic execution' };
270
+ const hexBlob = /(?:\\x[0-9a-f]{2}){12,}/i.exec(t);
271
+ if (hexBlob) return { at: hexBlob.index, detail: 'hex-encoded payload' };
272
+ return null;
273
+ },
274
+ message: () => 'Skill contains an obfuscated payload (encoded blob combined with eval/decode).',
275
+ fix: 'Decode the payload and replace it with readable instructions. Obfuscation has no place in a skill.',
276
+ },
277
+ {
278
+ id: 'skill.excessive-permissions',
279
+ severity: 'high',
280
+ test: (t) => {
281
+ const patterns = [
282
+ /\b(?:bypassPermissions|dangerouslySkipPermissions|dangerouslyDisableSandbox|autoApprove|alwaysAllow|full[- ]access|root\s+access|admin\s+access)\b/i,
283
+ /"allowedTools"\s*:\s*\[\s*"\*"\s*\]/i,
284
+ /(?:ignore|disable|bypass|turn\s+off|remove)[^\n]{0,60}(?:safety|guardrail|sandbox|approval|confirmation|security\s+check)/i,
285
+ /(?:without|no)\s+(?:asking|confirmation|approval|permission)[^\n]{0,40}/i,
286
+ ];
287
+ for (const re of patterns) {
288
+ const m = re.exec(t);
289
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
290
+ }
291
+ return null;
292
+ },
293
+ message: () => 'Skill requests or grants excessive permissions / tells the agent to skip safety and confirmation.',
294
+ fix: 'Scope permissions to the specific tools the skill needs. Never ship a wildcard allow or a safety bypass.',
295
+ },
296
+ {
297
+ id: 'skill.self-modification',
298
+ severity: 'high',
299
+ test: (t) => {
300
+ const m = /(?:edit|write|modify|append\s+to|overwrite)[^\n]{0,80}(?:AGENTS\.md|CLAUDE\.md|\.cursorrules|SKILL\.md|skill\.md|\.claude|\.cursor)[^\n]{0,40}/i.exec(t);
301
+ if (m) return { at: m.index, detail: snippetAt(t, m.index) };
302
+ const d = /(?:disable|uninstall|remove|kill)[^\n]{0,60}(?:vibeguard|firewall|guard|monitor|audit\s+log)/i.exec(t);
303
+ if (d) return { at: d.index, detail: snippetAt(t, d.index) };
304
+ return null;
305
+ },
306
+ message: () => 'Skill tells the agent to modify its own instructions or disable the security layer — persistence / evasion.',
307
+ fix: 'Remove the self-modification instruction. Skills must not rewrite agent instructions or disable monitoring.',
308
+ },
309
+ {
310
+ id: 'skill.secret-in-text',
311
+ severity: 'critical',
312
+ test: (t) => {
313
+ const leaks = scanForLeaks(t);
314
+ if (!leaks.secrets.length) return null;
315
+ return { at: 0, detail: leaks.secrets.join(', ') };
316
+ },
317
+ message: (d) => `Hardcoded credential in skill text (${d}) — every agent and every git reader gets it.`,
318
+ fix: 'Remove the credential, rotate it, and use an environment reference.',
319
+ redact: true,
320
+ },
321
+ {
322
+ id: 'skill.package-risk',
323
+ severity: 'high',
324
+ test: (t) => {
325
+ const commands = [
326
+ /\b(?:npx|bunx|pnpm\s+dlx)\s+(?:-y\s+|--yes\s+)?([@\w./-]+)/gi,
327
+ /\b(?:npm|pnpm|yarn|bun)\s+(?:i|install|add)\s+(?:--save\s+)?([@\w./-]+)/gi,
328
+ /\bpip3?\s+install\s+([\w.-]+)/gi,
329
+ /\buvx\s+([\w.-]+)/gi,
330
+ ];
331
+ for (const re of commands) {
332
+ let m;
333
+ while ((m = re.exec(t)) !== null) {
334
+ const spec = m[1];
335
+ const name = spec.startsWith('@') ? spec.split('@').slice(0, 2).join('@') : spec.split('@')[0];
336
+ const result = checkPackage(name);
337
+ const bad = result.risks.find((r) => r.action === 'block') || result.risks.find((r) => r.severity === 'high');
338
+ const unpinned = !spec.includes('@') || (spec.startsWith('@') && !spec.slice(1).includes('@'));
339
+ if (bad) return { at: m.index, detail: `${name}: ${bad.message}` };
340
+ if (unpinned) return { at: m.index, detail: `${name} is unpinned` };
341
+ }
342
+ }
343
+ return null;
344
+ },
345
+ message: (d) => `Skill installs a risky or unpinned package (${d}).`,
346
+ fix: 'Pin the package version and verify the package before the skill installs it.',
347
+ severityFor: (d) => (/malicious|typosquat/i.test(d) ? 'critical' : 'medium'),
348
+ },
349
+ ];
350
+
351
+ // ─── Embedded MCP definitions in skill/plugin files ─────────────────────────
352
+
353
+ function scanEmbeddedMcp(text, rel) {
354
+ const findings = [];
355
+ let json;
356
+ try { json = JSON.parse(text); } catch { return findings; }
357
+ const servers = (json && (json.mcpServers || json.servers || (json.mcp && json.mcp.servers))) || null;
358
+ if (!servers || typeof servers !== 'object') return findings;
359
+ for (const [name, cfg] of Object.entries(servers)) {
360
+ if (!cfg || typeof cfg !== 'object') continue;
361
+ for (const f of auditServer(name, cfg)) {
362
+ findings.push({
363
+ ruleId: `skill.${f.id.replace(/^mcp\./, 'mcp-')}`,
364
+ severity: f.severity,
365
+ confidence: 'high',
366
+ file: rel,
367
+ line: 1,
368
+ snippet: `${name}: ${f.message.slice(0, 100)}`,
369
+ message: f.message,
370
+ fix: f.fix,
371
+ category: 'mcp',
372
+ });
373
+ }
374
+ }
375
+ return findings;
376
+ }
377
+
378
+ // ─── Main scan ──────────────────────────────────────────────────────────────
379
+
380
+ function scanSkills(root, opts = {}) {
381
+ const projectRoot = path.resolve(root || process.cwd());
382
+ const files = collectSkillFiles(projectRoot, opts);
383
+ const findings = [];
384
+ const scanned = [];
385
+
386
+ for (const file of files) {
387
+ const rel = normalize(path.relative(projectRoot, file));
388
+ let text;
389
+ try { text = fs.readFileSync(file, 'utf8'); } catch { continue; }
390
+ scanned.push(rel);
391
+
392
+ for (const rule of RULES) {
393
+ let hit;
394
+ try { hit = rule.test(text); } catch { hit = null; }
395
+ if (!hit) continue;
396
+ let detail = hit.detail || '';
397
+ let snippet = snippetAt(text, hit.at || 0);
398
+ if (rule.redact) {
399
+ detail = detail;
400
+ snippet = '[redacted credential]';
401
+ }
402
+ const severity = rule.severityFor ? rule.severityFor(detail) : rule.severity;
403
+ findings.push({
404
+ ruleId: rule.id,
405
+ severity,
406
+ confidence: 'high',
407
+ file: rel,
408
+ line: lineOf(text, hit.at || 0),
409
+ snippet,
410
+ message: rule.message(detail),
411
+ fix: rule.fix,
412
+ category: 'skill',
413
+ owasp: ['ASI04', 'MCP04'],
414
+ });
415
+ }
416
+
417
+ if (/\.json$/i.test(file)) {
418
+ for (const f of scanEmbeddedMcp(text, rel)) findings.push(f);
419
+ }
420
+ }
421
+
422
+ const counts = { critical: 0, high: 0, medium: 0, low: 0 };
423
+ for (const f of findings) counts[f.severity] = (counts[f.severity] || 0) + 1;
424
+
425
+ let score = 0;
426
+ for (const f of findings) score += SEVERITY_WEIGHT[f.severity] || 1;
427
+ const riskScore = Math.min(100, score);
428
+ const grade = riskScore === 0 ? 'A' : riskScore < 20 ? 'B' : riskScore < 40 ? 'C' : riskScore < 65 ? 'D' : 'F';
429
+
430
+ findings.sort((a, b) => (SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]) || a.file.localeCompare(b.file) || a.line - b.line);
431
+
432
+ return {
433
+ root: projectRoot,
434
+ scannedFiles: scanned.length,
435
+ files: scanned,
436
+ findings,
437
+ counts,
438
+ riskScore,
439
+ grade,
440
+ clean: findings.length === 0,
441
+ };
442
+ }
443
+
444
+ function renderSkillReport(result) {
445
+ const C = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
446
+ const lines = [
447
+ `${C.bold}VibeGuard Skill Scanner${C.reset}`,
448
+ `${C.dim}${'─'.repeat(64)}${C.reset}`,
449
+ ` Files scanned: ${result.scannedFiles}`,
450
+ ` Risk score: ${result.riskScore}/100 Grade: ${result.grade}`,
451
+ '',
452
+ ];
453
+ if (result.findings.length === 0) {
454
+ lines.push(` ${C.green}No malicious skill or plugin behavior found.${C.reset}`);
455
+ return lines.join('\n');
456
+ }
457
+ for (const f of result.findings) {
458
+ const color = f.severity === 'critical' ? C.red : f.severity === 'high' ? C.yellow : C.dim;
459
+ lines.push(` ${color}${C.bold}${f.severity.toUpperCase().padEnd(8)}${C.reset} [${f.ruleId}] ${f.file}:${f.line}`);
460
+ lines.push(` ${f.message}`);
461
+ if (f.snippet && f.snippet !== '[redacted credential]') lines.push(` ${C.dim}${f.snippet.slice(0, 140)}${C.reset}`);
462
+ lines.push(` ${C.green}fix:${C.reset} ${f.fix}`);
463
+ lines.push('');
464
+ }
465
+ const c = result.counts;
466
+ lines.push(`${C.bold}${c.critical} critical, ${c.high} high, ${c.medium} medium, ${c.low} low${C.reset}`);
467
+ return lines.join('\n');
468
+ }
469
+
470
+ module.exports = {
471
+ scanSkills,
472
+ collectSkillFiles,
473
+ isSkillFileName,
474
+ renderSkillReport,
475
+ RULES,
476
+ SEVERITY_WEIGHT,
477
+ };