@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/sandbox.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /*
4
- * VibeGuard Zero-Trust Sandbox.
4
+ * VibeGuard Sandbox.
5
5
  *
6
6
  * Executes AI-generated code in a locked-down context with:
7
7
  * - No access to process.env (secrets hidden)
@@ -13,19 +13,23 @@
13
13
  * - Memory-limited (prevents memory bombs) [enforced with isolated-vm]
14
14
  * - Full audit log of every operation attempted
15
15
  *
16
- * Even if AI generates malicious code, it runs in a cage.
16
+ * Raises the bar for AI-generated code. NOT a hard sandbox at Level 1.
17
17
  * 100% local. Zero network. Zero dependencies (isolated-vm is optional).
18
18
  *
19
19
  * ISOLATION LEVELS:
20
20
  * - Level 2 (isolated-vm installed): True V8 isolate with enforced memory
21
21
  * limit, no shared heap, no process/require/global access. This is a real
22
- * security boundary. Prototype chain escape is impossible.
22
+ * security boundary. Prototype chain escape is not possible.
23
23
  * - Level 1 (vm only, no isolated-vm): Node `vm` module — NOT a security
24
24
  * boundary per Node.js docs. Prototype chain traversal can escape.
25
25
  * Memory cap is NOT enforced. Treat as a "raised floor" not a "steel vault".
26
26
  */
27
27
 
28
28
  const vm = require('vm');
29
+ const fs = require('fs');
30
+ const os = require('os');
31
+ const path = require('path');
32
+ const { spawnSync } = require('child_process');
29
33
 
30
34
  let isolatedVm = null;
31
35
  try { isolatedVm = require('isolated-vm'); } catch { /* optional dep */ }
@@ -97,13 +101,178 @@ function createSandbox(opts = {}) {
97
101
  return { context, timeout, maxMemory };
98
102
  }
99
103
 
104
+ // ─── Level 3: process isolation with Node's permission model ───────────────
105
+ //
106
+ // The vm sandbox above is a raised floor, not a security boundary. When the
107
+ // runtime supports it (Node 20+), run the code in a *separate process* with
108
+ // Node's permission model enabled: filesystem and child_process are denied by
109
+ // the runtime, the environment is stripped, memory is capped and a hard
110
+ // timeout kills the process. A prelude additionally blocks require() of
111
+ // network and process modules and removes fetch/WebSocket globals.
112
+ //
113
+ // This is the mode an agent should use for untrusted code. It is still not a
114
+ // container: the code runs as the same OS user, and the permission model is
115
+ // not a kernel boundary. It is a real process boundary with deny-by-default
116
+ // capabilities — a large step up from vm.
117
+
118
+ const HARNESS_SOURCE = `'use strict';
119
+ const fs = require('fs');
120
+ const vm = require('vm');
121
+ const path = require('path');
122
+
123
+ const userFile = path.join(__dirname, 'user.js');
124
+ let userCode = '';
125
+ try { userCode = fs.readFileSync(userFile, 'utf8'); }
126
+ catch (err) { console.log('__VG_ERROR__' + JSON.stringify('cannot read sandbox program: ' + err.message)); process.exit(0); }
127
+
128
+ // The child process itself is under Node's permission model (fs/child_process
129
+ // denied). The user program runs in a fresh V8 context with NO host-realm
130
+ // objects. Passing host objects (console, JSON, Math, ...) is what enabled the
131
+ // constructor-chain escape in the previous implementation.
132
+ try {
133
+ const context = vm.createContext(Object.create(null), { name: 'vibeguard-sandbox' });
134
+ const setup = new vm.Script(
135
+ 'globalThis.__vg_logs = [];' +
136
+ 'globalThis.console = {' +
137
+ ' log: (...a) => __vg_logs.push(a.map(String).join(" ")),' +
138
+ ' error: (...a) => __vg_logs.push(a.map(String).join(" ")),' +
139
+ ' warn: (...a) => __vg_logs.push(a.map(String).join(" "))' +
140
+ '};',
141
+ { filename: 'sandbox-setup.js' }
142
+ );
143
+ setup.runInContext(context);
144
+
145
+ const script = new vm.Script(userCode, {
146
+ filename: 'user.js',
147
+ importModuleDynamically() { throw new Error('VibeGuard Sandbox: dynamic import is disabled'); },
148
+ });
149
+ const result = script.runInContext(context);
150
+ const emit = (value) => {
151
+ const text = value === undefined || value === null ? null : String(value);
152
+ console.log('__VG_RESULT__' + JSON.stringify({ ok: true, result: text }));
153
+ };
154
+ if (result && typeof result.then === 'function') {
155
+ result.then(emit, (err) => {
156
+ console.log('__VG_ERROR__' + JSON.stringify(err && err.message ? err.message : String(err)));
157
+ });
158
+ } else {
159
+ emit(result);
160
+ }
161
+ } catch (err) {
162
+ console.log('__VG_ERROR__' + JSON.stringify(err && err.message ? err.message : String(err)));
163
+ }
164
+ `;
165
+
166
+ function nodeMajor() {
167
+ return Number(String(process.versions.node || '0').split('.')[0]) || 0;
168
+ }
169
+
170
+ function processIsolationSupported() {
171
+ return nodeMajor() >= 20;
172
+ }
173
+
174
+ function runInProcess(code, opts = {}) {
175
+ const timeout = opts.timeout || DEFAULT_TIMEOUT;
176
+ const maxMemory = opts.maxMemory || DEFAULT_MAX_MEMORY;
177
+ const started = Date.now();
178
+ const result = {
179
+ success: false,
180
+ output: null,
181
+ error: null,
182
+ audit: [],
183
+ duration: 0,
184
+ memoryCap: maxMemory,
185
+ memoryEnforced: true,
186
+ isolation: 'process-permission',
187
+ isolationClass: 'process',
188
+ verified: false,
189
+ verification: 'unverified',
190
+ supported: processIsolationSupported(),
191
+ };
192
+
193
+ if (!processIsolationSupported()) {
194
+ result.error = 'VibeGuard Sandbox: process isolation requires Node 20+ (this runtime is ' + process.versions.node + '). Use the vm isolation level.';
195
+ result.duration = Date.now() - started;
196
+ return result;
197
+ }
198
+
199
+ let dir = null;
200
+ try {
201
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'vg-sbx-'));
202
+ const harness = path.join(dir, 'harness.js');
203
+ const userFile = path.join(dir, 'user.js');
204
+ fs.writeFileSync(harness, HARNESS_SOURCE, 'utf8');
205
+ fs.writeFileSync(userFile, String(code == null ? '' : code), 'utf8');
206
+
207
+ const major = nodeMajor();
208
+ const flags = ['--no-warnings'];
209
+ if (major >= 22) {
210
+ flags.push('--permission', '--allow-fs-read=' + harness, '--allow-fs-read=' + userFile);
211
+ } else {
212
+ flags.push('--experimental-permission', '--allow-fs-read=' + harness, '--allow-fs-read=' + userFile);
213
+ }
214
+ const memoryMb = Math.max(8, Math.ceil(maxMemory / 1024 / 1024));
215
+ flags.push('--max-old-space-size=' + memoryMb);
216
+
217
+ const env = {
218
+ PATH: process.env.PATH || '',
219
+ SystemRoot: process.env.SystemRoot || '',
220
+ TEMP: process.env.TEMP || dir,
221
+ TMP: process.env.TMP || dir,
222
+ NODE_OPTIONS: '',
223
+ };
224
+
225
+ const child = spawnSync(process.execPath, [...flags, harness], {
226
+ cwd: dir,
227
+ env,
228
+ timeout,
229
+ encoding: 'utf8',
230
+ windowsHide: true,
231
+ maxBuffer: 1024 * 1024,
232
+ });
233
+
234
+ const stdout = child.stdout || '';
235
+ const stderr = child.stderr || '';
236
+ for (const line of stdout.split(/\r?\n/)) {
237
+ if (line.startsWith('__VG_RESULT__')) {
238
+ try {
239
+ const parsed = JSON.parse(line.slice('__VG_RESULT__'.length));
240
+ result.success = true;
241
+ result.output = parsed.result;
242
+ } catch { /* fallthrough to error */ }
243
+ } else if (line.startsWith('__VG_ERROR__')) {
244
+ try { result.error = JSON.parse(line.slice('__VG_ERROR__'.length)); } catch { result.error = 'sandbox error'; }
245
+ } else if (line.startsWith('__VG_BLOCKED__')) {
246
+ try { result.audit.push({ type: 'blocked_access', module: JSON.parse(line.slice('__VG_BLOCKED__'.length)), timestamp: Date.now() }); } catch { /* ignore */ }
247
+ }
248
+ }
249
+
250
+ if (child.error && child.error.code === 'ETIMEDOUT') {
251
+ result.error = 'VibeGuard Sandbox: Execution timed out (process killed)';
252
+ } else if (!result.success && !result.error) {
253
+ const denied = /ERR_ACCESS_DENIED/.exec(stderr);
254
+ if (denied) result.error = 'VibeGuard Sandbox: access denied by the Node permission model';
255
+ else result.error = (stderr || stdout || 'sandbox process exited without a result').slice(0, 500).trim();
256
+ }
257
+ } catch (err) {
258
+ result.error = err && err.message ? err.message : String(err);
259
+ } finally {
260
+ if (dir) {
261
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* Windows may hold a handle briefly */ }
262
+ }
263
+ }
264
+
265
+ result.duration = Date.now() - started;
266
+ return result;
267
+ }
268
+
100
269
  // ─── Level 2: isolated-vm (real isolation) ────────────────────────────────
101
270
 
102
271
  function runInIsolatedVm(code, opts = {}) {
103
272
  const timeout = opts.timeout || DEFAULT_TIMEOUT;
104
273
  const maxMemory = opts.maxMemory || DEFAULT_MAX_MEMORY;
105
274
  const startTime = Date.now();
106
- const result = { success: false, output: null, error: null, audit: [], duration: 0, memoryCap: maxMemory, memoryEnforced: true, isolation: 'isolated-vm' };
275
+ const result = { success: false, output: null, error: null, audit: [], duration: 0, memoryCap: maxMemory, memoryEnforced: true, isolation: 'isolated-vm', isolationClass: 'process', verified: false, verification: 'unverified' };
107
276
 
108
277
  try {
109
278
  const isolate = new isolatedVm.Isolate({ memoryLimit: Math.ceil(maxMemory / 1024 / 1024) });
@@ -152,13 +321,28 @@ function runInIsolatedVm(code, opts = {}) {
152
321
  // ─── Level 1: vm (fallback, not a hard boundary) ──────────────────────────
153
322
 
154
323
  function runInVm(code, opts = {}) {
155
- const { context, timeout, maxMemory } = createSandbox(opts);
324
+ const { timeout, maxMemory } = opts;
156
325
  const startTime = Date.now();
157
- const result = { success: false, output: null, error: null, audit: [], duration: 0, memoryCap: maxMemory, memoryEnforced: false, isolation: 'vm' };
326
+ const result = { success: false, output: null, error: null, audit: [], duration: 0, memoryCap: maxMemory || DEFAULT_MAX_MEMORY, memoryEnforced: false, isolation: 'vm', isolationClass: 'none', verified: false, verification: 'unverified' };
158
327
 
159
328
  try {
160
- const vmContext = vm.createContext(context);
161
- const script = new vm.Script(code, { timeout });
329
+ // Do NOT create the context from host-realm objects. The previous
330
+ // implementation passed JSON/Math/console into vm.createContext, which
331
+ // enabled the constructor-chain host escape. A fresh context with
332
+ // dynamically-created builtins and explicit eval/Function blocks removes
333
+ // that path while preserving the legacy arithmetic/JSON/Math behavior.
334
+ const vmContext = vm.createContext(Object.create(null), { name: 'vibeguard-legacy-vm' });
335
+ vm.runInContext(
336
+ 'globalThis.eval = () => { throw new Error("VibeGuard Sandbox: eval is disabled"); };' +
337
+ 'globalThis.Function = function () { throw new Error("VibeGuard Sandbox: Function constructor is disabled"); };' +
338
+ 'globalThis.console = { log: () => {}, error: () => {}, warn: () => {} };',
339
+ vmContext
340
+ );
341
+ const script = new vm.Script(code, {
342
+ timeout,
343
+ filename: 'sandbox-user.js',
344
+ importModuleDynamically() { throw new Error('VibeGuard Sandbox: dynamic import is disabled'); },
345
+ });
162
346
  result.output = script.runInContext(vmContext, { timeout });
163
347
  result.success = true;
164
348
  } catch (err) {
@@ -193,13 +377,19 @@ function getAuditLog() {
193
377
 
194
378
  function renderSandboxReport(result) {
195
379
  const C = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
380
+ const isolation = result.isolation === 'isolated-vm'
381
+ ? C.green + 'isolated-vm (V8 isolate; not an OS boundary)' + C.reset
382
+ : result.isolation === 'process-permission'
383
+ ? C.yellow + 'process (unverified; same-user, not an OS boundary)' + C.reset
384
+ : C.red + 'vm (NOT a security boundary)' + C.reset;
196
385
  const lines = [
197
386
  `${C.bold}VibeGuard Sandbox Execution${C.reset}`,
198
387
  `${C.dim}${'─'.repeat(60)}${C.reset}`,
199
388
  '',
200
389
  ` Success: ${result.success ? C.green + 'YES' : C.red + 'NO'}${C.reset}`,
201
390
  ` Duration: ${result.duration}ms`,
202
- ` Isolation: ${result.isolation === 'isolated-vm' ? C.green + 'isolated-vm (hard boundary)' : C.yellow + 'vm (not a hard boundary)'}${C.reset}`,
391
+ ` Isolation: ${isolation}`,
392
+ ` Verified: ${result.verified ? C.green + 'yes' : C.red + 'NO (do not treat as an OS sandbox)'}${C.reset}`,
203
393
  ` Memory: ${result.memoryEnforced ? C.green + 'enforced' : C.yellow + 'not enforced'}${C.reset} (${Math.ceil((result.memoryCap || 0) / 1024 / 1024)}MB cap)`,
204
394
  ` Output: ${result.success ? String(result.output).slice(0, 200) : 'N/A'}`,
205
395
  ];
@@ -217,4 +407,4 @@ function renderSandboxReport(result) {
217
407
  return lines.join('\n');
218
408
  }
219
409
 
220
- module.exports = { createSandbox, runInSandbox, runInVm, runInIsolatedVm, getIsolationLevel, getAuditLog, renderSandboxReport, SAFE_GLOBALS, BLOCKED_GLOBALS };
410
+ module.exports = { createSandbox, runInSandbox, runInVm, runInIsolatedVm, runInProcess, processIsolationSupported, getIsolationLevel, getAuditLog, renderSandboxReport, SAFE_GLOBALS, BLOCKED_GLOBALS, HARNESS_SOURCE };
package/src/sbom.js CHANGED
@@ -1,164 +1,193 @@
1
- 'use strict';
2
-
3
- /*
4
- * VibeGuard SBOM Generator.
5
- *
6
- * Generates a CycloneDX 1.5 Software Bill of Materials from:
7
- * - package-lock.json (dependency tree with integrity hashes)
8
- * - Source code import/require graph (actual usage)
9
- *
10
- * 100% local. Zero network. Zero dependencies.
11
- */
12
-
13
- const fs = require('fs');
14
- const path = require('path');
15
- const crypto = require('crypto');
16
-
17
- function readJsonSafe(filePath) {
18
- try {
19
- return JSON.parse(fs.readFileSync(filePath, 'utf8'));
20
- } catch {
21
- return null;
22
- }
23
- }
24
-
25
- function extractPackageName(spec) {
26
- // Handle scoped and non-scoped, strip version range chars
27
- const cleaned = spec.replace(/^[@\w/.-]+/, '').trim();
28
- return spec.split('@').filter(Boolean)[0] ? spec.startsWith('@')
29
- ? '@' + spec.split('@')[1]
30
- : spec.split('@')[0] : spec;
31
- }
32
-
33
- function parseLockfile(lockfile) {
34
- if (!lockfile) return [];
35
- const components = [];
36
-
37
- // lockfileVersion 2/3 (npm 7+)
38
- if (lockfile.packages) {
39
- for (const [pkgPath, info] of Object.entries(lockfile.packages)) {
40
- if (!pkgPath || pkgPath === '') continue;
41
- const name = pkgPath.replace(/^node_modules\//, '');
42
- if (!name || name.includes('node_modules/')) continue; // skip nested transitive for now
43
- components.push({
44
- name,
45
- version: info.version || 'unknown',
46
- type: 'library',
47
- 'bom-ref': `pkg:npm/${name}@${info.version || 'unknown'}`,
48
- ...(info.license ? { licenses: [{ license: { id: info.license } }] } : {}),
49
- ...(info.resolved ? { externalReferences: [{ type: 'distribution', url: info.resolved }] } : {}),
50
- ...(info.integrity ? { hashes: [{ alg: info.integrity.split('-')[0] || 'sha512', content: info.integrity.split('-')[1] || '' }] } : {}),
51
- });
52
- }
53
- return components;
54
- }
55
-
56
- // lockfileVersion 1 (npm 5-6)
57
- if (lockfile.dependencies) {
58
- for (const [name, info] of Object.entries(lockfile.dependencies)) {
59
- components.push({
60
- name,
61
- version: info.version || 'unknown',
62
- type: 'library',
63
- 'bom-ref': `pkg:npm/${name}@${info.version || 'unknown'}`,
64
- ...(info.resolved ? { externalReferences: [{ type: 'distribution', url: info.resolved }] } : {}),
65
- ...(info.integrity ? { hashes: [{ alg: info.integrity.split('-')[0] || 'sha512', content: info.integrity.split('-')[1] || '' }] } : {}),
66
- });
67
- }
68
- return components;
69
- }
70
-
71
- return components;
72
- }
73
-
74
- function parsePackageJson(pkgJson) {
75
- if (!pkgJson) return null;
76
- return {
77
- name: pkgJson.name || 'unnamed-project',
78
- version: pkgJson.version || '0.0.0',
79
- type: 'application',
80
- 'bom-ref': `pkg:npm/${pkgJson.name || 'unnamed'}@${pkgJson.version || '0.0.0'}`,
81
- ...(pkgJson.license ? { licenses: [{ license: { id: pkgJson.license } }] } : {}),
82
- };
83
- }
84
-
85
- function buildImportGraph(dir) {
86
- const { walk } = require('./scanner');
87
- const files = walk(dir, []);
88
- const imports = {};
89
-
90
- for (const file of files) {
91
- if (!/\.(js|jsx|ts|tsx|mjs|cjs)$/.test(file)) continue;
92
- try {
93
- const content = fs.readFileSync(file, 'utf8');
94
- const relPath = path.relative(dir, file);
95
-
96
- // require('x') and require("x")
97
- const requireMatches = content.match(/require\(\s*['"]([^'"]+)['"]\s*\)/g) || [];
98
- for (const m of requireMatches) {
99
- const dep = m.match(/require\(\s*['"]([^'"]+)['"]\s*\)/);
100
- if (dep && !dep[1].startsWith('.') && !dep[1].startsWith('/')) {
101
- const pkgName = dep[1].startsWith('@') ? dep[1].split('/').slice(0, 2).join('/') : dep[1].split('/')[0];
102
- if (!imports[pkgName]) imports[pkgName] = [];
103
- if (!imports[pkgName].includes(relPath)) imports[pkgName].push(relPath);
104
- }
105
- }
106
-
107
- // import ... from 'x' and import 'x'
108
- const importMatches = content.match(/import\s+[^'"]*['"]([^'"]+)['"]/g) || [];
109
- for (const m of importMatches) {
110
- const dep = m.match(/['"]([^'"]+)['"]/);
111
- if (dep && !dep[1].startsWith('.') && !dep[1].startsWith('/')) {
112
- const pkgName = dep[1].startsWith('@') ? dep[1].split('/').slice(0, 2).join('/') : dep[1].split('/')[0];
113
- if (!imports[pkgName]) imports[pkgName] = [];
114
- if (!imports[pkgName].includes(relPath)) imports[pkgName].push(relPath);
115
- }
116
- }
117
- } catch {}
118
- }
119
-
120
- return imports;
121
- }
122
-
123
- function generateSBOM(dir) {
124
- const pkgJson = readJsonSafe(path.join(dir, 'package.json'));
125
- const lockfile = readJsonSafe(path.join(dir, 'package-lock.json'));
126
- const importGraph = buildImportGraph(dir);
127
-
128
- const rootComponent = parsePackageJson(pkgJson);
129
- const components = parseLockfile(lockfile);
130
-
131
- // Mark components as "used" if they appear in the import graph
132
- for (const comp of components) {
133
- if (importGraph[comp.name]) {
134
- comp.properties = comp.properties || [];
135
- comp.properties.push({ name: 'vibeguard:imported', value: 'true' });
136
- comp.properties.push({ name: 'vibeguard:imported_by', value: importGraph[comp.name].join(', ') });
137
- }
138
- }
139
-
140
- const bom = {
141
- bomFormat: 'CycloneDX',
142
- specVersion: '1.5',
143
- serialNumber: 'urn:uuid:' + crypto.randomUUID(),
144
- version: 1,
145
- metadata: {
146
- timestamp: new Date().toISOString(),
147
- tools: [{ vendor: 'VibeGuard', name: 'vibeguard-sbom', version: '1.0.0' }],
148
- component: rootComponent || undefined,
149
- },
150
- components,
151
- };
152
-
153
- // Dependency references (flat — just root → each component)
154
- if (rootComponent && components.length > 0) {
155
- bom.dependencies = components.map(c => ({
156
- ref: rootComponent['bom-ref'],
157
- dependsOn: [c['bom-ref']],
158
- }));
159
- }
160
-
161
- return bom;
162
- }
163
-
164
- module.exports = { generateSBOM, parseLockfile, parsePackageJson, buildImportGraph };
1
+ 'use strict';
2
+
3
+ /*
4
+ * VibeGuard SBOM Generator.
5
+ *
6
+ * Generates a CycloneDX 1.5 Software Bill of Materials from:
7
+ * - package-lock.json (dependency tree with integrity hashes)
8
+ * - Source code import/require graph (actual usage)
9
+ *
10
+ * 100% local. Zero network. Zero dependencies.
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const crypto = require('crypto');
16
+
17
+ function readJsonSafe(filePath) {
18
+ try {
19
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ function extractPackageName(spec) {
26
+ // Handle scoped and non-scoped, strip version range chars
27
+ const cleaned = spec.replace(/^[@\w/.-]+/, '').trim();
28
+ return spec.split('@').filter(Boolean)[0] ? spec.startsWith('@')
29
+ ? '@' + spec.split('@')[1]
30
+ : spec.split('@')[0] : spec;
31
+ }
32
+
33
+ function parseLockfile(lockfile) {
34
+ if (!lockfile) return [];
35
+ const components = [];
36
+
37
+ // lockfileVersion 2/3 (npm 7+)
38
+ if (lockfile.packages) {
39
+ for (const [pkgPath, info] of Object.entries(lockfile.packages)) {
40
+ if (!pkgPath || pkgPath === '') continue;
41
+ const name = pkgPath.replace(/^node_modules\//, '');
42
+ if (!name || name.includes('node_modules/')) continue; // skip nested transitive for now
43
+ components.push({
44
+ name,
45
+ version: info.version || 'unknown',
46
+ type: 'library',
47
+ 'bom-ref': `pkg:npm/${name}@${info.version || 'unknown'}`,
48
+ ...(info.license ? { licenses: [{ license: { id: info.license } }] } : {}),
49
+ ...(info.resolved ? { externalReferences: [{ type: 'distribution', url: info.resolved }] } : {}),
50
+ ...(info.integrity ? { hashes: [{ alg: info.integrity.split('-')[0] || 'sha512', content: info.integrity.split('-')[1] || '' }] } : {}),
51
+ });
52
+ }
53
+ return components;
54
+ }
55
+
56
+ // lockfileVersion 1 (npm 5-6)
57
+ if (lockfile.dependencies) {
58
+ for (const [name, info] of Object.entries(lockfile.dependencies)) {
59
+ components.push({
60
+ name,
61
+ version: info.version || 'unknown',
62
+ type: 'library',
63
+ 'bom-ref': `pkg:npm/${name}@${info.version || 'unknown'}`,
64
+ ...(info.resolved ? { externalReferences: [{ type: 'distribution', url: info.resolved }] } : {}),
65
+ ...(info.integrity ? { hashes: [{ alg: info.integrity.split('-')[0] || 'sha512', content: info.integrity.split('-')[1] || '' }] } : {}),
66
+ });
67
+ }
68
+ return components;
69
+ }
70
+
71
+ return components;
72
+ }
73
+
74
+ function parsePackageJson(pkgJson) {
75
+ if (!pkgJson) return null;
76
+ return {
77
+ name: pkgJson.name || 'unnamed-project',
78
+ version: pkgJson.version || '0.0.0',
79
+ type: 'application',
80
+ 'bom-ref': `pkg:npm/${pkgJson.name || 'unnamed'}@${pkgJson.version || '0.0.0'}`,
81
+ ...(pkgJson.license ? { licenses: [{ license: { id: pkgJson.license } }] } : {}),
82
+ };
83
+ }
84
+
85
+ function buildImportGraph(dir) {
86
+ const { walk } = require('./scanner');
87
+ const files = walk(dir, []);
88
+ const imports = {};
89
+
90
+ for (const file of files) {
91
+ if (!/\.(js|jsx|ts|tsx|mjs|cjs)$/.test(file)) continue;
92
+ try {
93
+ const content = fs.readFileSync(file, 'utf8');
94
+ const relPath = path.relative(dir, file);
95
+
96
+ // require('x') and require("x")
97
+ const requireMatches = content.match(/require\(\s*['"]([^'"]+)['"]\s*\)/g) || [];
98
+ for (const m of requireMatches) {
99
+ const dep = m.match(/require\(\s*['"]([^'"]+)['"]\s*\)/);
100
+ if (dep && !dep[1].startsWith('.') && !dep[1].startsWith('/')) {
101
+ const pkgName = dep[1].startsWith('@') ? dep[1].split('/').slice(0, 2).join('/') : dep[1].split('/')[0];
102
+ if (!imports[pkgName]) imports[pkgName] = [];
103
+ if (!imports[pkgName].includes(relPath)) imports[pkgName].push(relPath);
104
+ }
105
+ }
106
+
107
+ // import ... from 'x' and import 'x'
108
+ const importMatches = content.match(/import\s+[^'"]*['"]([^'"]+)['"]/g) || [];
109
+ for (const m of importMatches) {
110
+ const dep = m.match(/['"]([^'"]+)['"]/);
111
+ if (dep && !dep[1].startsWith('.') && !dep[1].startsWith('/')) {
112
+ const pkgName = dep[1].startsWith('@') ? dep[1].split('/').slice(0, 2).join('/') : dep[1].split('/')[0];
113
+ if (!imports[pkgName]) imports[pkgName] = [];
114
+ if (!imports[pkgName].includes(relPath)) imports[pkgName].push(relPath);
115
+ }
116
+ }
117
+ } catch {}
118
+ }
119
+
120
+ return imports;
121
+ }
122
+
123
+ function generateSBOM(dir) {
124
+ const pkgJson = readJsonSafe(path.join(dir, 'package.json'));
125
+ const lockfile = readJsonSafe(path.join(dir, 'package-lock.json'));
126
+ const importGraph = buildImportGraph(dir);
127
+
128
+ const rootComponent = parsePackageJson(pkgJson);
129
+ const components = parseLockfile(lockfile);
130
+
131
+ // Mark components as "used" if they appear in the import graph
132
+ for (const comp of components) {
133
+ if (importGraph[comp.name]) {
134
+ comp.properties = comp.properties || [];
135
+ comp.properties.push({ name: 'vibeguard:imported', value: 'true' });
136
+ comp.properties.push({ name: 'vibeguard:imported_by', value: importGraph[comp.name].join(', ') });
137
+ }
138
+ }
139
+
140
+ const bom = {
141
+ bomFormat: 'CycloneDX',
142
+ specVersion: '1.5',
143
+ serialNumber: 'urn:uuid:' + crypto.randomUUID(),
144
+ version: 1,
145
+ metadata: {
146
+ timestamp: new Date().toISOString(),
147
+ tools: [{ vendor: 'VibeGuard', name: 'vibeguard-sbom', version: '1.0.0' }],
148
+ component: rootComponent || undefined,
149
+ },
150
+ components,
151
+ };
152
+
153
+ // Dependency references (flat — just root → each component)
154
+ if (rootComponent && components.length > 0) {
155
+ bom.dependencies = components.map(c => ({
156
+ ref: rootComponent['bom-ref'],
157
+ dependsOn: [c['bom-ref']],
158
+ }));
159
+ }
160
+
161
+ return bom;
162
+ }
163
+
164
+ /**
165
+ * diffSBOM(baseDir, headDir) — compare the dependency sets of two project
166
+ * snapshots (e.g. main vs. your PR). Returns machine-readable drift: what was
167
+ * added / removed / version-changed, so a CI or reviewer can spot new
168
+ * dependencies, unexpected upgrades, or disappearances.
169
+ */
170
+ function diffSBOM(baseDir, headDir) {
171
+ const base = generateSBOM(baseDir);
172
+ const head = generateSBOM(headDir);
173
+ const bMap = new Map(base.components.map(c => [c.name, c.version]));
174
+ const hMap = new Map(head.components.map(c => [c.name, c.version]));
175
+ const added = [], removed = [], changed = [];
176
+ for (const [name, version] of hMap) {
177
+ if (!bMap.has(name)) added.push({ name, version });
178
+ else if (bMap.get(name) !== version) changed.push({ name, from: bMap.get(name), to: version });
179
+ }
180
+ for (const [name, version] of bMap) {
181
+ if (!hMap.has(name)) removed.push({ name, version });
182
+ }
183
+ return {
184
+ base: baseDir,
185
+ head: headDir,
186
+ counts: { added: added.length, removed: removed.length, changed: changed.length },
187
+ added,
188
+ removed,
189
+ changed,
190
+ };
191
+ }
192
+
193
+ module.exports = { generateSBOM, parseLockfile, parsePackageJson, buildImportGraph, diffSBOM };