@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.
- package/.vibeguard-mcp.example.json +51 -0
- package/CHANGELOG.md +604 -216
- package/MCP-FIREWALL.md +296 -0
- package/README.md +355 -31
- package/bin/cli.js +355 -27
- package/bin/cmd-agent-monitor.js +45 -0
- package/bin/cmd-agent-risk.js +64 -0
- package/bin/cmd-gif.js +62 -0
- package/bin/cmd-git-scan.js +74 -0
- package/bin/cmd-llm-proxy.js +164 -0
- package/bin/cmd-mcp-firewall.js +191 -0
- package/bin/cmd-pentest.js +103 -0
- package/bin/cmd-platform.js +137 -0
- package/bin/cmd-pr-scan.js +135 -0
- package/bin/cmd-sbom-diff.js +38 -0
- package/bin/cmd-skill-scan.js +35 -0
- package/docs/AISVS.md +25 -0
- package/docs/ARCHITECTURE.md +81 -0
- package/docs/INSTALLATION.md +139 -0
- package/docs/WINDOWS.md +74 -0
- package/docs/security-policy.strict.example.json +134 -0
- package/docs/security-policy.strict.example.pub.pem +3 -0
- package/package.json +45 -7
- package/src/.vibeguard/cache/file-hashes.json +60 -0
- package/src/.vibeguard/latest-snapshot.json +36 -0
- package/src/.vibeguard/mcp-pins.json +1 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
- package/src/.vibeguard-baseline.json +5226 -0
- package/src/action-guard.js +84 -6
- package/src/agent-monitor.js +262 -0
- package/src/agent-policy.js +642 -0
- package/src/agent-risk.js +271 -0
- package/src/agentic.js +1513 -0
- package/src/ast.js +165 -7
- package/src/audit-trail.js +212 -67
- package/src/auto.js +427 -427
- package/src/autofix.js +11 -4
- package/src/bundles.js +198 -0
- package/src/daemon.js +343 -343
- package/src/dashboard.js +278 -278
- package/src/engine.js +3 -0
- package/src/entropy.js +187 -0
- package/src/firewall.js +19 -3
- package/src/gif.js +134 -0
- package/src/gitscan.js +282 -0
- package/src/hook.js +151 -151
- package/src/injection-decode.js +136 -0
- package/src/install.js +298 -280
- package/src/integrity.js +16 -1
- package/src/integrity.json +43 -13
- package/src/interceptor.js +12 -9
- package/src/llm-proxy.js +986 -0
- package/src/mcp-audit.js +61 -5
- package/src/mcp-firewall.js +971 -0
- package/src/mcp-server.js +2500 -2047
- package/src/obfuscation.js +315 -0
- package/src/owasp-agentic.js +314 -0
- package/src/pentest.js +589 -0
- package/src/pii.js +4 -0
- package/src/platform/aisvs.js +38 -0
- package/src/platform/approval.js +187 -0
- package/src/platform/canonical.js +73 -0
- package/src/platform/contracts.js +158 -0
- package/src/platform/delegation.js +73 -0
- package/src/platform/http-gateway.js +177 -0
- package/src/platform/identity.js +253 -0
- package/src/platform/jwt.js +86 -0
- package/src/platform/mcp-http-bridge.js +199 -0
- package/src/platform/memory-guard.js +64 -0
- package/src/platform/os-sandbox.js +144 -0
- package/src/platform/policy.js +332 -0
- package/src/platform/sandbox-manager.js +92 -0
- package/src/platform/signed-audit.js +357 -0
- package/src/platform/ssrf.js +129 -0
- package/src/plugin.js +182 -168
- package/src/pre-deploy.js +170 -55
- package/src/privacy-audit.js +272 -272
- package/src/repl.js +150 -150
- package/src/report.js +7 -1
- package/src/routes.js +1210 -0
- package/src/rules-2026.js +1407 -0
- package/src/rules-pack.js +3068 -3019
- package/src/rules.js +376 -60
- package/src/sandbox.js +200 -10
- package/src/sbom.js +193 -164
- package/src/scanner.js +189 -33
- package/src/shell-guard.js +11 -0
- package/src/skill-scan.js +477 -0
- package/src/slopsquat.js +144 -144
- package/src/surface.js +408 -0
- package/src/taint-ast.js +204 -37
- package/src/taint.js +15 -3
- package/src/tokenlean.js +579 -0
- 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
|
|
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
|
-
*
|
|
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
|
|
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 {
|
|
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
|
-
|
|
161
|
-
|
|
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: ${
|
|
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
|
-
|
|
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 };
|