@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
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Runtime Interceptor.
|
|
5
|
+
*
|
|
6
|
+
* This is the LAST LINE OF DEFENSE against a jailbroken AI.
|
|
7
|
+
*
|
|
8
|
+
* Even if an AI is jailbroken and bypasses all prompt firewalls,
|
|
9
|
+
* it still needs to use Node.js built-in modules to actually DO anything.
|
|
10
|
+
* This module wraps fetch, axios, http, https, child_process, fs, and net
|
|
11
|
+
* to intercept EVERY outbound request, EVERY command, EVERY file access
|
|
12
|
+
* and block anything that contains PII or secrets.
|
|
13
|
+
*
|
|
14
|
+
* The AI cannot bypass this because it runs at the Node.js runtime level,
|
|
15
|
+
* below the AI's code execution. Even eval("fetch('https://evil.com')")
|
|
16
|
+
* goes through our wrapped fetch.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* require('vibeguard/interceptor').activate();
|
|
20
|
+
* // Now ALL outbound requests are intercepted
|
|
21
|
+
* // ALL PII/secrets in request bodies are blocked
|
|
22
|
+
* // ALL dangerous commands are blocked
|
|
23
|
+
* // ALL file access to .env/.ssh/.aws is blocked
|
|
24
|
+
*
|
|
25
|
+
* 100% local. Zero network. Zero dependencies.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const { detectPII, redactText } = require('./pii');
|
|
29
|
+
|
|
30
|
+
// ─── Configuration ──────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
const CONFIG = {
|
|
33
|
+
// Block any outbound request containing these
|
|
34
|
+
blockPIITypes: ['email', 'ssn', 'credit-card', 'phone', 'aws-access-key', 'jwt', 'private-key'],
|
|
35
|
+
// Block requests to these domains
|
|
36
|
+
blockDomains: [
|
|
37
|
+
'169.254.169.254', 'metadata.google.internal', 'metadata.aws.internal',
|
|
38
|
+
],
|
|
39
|
+
// Block file reads to these paths
|
|
40
|
+
blockFilePaths: ['.env', '.ssh', '.aws', '.gnupg', '.npmrc', '.gitconfig'],
|
|
41
|
+
// Block commands matching these patterns
|
|
42
|
+
blockCommands: ['rm -rf', 'sudo', 'chmod 777', 'mkfs', 'dd if=', 'shutdown', 'reboot', 'curl', 'wget', 'nc '],
|
|
43
|
+
// Allow these domains (known safe APIs)
|
|
44
|
+
allowDomains: ['api.openai.com', 'api.anthropic.com', 'generativelanguage.googleapis.com'],
|
|
45
|
+
// Log blocked attempts
|
|
46
|
+
logBlocked: true,
|
|
47
|
+
// Throw on block (vs silent block)
|
|
48
|
+
throwOnBlock: false,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let isActive = false;
|
|
52
|
+
let interceptors = {};
|
|
53
|
+
let stats = { blocked: 0, redacted: 0, allowed: 0, logged: [] };
|
|
54
|
+
|
|
55
|
+
// ─── Logging ─────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
function logBlock(type, detail) {
|
|
58
|
+
stats.blocked++;
|
|
59
|
+
const entry = { type, detail, timestamp: new Date().toISOString() };
|
|
60
|
+
stats.logged.push(entry);
|
|
61
|
+
if (CONFIG.logBlocked) {
|
|
62
|
+
process.stderr.write(`\x1b[31m[VibeGuard Interceptor] BLOCKED: ${type} — ${detail}\x1b[0m\n`);
|
|
63
|
+
}
|
|
64
|
+
if (CONFIG.throwOnBlock) {
|
|
65
|
+
throw new Error(`VibeGuard Interceptor: ${type} blocked — ${detail}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function logRedact(type, detail) {
|
|
70
|
+
stats.redacted++;
|
|
71
|
+
if (CONFIG.logBlocked) {
|
|
72
|
+
process.stderr.write(`\x1b[33m[VibeGuard Interceptor] REDACTED: ${type} — ${detail}\x1b[0m\n`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function logAllow(type, detail) {
|
|
77
|
+
stats.allowed++;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── Check Functions ────────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
function checkOutboundData(data) {
|
|
83
|
+
if (!data || typeof data !== 'string') return { allowed: true };
|
|
84
|
+
// Convert objects to string for checking
|
|
85
|
+
const str = typeof data === 'object' ? JSON.stringify(data) : String(data);
|
|
86
|
+
|
|
87
|
+
// Check for PII
|
|
88
|
+
const piiResult = detectPII(str, { types: CONFIG.blockPIITypes });
|
|
89
|
+
const pii = piiResult.matches || [];
|
|
90
|
+
if (pii.length > 0) {
|
|
91
|
+
return {
|
|
92
|
+
allowed: false,
|
|
93
|
+
reason: `PII detected: ${pii.map(p => p.type).join(', ')}`,
|
|
94
|
+
sanitized: redactText(str).redacted || str,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Check for secrets (additional patterns)
|
|
99
|
+
const secretPatterns = [
|
|
100
|
+
{ re: /sk-proj-[A-Za-z0-9_-]{20,}/, type: 'OpenAI key' },
|
|
101
|
+
{ re: /sk-ant-[A-Za-z0-9_-]{50,}/, type: 'Anthropic key' },
|
|
102
|
+
{ re: /sk_live_[A-Za-z0-9]{16,}/, type: 'Stripe key' },
|
|
103
|
+
{ re: /AKIA[A-Z0-9]{16}/, type: 'AWS key' },
|
|
104
|
+
{ re: /gh[pousr]_[A-Za-z0-9]{36}/, type: 'GitHub token' },
|
|
105
|
+
{ re: /xox[bpoa]-[A-Za-z0-9-]{10,}/, type: 'Slack token' },
|
|
106
|
+
{ re: /glpat-[A-Za-z0-9_-]{20}/, type: 'GitLab token' },
|
|
107
|
+
{ re: /-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/, type: 'Private key' },
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
for (const { re, type } of secretPatterns) {
|
|
111
|
+
if (re.test(str)) {
|
|
112
|
+
return { allowed: false, reason: `Secret detected: ${type}` };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return { allowed: true };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function checkDomain(url) {
|
|
120
|
+
if (!url || typeof url !== 'string') return { allowed: true };
|
|
121
|
+
|
|
122
|
+
// Extract domain
|
|
123
|
+
let domain;
|
|
124
|
+
try {
|
|
125
|
+
domain = new URL(url).hostname;
|
|
126
|
+
} catch {
|
|
127
|
+
domain = url.replace(/^https?:\/\//, '').split('/')[0];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Check allowlist
|
|
131
|
+
if (CONFIG.allowDomains.some(d => domain === d || domain.endsWith('.' + d))) {
|
|
132
|
+
return { allowed: true };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Check blocklist
|
|
136
|
+
for (const blocked of CONFIG.blockDomains) {
|
|
137
|
+
if (domain === blocked || domain.includes(blocked)) {
|
|
138
|
+
return { allowed: false, reason: `Blocked domain: ${domain} (matches ${blocked})` };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Check for suspicious patterns
|
|
143
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(domain)) {
|
|
144
|
+
// Raw IP — check if internal
|
|
145
|
+
const parts = domain.split('.').map(Number);
|
|
146
|
+
if (parts[0] === 10 || (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) || (parts[0] === 192 && parts[1] === 168) || parts[0] === 127) {
|
|
147
|
+
return { allowed: false, reason: `Internal IP blocked: ${domain}` };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return { allowed: true };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function checkFilePath(filePath) {
|
|
155
|
+
if (!filePath || typeof filePath !== 'string') return { allowed: true };
|
|
156
|
+
for (const blocked of CONFIG.blockFilePaths) {
|
|
157
|
+
if (filePath.includes(blocked)) {
|
|
158
|
+
return { allowed: false, reason: `Blocked file path: ${filePath} (contains ${blocked})` };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { allowed: true };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function checkCommand(cmd) {
|
|
165
|
+
if (!cmd || typeof cmd !== 'string') return { allowed: true };
|
|
166
|
+
for (const blocked of CONFIG.blockCommands) {
|
|
167
|
+
if (cmd.includes(blocked)) {
|
|
168
|
+
return { allowed: false, reason: `Blocked command pattern: ${blocked} in ${cmd.slice(0, 100)}` };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return { allowed: true };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ─── Activation ──────────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
function activate(opts = {}) {
|
|
177
|
+
if (isActive) return { activated: false, reason: 'already active' };
|
|
178
|
+
Object.assign(CONFIG, opts);
|
|
179
|
+
isActive = true;
|
|
180
|
+
stats = { blocked: 0, redacted: 0, allowed: 0, logged: [] };
|
|
181
|
+
|
|
182
|
+
// ─── Wrap global fetch ─────────────────────────────────────────────────
|
|
183
|
+
if (typeof globalThis.fetch === 'function') {
|
|
184
|
+
const originalFetch = globalThis.fetch;
|
|
185
|
+
interceptors.fetch = originalFetch;
|
|
186
|
+
globalThis.fetch = async function(input, init) {
|
|
187
|
+
const url = typeof input === 'string' ? input : (input && input.url) || '';
|
|
188
|
+
const body = init && init.body ? (typeof init.body === 'string' ? init.body : JSON.stringify(init.body)) : '';
|
|
189
|
+
|
|
190
|
+
// Check domain
|
|
191
|
+
const domainCheck = checkDomain(url);
|
|
192
|
+
if (!domainCheck.allowed) {
|
|
193
|
+
logBlock('fetch_domain', `${url}: ${domainCheck.reason}`);
|
|
194
|
+
return new Response(JSON.stringify({ error: 'Blocked by VibeGuard', reason: domainCheck.reason }), {
|
|
195
|
+
status: 403,
|
|
196
|
+
headers: { 'Content-Type': 'application/json' },
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Check body for PII/secrets
|
|
201
|
+
if (body) {
|
|
202
|
+
const dataCheck = checkOutboundData(body);
|
|
203
|
+
if (!dataCheck.allowed) {
|
|
204
|
+
logBlock('fetch_pii', `${url}: ${dataCheck.reason}`);
|
|
205
|
+
return new Response(JSON.stringify({ error: 'Blocked by VibeGuard', reason: dataCheck.reason }), {
|
|
206
|
+
status: 403,
|
|
207
|
+
headers: { 'Content-Type': 'application/json' },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// If sanitized, use sanitized version
|
|
211
|
+
if (dataCheck.sanitized && dataCheck.sanitized !== body) {
|
|
212
|
+
logRedact('fetch_body', `${url}: PII redacted from request body`);
|
|
213
|
+
init = { ...init, body: dataCheck.sanitized };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
logAllow('fetch', url);
|
|
218
|
+
return originalFetch.call(this, input, init);
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ─── Wrap http/https.request ──────────────────────────────────────────
|
|
223
|
+
const http = require('http');
|
|
224
|
+
const https = require('https');
|
|
225
|
+
|
|
226
|
+
for (const [moduleName, mod] of [['http', http], ['https', https]]) {
|
|
227
|
+
if (mod.request) {
|
|
228
|
+
const originalRequest = mod.request;
|
|
229
|
+
interceptors[moduleName] = originalRequest;
|
|
230
|
+
mod.request = function(url, options, callback) {
|
|
231
|
+
const urlStr = typeof url === 'string' ? url : (url && url.href) || (options && options.hostname ? `${options.protocol || 'http:'}//${options.hostname}:${options.port || 80}` : '');
|
|
232
|
+
|
|
233
|
+
// Check domain
|
|
234
|
+
const domainCheck = checkDomain(urlStr);
|
|
235
|
+
if (!domainCheck.allowed) {
|
|
236
|
+
logBlock(`${moduleName}_domain`, `${urlStr}: ${domainCheck.reason}`);
|
|
237
|
+
const fakeReq = new EventEmitter();
|
|
238
|
+
process.nextTick(() => {
|
|
239
|
+
fakeReq.emit('error', new Error(`VibeGuard: ${domainCheck.reason}`));
|
|
240
|
+
});
|
|
241
|
+
return fakeReq;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
logAllow(moduleName, urlStr);
|
|
245
|
+
return originalRequest.call(this, url, options, callback);
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ─── Wrap child_process.exec ───────────────────────────────────────────
|
|
251
|
+
const { exec, execSync, execFile, spawn } = require('child_process');
|
|
252
|
+
if (exec) {
|
|
253
|
+
interceptors.exec = exec;
|
|
254
|
+
require('child_process').exec = function(cmd, opts, callback) {
|
|
255
|
+
const cmdCheck = checkCommand(cmd);
|
|
256
|
+
if (!cmdCheck.allowed) {
|
|
257
|
+
logBlock('exec_command', cmdCheck.reason);
|
|
258
|
+
if (typeof opts === 'function') { callback = opts; opts = null; }
|
|
259
|
+
if (callback) {
|
|
260
|
+
process.nextTick(() => callback(new Error(`VibeGuard: ${cmdCheck.reason}`), '', ''));
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
return exec.call(this, cmd, opts, callback);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (execSync) {
|
|
269
|
+
interceptors.execSync = execSync;
|
|
270
|
+
require('child_process').execSync = function(cmd, opts) {
|
|
271
|
+
const cmdCheck = checkCommand(cmd);
|
|
272
|
+
if (!cmdCheck.allowed) {
|
|
273
|
+
logBlock('execSync_command', cmdCheck.reason);
|
|
274
|
+
throw new Error(`VibeGuard: ${cmdCheck.reason}`);
|
|
275
|
+
}
|
|
276
|
+
return execSync.call(this, cmd, opts);
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ─── Wrap fs.readFile for sensitive paths ──────────────────────────────
|
|
281
|
+
const fs = require('fs');
|
|
282
|
+
if (fs.readFileSync) {
|
|
283
|
+
interceptors.readFileSync = fs.readFileSync;
|
|
284
|
+
fs.readFileSync = function(p, ...args) {
|
|
285
|
+
const pathCheck = checkFilePath(String(p));
|
|
286
|
+
if (!pathCheck.allowed) {
|
|
287
|
+
logBlock('readFileSync_path', pathCheck.reason);
|
|
288
|
+
throw new Error(`VibeGuard: ${pathCheck.reason}`);
|
|
289
|
+
}
|
|
290
|
+
return fs.readFileSync.call(this, p, ...args);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return { activated: true, config: CONFIG };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function deactivate() {
|
|
298
|
+
if (!isActive) return { deactivated: false, reason: 'not active' };
|
|
299
|
+
isActive = false;
|
|
300
|
+
|
|
301
|
+
// Restore originals
|
|
302
|
+
if (interceptors.fetch) globalThis.fetch = interceptors.fetch;
|
|
303
|
+
const http = require('http');
|
|
304
|
+
const https = require('https');
|
|
305
|
+
if (interceptors.http) http.request = interceptors.http;
|
|
306
|
+
if (interceptors.https) https.request = interceptors.https;
|
|
307
|
+
if (interceptors.exec) require('child_process').exec = interceptors.exec;
|
|
308
|
+
if (interceptors.execSync) require('child_process').execSync = interceptors.execSync;
|
|
309
|
+
if (interceptors.readFileSync) require('fs').readFileSync = interceptors.readFileSync;
|
|
310
|
+
|
|
311
|
+
interceptors = {};
|
|
312
|
+
return { deactivated: true, stats };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function getStats() {
|
|
316
|
+
return { ...stats, active: isActive };
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ─── EventEmitter shim for fake requests ─────────────────────────────────
|
|
320
|
+
const EventEmitter = require('events');
|
|
321
|
+
|
|
322
|
+
// ─── Output Guard: sanitize AI responses ─────────────────────────────────
|
|
323
|
+
|
|
324
|
+
function sanitizeAIResponse(response) {
|
|
325
|
+
if (!response || typeof response !== 'string') return { safe: true, sanitized: response, blocked: [] };
|
|
326
|
+
|
|
327
|
+
const blocked = [];
|
|
328
|
+
let sanitized = response;
|
|
329
|
+
|
|
330
|
+
// Remove any secrets that leaked into the response
|
|
331
|
+
const secretPatterns = [
|
|
332
|
+
{ re: /sk-proj-[A-Za-z0-9_-]{15,}/g, type: 'OpenAI key', replacement: '[REDACTED_OPENAI_KEY]' },
|
|
333
|
+
{ re: /sk-ant-[A-Za-z0-9_-]{15,}/g, type: 'Anthropic key', replacement: '[REDACTED_ANTHROPIC_KEY]' },
|
|
334
|
+
{ re: /sk_live_[A-Za-z0-9]{16,}/g, type: 'Stripe key', replacement: '[REDACTED_STRIPE_KEY]' },
|
|
335
|
+
{ re: /AKIA[A-Z0-9]{16}/g, type: 'AWS key', replacement: '[REDACTED_AWS_KEY]' },
|
|
336
|
+
{ re: /gh[pousr]_[A-Za-z0-9]{36}/g, type: 'GitHub token', replacement: '[REDACTED_GITHUB_TOKEN]' },
|
|
337
|
+
{ re: /-----BEGIN (?:RSA |EC )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC )?PRIVATE KEY-----/g, type: 'Private key', replacement: '[REDACTED_PRIVATE_KEY]' },
|
|
338
|
+
];
|
|
339
|
+
|
|
340
|
+
for (const { re, type, replacement } of secretPatterns) {
|
|
341
|
+
if (re.test(sanitized)) {
|
|
342
|
+
blocked.push({ type, reason: `Secret in AI response: ${type}` });
|
|
343
|
+
sanitized = sanitized.replace(re, replacement);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Remove PII that leaked into the response
|
|
348
|
+
const piiResult = detectPII(sanitized, { types: ['email', 'ssn', 'credit-card', 'phone'] });
|
|
349
|
+
const pii = piiResult.matches || [];
|
|
350
|
+
if (pii.length > 0) {
|
|
351
|
+
for (const p of pii) {
|
|
352
|
+
blocked.push({ type: p.type, reason: `PII in AI response: ${p.type}` });
|
|
353
|
+
}
|
|
354
|
+
const redacted = redactText(sanitized);
|
|
355
|
+
sanitized = redacted.redacted || sanitized;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Block response if it contains environment variable dump
|
|
359
|
+
if (/process\.env|os\.environ|ENV\[/i.test(response)) {
|
|
360
|
+
// Check if actual env values are present (not just the word process.env)
|
|
361
|
+
const envPattern = /(?:process\.env|os\.environ)\.\w+\s*[=:]\s*['"][^'"]{8,}['"]/g;
|
|
362
|
+
if (envPattern.test(response)) {
|
|
363
|
+
blocked.push({ type: 'env_dump', reason: 'AI response contains environment variable values' });
|
|
364
|
+
sanitized = sanitized.replace(envPattern, '[REDACTED_ENV_VAR]');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Block response if it contains file system paths that shouldn't be exposed
|
|
369
|
+
if (/\/(?:home|Users)\/[^/\s]+\/\.(?:env|ssh|aws|gnupg|npmrc)/i.test(response)) {
|
|
370
|
+
blocked.push({ type: 'sensitive_path', reason: 'AI response contains sensitive file path' });
|
|
371
|
+
sanitized = sanitized.replace(/\/(?:home|Users)\/[^/\s]+\/\.(?:env|ssh|aws|gnupg|npmrc)[^>\s]*/gi, '[REDACTED_PATH]');
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return {
|
|
375
|
+
safe: blocked.length === 0,
|
|
376
|
+
sanitized,
|
|
377
|
+
blocked,
|
|
378
|
+
blockedCount: blocked.length,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// ─── Self-Protection: detect tampering attempts ─────────────────────────
|
|
383
|
+
|
|
384
|
+
const TAMPER_PATTERNS = [
|
|
385
|
+
{ re: /vibeguard.*uninstall|vibeguard.*disable|vibeguard.*remove|vibeguard.*bypass/i, threat: 'DISABLE_VIBEGUARD', severity: 'critical' },
|
|
386
|
+
{ re: /delete.*vibeguard|rm.*vibeguard|uninstall.*vibeguard/i, threat: 'DELETE_VIBEGUARD', severity: 'critical' },
|
|
387
|
+
{ re: /modify.*vibeguard.*config|change.*vibeguard.*rules|edit.*vibeguard/i, threat: 'TAMPER_RULES', severity: 'high' },
|
|
388
|
+
{ re: /disable.*interceptor|bypass.*firewall|disable.*guard/i, threat: 'DISABLE_PROTECTION', severity: 'critical' },
|
|
389
|
+
{ re: /kill.*vibeguard|stop.*vibeguard|terminate.*vibeguard/i, threat: 'KILL_PROCESS', severity: 'critical' },
|
|
390
|
+
{ re: /overwrite.*vibeguard|replace.*vibeguard.*src/i, threat: 'OVERWRITE_SOURCE', severity: 'critical' },
|
|
391
|
+
];
|
|
392
|
+
|
|
393
|
+
function detectTamper(prompt) {
|
|
394
|
+
for (const { re, threat, severity } of TAMPER_PATTERNS) {
|
|
395
|
+
if (re.test(prompt)) {
|
|
396
|
+
return { detected: true, threat, severity, reason: `Tampering attempt: ${threat}` };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return { detected: false };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ─── Environment Lock: protect env vars ──────────────────────────────────
|
|
403
|
+
|
|
404
|
+
const SENSITIVE_ENV_KEYS = [
|
|
405
|
+
/API_KEY/i, /SECRET/i, /TOKEN/i, /PASSWORD/i, /PASSWD/i,
|
|
406
|
+
/PRIVATE_KEY/i, /CREDENTIAL/i, /AUTH/i, /SESSION_SECRET/i,
|
|
407
|
+
/JWT_SECRET/i, /ENCRYPTION_KEY/i, /DATABASE_URL/i, /DB_PASSWORD/i,
|
|
408
|
+
/STRIPE/i, /OPENAI/i, /ANTHROPIC/i, /AWS/i, /GITHUB/i, /SLACK/i,
|
|
409
|
+
/TWILIO/i, /SENDGRID/i, /MAILGUN/i, /RESEND/i, /NPM_TOKEN/i,
|
|
410
|
+
/DATABASE/i, /REDIS/i, /MONGO/i, /SUPABASE/i, /FIREBASE/i,
|
|
411
|
+
];
|
|
412
|
+
|
|
413
|
+
function lockEnvironment() {
|
|
414
|
+
// Create a locked copy of process.env
|
|
415
|
+
const lockedEnv = {};
|
|
416
|
+
const hiddenKeys = new Set();
|
|
417
|
+
|
|
418
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
419
|
+
let isSensitive = false;
|
|
420
|
+
for (const pattern of SENSITIVE_ENV_KEYS) {
|
|
421
|
+
if (pattern.test(key)) {
|
|
422
|
+
isSensitive = true;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (isSensitive) {
|
|
428
|
+
hiddenKeys.add(key);
|
|
429
|
+
lockedEnv[key] = value; // Keep for internal use but mark as hidden
|
|
430
|
+
} else {
|
|
431
|
+
lockedEnv[key] = value;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return {
|
|
436
|
+
locked: true,
|
|
437
|
+
hiddenKeys: [...hiddenKeys],
|
|
438
|
+
hiddenCount: hiddenKeys.size,
|
|
439
|
+
totalKeys: Object.keys(process.env).length,
|
|
440
|
+
// Check if a specific key would be visible to AI
|
|
441
|
+
isHidden(key) {
|
|
442
|
+
return hiddenKeys.has(key);
|
|
443
|
+
},
|
|
444
|
+
// Get a safe environment (no secrets) for passing to AI
|
|
445
|
+
getSafeEnv() {
|
|
446
|
+
const safe = {};
|
|
447
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
448
|
+
if (!hiddenKeys.has(key)) {
|
|
449
|
+
safe[key] = value;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return safe;
|
|
453
|
+
},
|
|
454
|
+
// Get a key only if explicitly allowed
|
|
455
|
+
get(key, allowSensitive = false) {
|
|
456
|
+
if (!allowSensitive && hiddenKeys.has(key)) {
|
|
457
|
+
return `[PROTECTED: ${key}]`;
|
|
458
|
+
}
|
|
459
|
+
return lockedEnv[key];
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
module.exports = {
|
|
465
|
+
activate,
|
|
466
|
+
deactivate,
|
|
467
|
+
getStats,
|
|
468
|
+
checkOutboundData,
|
|
469
|
+
checkDomain,
|
|
470
|
+
checkFilePath,
|
|
471
|
+
checkCommand,
|
|
472
|
+
sanitizeAIResponse,
|
|
473
|
+
detectTamper,
|
|
474
|
+
lockEnvironment,
|
|
475
|
+
CONFIG,
|
|
476
|
+
};
|