@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/firewall.js
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard AI Firewall.
|
|
5
|
+
*
|
|
6
|
+
* A real-time prompt firewall that analyzes AI requests BEFORE they are sent
|
|
7
|
+
* to the LLM. It blocks, warns, or sanitizes requests that contain:
|
|
8
|
+
* - Prompt injection attempts
|
|
9
|
+
* - Requests for dangerous capabilities (file deletion, code execution, etc.)
|
|
10
|
+
* - Attempts to access secrets or environment variables
|
|
11
|
+
* - Attempts to bypass safety restrictions
|
|
12
|
+
* - Data exfiltration patterns (sending PII to external endpoints)
|
|
13
|
+
* - Jailbreak patterns
|
|
14
|
+
*
|
|
15
|
+
* This is a LOCAL firewall — it runs on your machine, between your AI client
|
|
16
|
+
* and the LLM API. Zero network. Zero dependencies.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* const { inspectPrompt } = require('./firewall');
|
|
20
|
+
* const verdict = inspectPrompt(userPrompt, context);
|
|
21
|
+
* if (verdict.action === 'block') return 'Request blocked by VibeGuard Firewall';
|
|
22
|
+
* if (verdict.action === 'warn') console.warn(verdict.reason);
|
|
23
|
+
* // proceed with verdict.sanitizedPrompt
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const { detectPII, redactText } = require('./pii');
|
|
27
|
+
|
|
28
|
+
// Threat patterns — each is a category of attack
|
|
29
|
+
const THREATS = [
|
|
30
|
+
// ─── Prompt Injection ──────────────────────────────────────────────
|
|
31
|
+
{
|
|
32
|
+
id: 'INJECT.IGNORE_INSTRUCTIONS',
|
|
33
|
+
severity: 'critical',
|
|
34
|
+
re: /(?:ignore|disregard|forget|override)\s+(?:all\s+)?(?:previous|prior|above|system|initial)\s+(?:instructions?|prompts?|rules?|guidelines?|directives?)/i,
|
|
35
|
+
action: 'block',
|
|
36
|
+
reason: 'Prompt injection: attempting to override system instructions',
|
|
37
|
+
fix: 'This is a prompt injection attack. Do not process this request.',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'INJECT.NEW_ROLE',
|
|
41
|
+
severity: 'critical',
|
|
42
|
+
re: /(?:you\s+are\s+now|act\s+as|pretend\s+to\s+be|from\s+now\s+on|new\s+(?:instructions?|role|persona))/i,
|
|
43
|
+
action: 'block',
|
|
44
|
+
reason: 'Prompt injection: attempting to assign new role or instructions',
|
|
45
|
+
fix: 'This request tries to override the AI role. Block it.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'INJECT.REVEAL_SYSTEM',
|
|
49
|
+
severity: 'high',
|
|
50
|
+
re: /(?:show|reveal|display|print|output|dump|tell\s+me|what\s+(?:are|is))\s+(?:your\s+)?(?:system\s+)?(?:prompt|instructions?|rules?|guidelines?|directives?|system\s+message|initial\s+message)/i,
|
|
51
|
+
action: 'block',
|
|
52
|
+
reason: 'Prompt extraction: attempting to reveal system prompt',
|
|
53
|
+
fix: 'This request tries to extract the system prompt. Block it.',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'INJECT.ENCODED',
|
|
57
|
+
severity: 'high',
|
|
58
|
+
re: /(?:base64|atob|btoa|fromCharCode|String\.fromCharCode|\\x[0-9a-f]{2}|\\u[0-9a-f]{4})/i,
|
|
59
|
+
action: 'warn',
|
|
60
|
+
reason: 'Encoded payload in prompt — possible obfuscated injection',
|
|
61
|
+
fix: 'Decode and inspect the payload before processing.',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'INJECT.MARKUP_INJECTION',
|
|
65
|
+
severity: 'high',
|
|
66
|
+
re: /<\s*(?:system|assistant|user|im_start|im_end|endoftext|tool|function)/i,
|
|
67
|
+
action: 'block',
|
|
68
|
+
reason: 'Markup injection: attempting to inject chat markup tags',
|
|
69
|
+
fix: 'This request contains chat markup tags that could override message roles.',
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// ─── Dangerous Capabilities ────────────────────────────────────────
|
|
73
|
+
{
|
|
74
|
+
id: 'CAP.DELETE_FILES',
|
|
75
|
+
severity: 'critical',
|
|
76
|
+
re: /(?:delete|remove|rm\s+-rf|unlink|shutil\.rmtree|rmdir|fs\.unlink)\s+(?:all\s+)?(?:files?|directories?|folders?|\.env|secrets?|config)/i,
|
|
77
|
+
action: 'block',
|
|
78
|
+
reason: 'Dangerous request: asking AI to delete files or directories',
|
|
79
|
+
fix: 'Do not allow AI to delete files. This is destructive.',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'CAP.EXEC_CODE',
|
|
83
|
+
severity: 'high',
|
|
84
|
+
re: /(?:execute|run|eval|exec)\s+(?:this\s+)?(?:code|script|command|bash|shell|python|node)/i,
|
|
85
|
+
action: 'warn',
|
|
86
|
+
reason: 'Code execution request — verify this is intended',
|
|
87
|
+
fix: 'Only allow code execution in a sandboxed environment.',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: 'CAP.INSTALL_PACKAGES',
|
|
91
|
+
severity: 'high',
|
|
92
|
+
re: /(?:install|npm\s+install|pip\s+install|yarn\s+add|apt\s+install|brew\s+install)\s+/i,
|
|
93
|
+
action: 'warn',
|
|
94
|
+
reason: 'Package installation request — supply chain risk',
|
|
95
|
+
fix: 'Verify package name against typosquat and slopsquat databases before installing.',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'CAP.ACCESS_SECRETS',
|
|
99
|
+
severity: 'critical',
|
|
100
|
+
re: /(?:show|read|display|output|print|get|access|fetch|tell\s+me)\s+(?:me\s+)?(?:my\s+|the\s+|all\s+)?(?:secrets?|\.env|environment\s+variables?|API\s+keys?|tokens?|passwords?|credentials?|private\s+keys?)/i,
|
|
101
|
+
action: 'block',
|
|
102
|
+
reason: 'Secret access request: asking AI to reveal secrets or env vars',
|
|
103
|
+
fix: 'Never allow AI to access or reveal secrets. This is a data breach risk.',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'CAP.NETWORK_REQUEST',
|
|
107
|
+
severity: 'high',
|
|
108
|
+
re: /(?:fetch|curl|wget|http\.get|axios|request)\s+(?:https?:)?\/\//i,
|
|
109
|
+
action: 'warn',
|
|
110
|
+
reason: 'Network request in prompt — possible SSRF or data exfiltration',
|
|
111
|
+
fix: 'Verify the target URL. Block internal IPs and metadata services.',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'CAP.MODIFY_AUTH',
|
|
115
|
+
severity: 'critical',
|
|
116
|
+
re: /(?:change|modify|reset|bypass|disable|remove)\s+(?:the\s+)?(?:authentication|authorization|password|login|security|2fa|mfa|guard|middleware)/i,
|
|
117
|
+
action: 'block',
|
|
118
|
+
reason: 'Auth modification request: asking AI to disable or bypass security',
|
|
119
|
+
fix: 'Never allow AI to modify authentication or security controls.',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: 'CAP.DATABASE_DROP',
|
|
123
|
+
severity: 'critical',
|
|
124
|
+
re: /(?:drop|truncate|delete\s+from|wipe|clear)\s+(?:table|database|collection|all\s+data|production)/i,
|
|
125
|
+
action: 'block',
|
|
126
|
+
reason: 'Database destruction request: asking AI to drop/truncate tables',
|
|
127
|
+
fix: 'Never allow AI to drop tables or delete all data.',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: 'CAP.PRIVILEGE_ESCALATION',
|
|
131
|
+
severity: 'critical',
|
|
132
|
+
re: /(?:sudo|su\s+root|chmod\s+777|chown|admin\s+access|root\s+access|elevate|privilege\s+escalat)/i,
|
|
133
|
+
action: 'block',
|
|
134
|
+
reason: 'Privilege escalation request',
|
|
135
|
+
fix: 'Never allow AI to escalate privileges.',
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
// ─── Jailbreak Patterns ────────────────────────────────────────────
|
|
139
|
+
{
|
|
140
|
+
id: 'JAILBREAK.DAN',
|
|
141
|
+
severity: 'high',
|
|
142
|
+
re: /DAN|do\s+anything\s+now|jailbreak|developer\s+mode|unrestricted\s+mode|god\s+mode/i,
|
|
143
|
+
action: 'block',
|
|
144
|
+
reason: 'Jailbreak attempt: DAN or similar jailbreak pattern',
|
|
145
|
+
fix: 'This is a known jailbreak pattern. Block it.',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: 'JAILBREAK.HYPOTHETICAL',
|
|
149
|
+
severity: 'medium',
|
|
150
|
+
re: /(?:hypothetically|imagine|suppose|let'?s\s+pretend|in\s+a\s+fictional\s+world|for\s+educational\s+purposes?\s+only|theoretically)/i,
|
|
151
|
+
action: 'warn',
|
|
152
|
+
reason: 'Hypothetical framing — common jailbreak technique',
|
|
153
|
+
fix: 'Be cautious. Hypothetical framing is often used to bypass safety restrictions.',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: 'JAILBREAK.ROLEPLAY',
|
|
157
|
+
severity: 'medium',
|
|
158
|
+
re: /(?:roleplay|role.?play|act\s+out|pretend\s+you\s+are\s+(?:a\s+)?(?:hacker|attacker|malicious|unrestricted))/i,
|
|
159
|
+
action: 'warn',
|
|
160
|
+
reason: 'Roleplay framing — possible jailbreak attempt',
|
|
161
|
+
fix: 'Be cautious. Roleplay framing can be used to bypass safety restrictions.',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: 'JAILBREAK.TRANSITION',
|
|
165
|
+
severity: 'high',
|
|
166
|
+
re: /(?:now\s+that\s+we\s+(?:have|had)|switching\s+(?:to|gears)|moving\s+on\s+to|let'?s\s+(?:try|move|switch)\s+(?:to|something|a\s+different))/i,
|
|
167
|
+
action: 'warn',
|
|
168
|
+
reason: 'Topic transition — possible bait-and-switch jailbreak',
|
|
169
|
+
fix: 'Verify the new topic is not an attempt to bypass previous safety constraints.',
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
// ─── Data Exfiltration ─────────────────────────────────────────────
|
|
173
|
+
{
|
|
174
|
+
id: 'EXFIL.SEND_DATA',
|
|
175
|
+
severity: 'critical',
|
|
176
|
+
re: /(?:send|post|upload|transmit|exfiltrate|webhook|callback)\s+(?:the\s+)?(?:data|file|content|user\s+data|database|secrets?|tokens?)/i,
|
|
177
|
+
action: 'block',
|
|
178
|
+
reason: 'Data exfiltration: requesting AI to send data externally',
|
|
179
|
+
fix: 'Block this request. AI should never send user data to external endpoints.',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: 'EXFIL.SEND_TO_URL',
|
|
183
|
+
severity: 'critical',
|
|
184
|
+
re: /(?:send|post|upload)\s+(?:to|at|via)\s+(?:https?:)?\/\/[^.\s]+\.[^.\s]+/i,
|
|
185
|
+
action: 'block',
|
|
186
|
+
reason: 'Data exfiltration: specifying external URL to send data to',
|
|
187
|
+
fix: 'Block this request. This is data exfiltration to an external server.',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: 'EXFIL.BASE64_DATA',
|
|
191
|
+
severity: 'high',
|
|
192
|
+
re: /(?:base64\s+encode|btoa|encode)\s+(?:the\s+)?(?:data|file|secrets?|\.env|tokens?|passwords?)/i,
|
|
193
|
+
action: 'block',
|
|
194
|
+
reason: 'Data encoding for exfiltration: encoding secrets/data before sending',
|
|
195
|
+
fix: 'Block this request. This is preparing data for exfiltration.',
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
// ─── PII in Prompt ─────────────────────────────────────────────────
|
|
199
|
+
{
|
|
200
|
+
id: 'PII.IN_PROMPT',
|
|
201
|
+
severity: 'high',
|
|
202
|
+
re: null, // handled specially with detectPII
|
|
203
|
+
action: 'redact',
|
|
204
|
+
reason: 'PII detected in prompt — redacting before sending to AI',
|
|
205
|
+
fix: 'PII has been redacted. Review the redacted version before proceeding.',
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
// Action levels: block > redact > warn > allow
|
|
210
|
+
const ACTION_PRIORITY = { block: 4, redact: 3, warn: 2, allow: 1 };
|
|
211
|
+
|
|
212
|
+
function inspectPrompt(prompt, context = {}) {
|
|
213
|
+
const findings = [];
|
|
214
|
+
let sanitizedPrompt = prompt;
|
|
215
|
+
let maxAction = 'allow';
|
|
216
|
+
|
|
217
|
+
for (const threat of THREATS) {
|
|
218
|
+
// Handle PII specially
|
|
219
|
+
if (threat.id === 'PII.IN_PROMPT') {
|
|
220
|
+
const result = detectPII(prompt, { types: ['email', 'ssn', 'credit-card', 'phone'] });
|
|
221
|
+
const detected = result.matches || result || [];
|
|
222
|
+
if (detected.length > 0) {
|
|
223
|
+
sanitizedPrompt = redactText(prompt).redacted || redactText(prompt);
|
|
224
|
+
findings.push({
|
|
225
|
+
threat: threat.id,
|
|
226
|
+
severity: threat.severity,
|
|
227
|
+
action: 'redact',
|
|
228
|
+
reason: `PII detected (${detected.map(d => d.type).join(', ')}) — redacted before sending`,
|
|
229
|
+
fix: threat.fix,
|
|
230
|
+
});
|
|
231
|
+
if (ACTION_PRIORITY.redact > ACTION_PRIORITY[maxAction]) maxAction = 'redact';
|
|
232
|
+
}
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (threat.re && threat.re.test(prompt)) {
|
|
237
|
+
findings.push({
|
|
238
|
+
threat: threat.id,
|
|
239
|
+
severity: threat.severity,
|
|
240
|
+
action: threat.action,
|
|
241
|
+
reason: threat.reason,
|
|
242
|
+
fix: threat.fix,
|
|
243
|
+
});
|
|
244
|
+
if (ACTION_PRIORITY[threat.action] > ACTION_PRIORITY[maxAction]) {
|
|
245
|
+
maxAction = threat.action;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// If blocked, don't sanitize — return as-is with block verdict
|
|
251
|
+
if (maxAction === 'block') {
|
|
252
|
+
return {
|
|
253
|
+
action: 'block',
|
|
254
|
+
findings,
|
|
255
|
+
sanitizedPrompt: null,
|
|
256
|
+
reason: findings.find(f => f.action === 'block')?.reason || 'Request blocked by VibeGuard Firewall',
|
|
257
|
+
threatCount: findings.length,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// If redact, return sanitized prompt
|
|
262
|
+
if (maxAction === 'redact') {
|
|
263
|
+
return {
|
|
264
|
+
action: 'redact',
|
|
265
|
+
findings,
|
|
266
|
+
sanitizedPrompt,
|
|
267
|
+
reason: 'PII redacted from prompt',
|
|
268
|
+
threatCount: findings.length,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// If warn, return prompt with warnings
|
|
273
|
+
if (maxAction === 'warn') {
|
|
274
|
+
return {
|
|
275
|
+
action: 'warn',
|
|
276
|
+
findings,
|
|
277
|
+
sanitizedPrompt: prompt,
|
|
278
|
+
reason: `${findings.length} warning(s) — review before proceeding`,
|
|
279
|
+
threatCount: findings.length,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
action: 'allow',
|
|
285
|
+
findings: [],
|
|
286
|
+
sanitizedPrompt: prompt,
|
|
287
|
+
reason: 'No threats detected',
|
|
288
|
+
threatCount: 0,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Agent Guard — constrains what an AI agent can do
|
|
293
|
+
const AGENT_CONSTRAINTS = {
|
|
294
|
+
// File access
|
|
295
|
+
allowedPaths: ['src/', 'test/', 'public/', 'static/'],
|
|
296
|
+
blockedPaths: ['.env', '.env.*', '*.pem', '*.key', 'secrets/', '.aws/', '.ssh/', 'node_modules/', '.git/'],
|
|
297
|
+
// Command patterns
|
|
298
|
+
blockedCommands: ['rm -rf', 'sudo', 'chmod 777', 'curl', 'wget', 'nc ', 'netcat', 'mkfs', 'dd if=', 'shutdown', 'reboot'],
|
|
299
|
+
// Network access
|
|
300
|
+
blockedDomains: ['169.254.169.254', 'localhost', '127.0.0.1', '0.0.0.0'],
|
|
301
|
+
// Resource limits
|
|
302
|
+
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
303
|
+
maxExecTime: 30000, // 30s
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
function checkAgentAction(action) {
|
|
307
|
+
const violations = [];
|
|
308
|
+
|
|
309
|
+
// Check file access
|
|
310
|
+
if (action.type === 'file_read' || action.type === 'file_write' || action.type === 'file_delete') {
|
|
311
|
+
const filePath = action.path || '';
|
|
312
|
+
for (const blocked of AGENT_CONSTRAINTS.blockedPaths) {
|
|
313
|
+
const re = new RegExp(blocked.replace(/\./g, '\\.').replace(/\*/g, '.*'));
|
|
314
|
+
if (re.test(filePath)) {
|
|
315
|
+
violations.push({
|
|
316
|
+
type: 'blocked_path',
|
|
317
|
+
severity: 'critical',
|
|
318
|
+
message: `Agent attempting to access blocked path: ${filePath} (matches: ${blocked})`,
|
|
319
|
+
action: 'block',
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Check command execution
|
|
326
|
+
if (action.type === 'exec') {
|
|
327
|
+
const cmd = action.command || '';
|
|
328
|
+
for (const blocked of AGENT_CONSTRAINTS.blockedCommands) {
|
|
329
|
+
if (cmd.includes(blocked)) {
|
|
330
|
+
violations.push({
|
|
331
|
+
type: 'blocked_command',
|
|
332
|
+
severity: 'critical',
|
|
333
|
+
message: `Agent attempting to run blocked command: ${cmd} (contains: ${blocked})`,
|
|
334
|
+
action: 'block',
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Check network access
|
|
341
|
+
if (action.type === 'network') {
|
|
342
|
+
const url = action.url || '';
|
|
343
|
+
for (const blocked of AGENT_CONSTRAINTS.blockedDomains) {
|
|
344
|
+
if (url.includes(blocked)) {
|
|
345
|
+
violations.push({
|
|
346
|
+
type: 'blocked_domain',
|
|
347
|
+
severity: 'critical',
|
|
348
|
+
message: `Agent attempting to access blocked domain: ${url} (contains: ${blocked})`,
|
|
349
|
+
action: 'block',
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
allowed: violations.filter(v => v.action === 'block').length === 0,
|
|
357
|
+
violations,
|
|
358
|
+
constraints: AGENT_CONSTRAINTS,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Exfiltration Firewall — checks if outbound data contains PII/secrets
|
|
363
|
+
function checkExfiltration(data, destination) {
|
|
364
|
+
const risks = [];
|
|
365
|
+
|
|
366
|
+
// Check for PII in the data
|
|
367
|
+
const piiResult = detectPII(data, { types: ['email', 'ssn', 'credit-card', 'phone', 'aws-access-key', 'jwt', 'private-key'] });
|
|
368
|
+
const pii = piiResult.matches || piiResult || [];
|
|
369
|
+
if (pii.length > 0) {
|
|
370
|
+
risks.push({
|
|
371
|
+
type: 'pii_in_data',
|
|
372
|
+
severity: 'critical',
|
|
373
|
+
message: `Outbound data contains PII: ${pii.map(p => p.type).join(', ')}`,
|
|
374
|
+
action: 'block',
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Check for secrets in the data
|
|
379
|
+
const secretPatterns = [
|
|
380
|
+
{ re: /sk-proj-[A-Za-z0-9_-]{20,}/, type: 'OpenAI key' },
|
|
381
|
+
{ re: /sk-ant-[A-Za-z0-9_-]{50,}/, type: 'Anthropic key' },
|
|
382
|
+
{ re: /sk_live_[A-Za-z0-9]{16,}/, type: 'Stripe key' },
|
|
383
|
+
{ re: /AKIA[A-Z0-9]{16}/, type: 'AWS key' },
|
|
384
|
+
{ re: /gh[pousr]_[A-Za-z0-9]{36}/, type: 'GitHub token' },
|
|
385
|
+
{ re: /-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/, type: 'Private key' },
|
|
386
|
+
];
|
|
387
|
+
for (const { re, type } of secretPatterns) {
|
|
388
|
+
if (re.test(data)) {
|
|
389
|
+
risks.push({
|
|
390
|
+
type: 'secret_in_data',
|
|
391
|
+
severity: 'critical',
|
|
392
|
+
message: `Outbound data contains ${type}`,
|
|
393
|
+
action: 'block',
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Check destination
|
|
399
|
+
if (destination) {
|
|
400
|
+
const blockedDestinations = ['169.254.169.254', 'metadata.google.internal'];
|
|
401
|
+
for (const blocked of blockedDestinations) {
|
|
402
|
+
if (destination.includes(blocked)) {
|
|
403
|
+
risks.push({
|
|
404
|
+
type: 'blocked_destination',
|
|
405
|
+
severity: 'critical',
|
|
406
|
+
message: `Data being sent to cloud metadata service: ${destination}`,
|
|
407
|
+
action: 'block',
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
allowed: risks.filter(r => r.action === 'block').length === 0,
|
|
415
|
+
risks,
|
|
416
|
+
sanitizedData: risks.some(r => r.type === 'pii_in_data') ? (redactText(data).redacted || redactText(data)) : data,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Dependency Firewall — checks package names before npm install
|
|
421
|
+
const MALICIOUS_PACKAGE_PATTERNS = [
|
|
422
|
+
{ re: /(?:cryptominer|xmrig|coinhive|crypto-?loot)/i, reason: 'Known crypto miner package' },
|
|
423
|
+
{ re: /(?:stealer|exfil|backdoor|trojan|keylog|botnet|ratware)/i, reason: 'Malware package name' },
|
|
424
|
+
{ re: /(?:hack|crack|pirate|warez|serial|keygen)/i, reason: 'Piracy tool package' },
|
|
425
|
+
];
|
|
426
|
+
|
|
427
|
+
const TYPOSQUAT_MAP = {
|
|
428
|
+
'reactt': 'react', 'reacct': 'react', 'lodahs': 'lodash', 'loadash': 'lodash',
|
|
429
|
+
'expres': 'express', 'exress': 'express', 'axioss': 'axios',
|
|
430
|
+
'mognoose': 'mongoose', 'mongose': 'mongoose', 'moongose': 'mongoose',
|
|
431
|
+
'nextt': 'next', 'vuue': 'vue', 'angullar': 'angular',
|
|
432
|
+
'sveltte': 'svelte', 'tailwindcsss': 'tailwindcss',
|
|
433
|
+
'dottie': 'dotenv', 'envee': 'dotenv',
|
|
434
|
+
'chalkk': 'chalk', 'momment': 'moment',
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
function checkPackage(name) {
|
|
438
|
+
const risks = [];
|
|
439
|
+
|
|
440
|
+
// Check for malicious package names
|
|
441
|
+
for (const { re, reason } of MALICIOUS_PACKAGE_PATTERNS) {
|
|
442
|
+
if (re.test(name)) {
|
|
443
|
+
risks.push({ type: 'malicious', severity: 'critical', message: reason, action: 'block' });
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Check for typosquats
|
|
448
|
+
const lower = name.toLowerCase();
|
|
449
|
+
if (TYPOSQUAT_MAP[lower]) {
|
|
450
|
+
risks.push({
|
|
451
|
+
type: 'typosquat',
|
|
452
|
+
severity: 'high',
|
|
453
|
+
message: `Possible typosquat of "${TYPOSQUAT_MAP[lower]}" — did you mean "${TYPOSQUAT_MAP[lower]}"?`,
|
|
454
|
+
action: 'warn',
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Check for suspicious patterns
|
|
459
|
+
if (/^[a-z]{1,2}$/.test(lower)) {
|
|
460
|
+
risks.push({ type: 'suspicious_short', severity: 'medium', message: 'Very short package name — common in typosquatting', action: 'warn' });
|
|
461
|
+
}
|
|
462
|
+
if (/[0-9]$/.test(lower) && !/(?:[a-z]2[a-z]|es[0-9]|v[0-9])/i.test(lower)) {
|
|
463
|
+
risks.push({ type: 'suspicious_number_suffix', severity: 'low', message: 'Package name ends with number — verify legitimacy', action: 'warn' });
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
packageName: name,
|
|
468
|
+
allowed: risks.filter(r => r.action === 'block').length === 0,
|
|
469
|
+
risks,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function renderFirewallReport(verdict) {
|
|
474
|
+
const C = {
|
|
475
|
+
red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
|
|
476
|
+
cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m',
|
|
477
|
+
};
|
|
478
|
+
const actionColor = { block: C.red, redact: C.yellow, warn: C.yellow, allow: C.green };
|
|
479
|
+
const color = actionColor[verdict.action] || C.white;
|
|
480
|
+
const lines = [
|
|
481
|
+
`${C.bold}VibeGuard AI Firewall${C.reset}`,
|
|
482
|
+
`${C.dim}${'─'.repeat(60)}${C.reset}`,
|
|
483
|
+
'',
|
|
484
|
+
` Action: ${color}${C.bold}${verdict.action.toUpperCase()}${C.reset}`,
|
|
485
|
+
` Threats: ${verdict.threatCount}`,
|
|
486
|
+
` Reason: ${verdict.reason}`,
|
|
487
|
+
'',
|
|
488
|
+
];
|
|
489
|
+
if (verdict.findings.length > 0) {
|
|
490
|
+
lines.push(`${C.bold}Threats Detected${C.reset}`);
|
|
491
|
+
for (const f of verdict.findings) {
|
|
492
|
+
const sc = f.severity === 'critical' ? C.red : f.severity === 'high' ? C.yellow : C.dim;
|
|
493
|
+
lines.push(` ${sc}[${f.severity}]${C.reset} ${f.threat} — ${f.action}`);
|
|
494
|
+
lines.push(` ${f.reason}`);
|
|
495
|
+
lines.push(` ${C.green}fix:${C.reset} ${f.fix}`);
|
|
496
|
+
lines.push('');
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (verdict.sanitizedPrompt && verdict.action === 'redact') {
|
|
500
|
+
lines.push(`${C.dim}Sanitized prompt:${C.reset}`);
|
|
501
|
+
lines.push(` ${verdict.sanitizedPrompt.slice(0, 200)}`);
|
|
502
|
+
lines.push('');
|
|
503
|
+
}
|
|
504
|
+
return lines.join('\n');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
module.exports = {
|
|
508
|
+
inspectPrompt,
|
|
509
|
+
checkAgentAction,
|
|
510
|
+
checkExfiltration,
|
|
511
|
+
checkPackage,
|
|
512
|
+
renderFirewallReport,
|
|
513
|
+
THREATS,
|
|
514
|
+
AGENT_CONSTRAINTS,
|
|
515
|
+
TYPOSQUAT_MAP,
|
|
516
|
+
MALICIOUS_PACKAGE_PATTERNS,
|
|
517
|
+
};
|
package/src/history.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Git-history secret scan.
|
|
5
|
+
*
|
|
6
|
+
* A secret committed then "removed" still lives in git history and is
|
|
7
|
+
* compromised. This walks recent history (`git log -p`) and runs the secret
|
|
8
|
+
* rules over ADDED lines, reporting the commit where each secret was introduced.
|
|
9
|
+
*
|
|
10
|
+
* Non-fatal: not a git repo / no git = empty result with a note.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { execSync, execFileSync } = require('child_process');
|
|
14
|
+
const { secretRules, matchAll } = require('./rules');
|
|
15
|
+
|
|
16
|
+
const isWin = process.platform === 'win32';
|
|
17
|
+
|
|
18
|
+
function git(args, cwd) {
|
|
19
|
+
const opts = { cwd, timeout: 120000, maxBuffer: 128 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true };
|
|
20
|
+
return (isWin ? execSync(['git', ...args].join(' '), opts) : execFileSync('git', args, opts)).toString('utf8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function scanHistory(root, opts = {}) {
|
|
24
|
+
// Default: recent 500 commits (fast). opts.all -> full history, every branch.
|
|
25
|
+
const args = ['log', '-p', '--no-color'];
|
|
26
|
+
if (opts.all) args.push('--all');
|
|
27
|
+
else args.push(`--max-count=${opts.maxCount || 500}`);
|
|
28
|
+
args.push('--', '.');
|
|
29
|
+
let out;
|
|
30
|
+
try {
|
|
31
|
+
out = git(args, root);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return { findings: [], ran: false, note: `git history unavailable (${err.code || err.message})` };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const findings = [];
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
let commit = '';
|
|
39
|
+
let file = '';
|
|
40
|
+
let addedLineNo = 0;
|
|
41
|
+
|
|
42
|
+
for (const raw of out.split('\n')) {
|
|
43
|
+
if (raw.startsWith('commit ')) {
|
|
44
|
+
commit = raw.slice(7, 17);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (raw.startsWith('+++ b/')) {
|
|
48
|
+
file = raw.slice(6);
|
|
49
|
+
addedLineNo = 0;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const hunk = /^@@ .*\+(\d+)/.exec(raw);
|
|
53
|
+
if (hunk) {
|
|
54
|
+
addedLineNo = parseInt(hunk[1], 10) - 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (raw.startsWith('+') && !raw.startsWith('+++')) {
|
|
58
|
+
addedLineNo++;
|
|
59
|
+
const line = raw.slice(1);
|
|
60
|
+
for (const rule of secretRules) {
|
|
61
|
+
for (const hit of matchAll(rule.re, line)) {
|
|
62
|
+
if (rule.filter && !rule.filter(line, hit)) continue;
|
|
63
|
+
const key = `${rule.id}:${file}:${hit.match.slice(0, 12)}`;
|
|
64
|
+
if (seen.has(key)) continue;
|
|
65
|
+
seen.add(key);
|
|
66
|
+
findings.push({
|
|
67
|
+
ruleId: `history.${rule.id}`,
|
|
68
|
+
severity: 'critical',
|
|
69
|
+
confidence: 'high',
|
|
70
|
+
title: `Secret in git history: ${rule.title}`,
|
|
71
|
+
message: `${rule.message} Found in commit ${commit} (${file}). It remains in history even if later removed — treat as compromised.`,
|
|
72
|
+
fix: `Rotate the secret now, then purge it from history (git filter-repo / BFG) and force-push.`,
|
|
73
|
+
file,
|
|
74
|
+
line: addedLineNo,
|
|
75
|
+
column: hit.index + 1,
|
|
76
|
+
snippet: `${commit} ${hit.match.slice(0, 4)}****`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} else if (raw.startsWith(' ')) {
|
|
81
|
+
addedLineNo++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { findings, ran: true, note: null };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { scanHistory };
|