@yagyeshvyas/vibeguard 0.1.0
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/README.md +600 -0
- package/bin/cli.js +1640 -0
- package/ci/vibeguard.yml +41 -0
- package/ci-templates/Jenkinsfile +26 -0
- package/ci-templates/azure-pipelines.yml +29 -0
- package/ci-templates/circleci.yml +24 -0
- package/ci-templates/gitlab.yml +19 -0
- package/hooks/pre-commit +31 -0
- package/package.json +94 -0
- package/src/ai-guard.js +205 -0
- package/src/ast.js +319 -0
- package/src/audit-trail.js +154 -0
- package/src/autofix.js +524 -0
- package/src/badge.js +42 -0
- package/src/behavior.js +205 -0
- package/src/compliance.js +151 -0
- package/src/crosstaint.js +324 -0
- package/src/cve-intel.js +136 -0
- package/src/dashboard.js +279 -0
- package/src/deps.js +159 -0
- package/src/doctor.js +111 -0
- package/src/engine.js +234 -0
- package/src/external.js +160 -0
- package/src/firewall.js +517 -0
- package/src/history.js +87 -0
- package/src/hook.js +151 -0
- package/src/install.js +248 -0
- package/src/interceptor.js +476 -0
- package/src/mcp-server.js +1804 -0
- package/src/net-audit.js +208 -0
- package/src/pii.js +212 -0
- package/src/plugin.js +80 -0
- package/src/policy-gen.js +288 -0
- package/src/pre-deploy.js +282 -0
- package/src/presets.js +113 -0
- package/src/privacy-audit.js +273 -0
- package/src/repl.js +150 -0
- package/src/report.js +312 -0
- package/src/rules-pack.js +2753 -0
- package/src/rules.js +1446 -0
- package/src/sandbox.js +139 -0
- package/src/scanner.js +651 -0
- package/src/secure-prompt.js +140 -0
- package/src/slopsquat.js +144 -0
- package/src/supply-firewall.js +243 -0
- package/src/suppress.js +89 -0
- package/src/taint.js +168 -0
- package/src/trace.js +220 -0
- package/src/urlscan.js +142 -0
- package/src/vault.js +145 -0
- package/src/verify.js +98 -0
- package/src/verifykeys.js +87 -0
package/src/sandbox.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Zero-Trust Sandbox.
|
|
5
|
+
*
|
|
6
|
+
* Executes AI-generated code in a locked-down context with:
|
|
7
|
+
* - No access to process.env (secrets hidden)
|
|
8
|
+
* - No access to fs (filesystem locked)
|
|
9
|
+
* - No access to child_process (no command execution)
|
|
10
|
+
* - No access to net/http (no network access)
|
|
11
|
+
* - No access to eval/Function (no dynamic code)
|
|
12
|
+
* - Time-limited execution (prevents infinite loops)
|
|
13
|
+
* - Memory-limited (prevents memory bombs)
|
|
14
|
+
* - Full audit log of every operation attempted
|
|
15
|
+
*
|
|
16
|
+
* Even if AI generates malicious code, it runs in a cage.
|
|
17
|
+
* 100% local. Zero network. Zero dependencies.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const vm = require('vm');
|
|
21
|
+
|
|
22
|
+
const DEFAULT_TIMEOUT = 5000; // 5s
|
|
23
|
+
const DEFAULT_MAX_MEMORY = 16 * 1024 * 1024; // 16MB
|
|
24
|
+
|
|
25
|
+
// Safe globals — only harmless operations allowed
|
|
26
|
+
const SAFE_GLOBALS = {
|
|
27
|
+
console: { log: (...args) => sandboxLog('log', args), error: (...args) => sandboxLog('error', args), warn: (...args) => sandboxLog('warn', args) },
|
|
28
|
+
JSON: { parse: JSON.parse, stringify: JSON.stringify },
|
|
29
|
+
Math: Math,
|
|
30
|
+
Date: Date,
|
|
31
|
+
Array: Array,
|
|
32
|
+
Object: Object,
|
|
33
|
+
String: String,
|
|
34
|
+
Number: Number,
|
|
35
|
+
Boolean: Boolean,
|
|
36
|
+
RegExp: RegExp,
|
|
37
|
+
Map: Map,
|
|
38
|
+
Set: Set,
|
|
39
|
+
Promise: Promise,
|
|
40
|
+
Symbol: Symbol,
|
|
41
|
+
parseInt: parseInt,
|
|
42
|
+
parseFloat: parseFloat,
|
|
43
|
+
isNaN: isNaN,
|
|
44
|
+
isFinite: isFinite,
|
|
45
|
+
encodeURIComponent: encodeURIComponent,
|
|
46
|
+
decodeURIComponent: decodeURIComponent,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Blocked globals — AI cannot access these
|
|
50
|
+
const BLOCKED_GLOBALS = [
|
|
51
|
+
'process', 'require', 'module', 'exports', '__dirname', '__filename',
|
|
52
|
+
'eval', 'Function', 'setTimeout', 'setInterval', 'setImmediate',
|
|
53
|
+
'fetch', 'XMLHttpRequest', 'WebSocket', 'ChildProcess',
|
|
54
|
+
'Buffer', 'Stream', 'crypto', 'net', 'http', 'https', 'dns', 'os',
|
|
55
|
+
'child_process', 'cluster', 'worker', 'v8', 'vm',
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
let sandboxLog = () => {};
|
|
59
|
+
let auditLog = [];
|
|
60
|
+
|
|
61
|
+
function createSandbox(opts = {}) {
|
|
62
|
+
const timeout = opts.timeout || DEFAULT_TIMEOUT;
|
|
63
|
+
const maxMemory = opts.maxMemory || DEFAULT_MAX_MEMORY;
|
|
64
|
+
auditLog = [];
|
|
65
|
+
|
|
66
|
+
sandboxLog = (level, args) => {
|
|
67
|
+
auditLog.push({ type: 'console', level, args: args.map(a => String(a).slice(0, 200)) });
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const context = { ...SAFE_GLOBALS };
|
|
71
|
+
|
|
72
|
+
// Add blocked globals as traps that log attempts
|
|
73
|
+
for (const blocked of BLOCKED_GLOBALS) {
|
|
74
|
+
Object.defineProperty(context, blocked, {
|
|
75
|
+
get() {
|
|
76
|
+
auditLog.push({ type: 'blocked_access', global: blocked, timestamp: Date.now() });
|
|
77
|
+
throw new Error(`VibeGuard Sandbox: "${blocked}" is not available in sandboxed execution`);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
context.globalThis = context;
|
|
83
|
+
context.global = context;
|
|
84
|
+
context.this = context;
|
|
85
|
+
|
|
86
|
+
return { context, timeout, maxMemory };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function runInSandbox(code, opts = {}) {
|
|
90
|
+
const { context, timeout } = createSandbox(opts);
|
|
91
|
+
const startTime = Date.now();
|
|
92
|
+
const result = { success: false, output: null, error: null, audit: [], duration: 0 };
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const vmContext = vm.createContext(context);
|
|
96
|
+
const script = new vm.Script(code, { timeout });
|
|
97
|
+
result.output = script.runInContext(vmContext, { timeout });
|
|
98
|
+
result.success = true;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
result.error = err.message;
|
|
101
|
+
if (err.code === 'ERR_SCRIPT_EXECUTION_TIMEOUT') {
|
|
102
|
+
result.error = 'VibeGuard Sandbox: Execution timed out (possible infinite loop)';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
result.duration = Date.now() - startTime;
|
|
107
|
+
result.audit = auditLog;
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getAuditLog() {
|
|
112
|
+
return auditLog;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function renderSandboxReport(result) {
|
|
116
|
+
const C = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
117
|
+
const lines = [
|
|
118
|
+
`${C.bold}VibeGuard Sandbox Execution${C.reset}`,
|
|
119
|
+
`${C.dim}${'─'.repeat(60)}${C.reset}`,
|
|
120
|
+
'',
|
|
121
|
+
` Success: ${result.success ? C.green + 'YES' : C.red + 'NO'}${C.reset}`,
|
|
122
|
+
` Duration: ${result.duration}ms`,
|
|
123
|
+
` Output: ${result.success ? String(result.output).slice(0, 200) : 'N/A'}`,
|
|
124
|
+
];
|
|
125
|
+
if (result.error) lines.push(` Error: ${C.red}${result.error}${C.reset}`);
|
|
126
|
+
if (result.audit.length > 0) {
|
|
127
|
+
lines.push('', `${C.bold}Audit Log${C.reset}`, '');
|
|
128
|
+
for (const entry of result.audit) {
|
|
129
|
+
if (entry.type === 'blocked_access') {
|
|
130
|
+
lines.push(` ${C.red}[BLOCKED]${C.reset} Attempted access to "${entry.global}"`);
|
|
131
|
+
} else if (entry.type === 'console') {
|
|
132
|
+
lines.push(` ${C.dim}[${entry.level}]${C.reset} ${entry.args.join(' ').slice(0, 100)}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return lines.join('\n');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = { createSandbox, runInSandbox, getAuditLog, renderSandboxReport, SAFE_GLOBALS, BLOCKED_GLOBALS };
|