@yagyeshvyas/vibeguard 1.1.0 → 1.2.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/CHANGELOG.md +57 -0
- package/README.md +564 -499
- package/bin/cli.js +91 -3
- package/package.json +4 -3
- package/src/action-guard.js +220 -0
- package/src/agent-scan.js +192 -0
- package/src/integrity.js +74 -0
- package/src/integrity.json +22 -0
- package/src/interceptor.js +42 -7
- package/src/mcp-audit.js +245 -0
- package/src/mcp-server.js +70 -0
package/bin/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ const {
|
|
|
23
23
|
} = require('../src/report');
|
|
24
24
|
|
|
25
25
|
// Flags that take a value (support both --flag=value and --flag value).
|
|
26
|
-
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence']);
|
|
26
|
+
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence', 'trust']);
|
|
27
27
|
|
|
28
28
|
function parseArgs(argv) {
|
|
29
29
|
const args = { _: [], flags: {} };
|
|
@@ -77,6 +77,9 @@ Advanced:
|
|
|
77
77
|
vibeguard url <url> Scan a live site's HTTP headers.
|
|
78
78
|
vibeguard badge [dir] Award badge SVG (zero critical+high).
|
|
79
79
|
vibeguard init-ci [dir] Write GitHub Actions workflow.
|
|
80
|
+
vibeguard mcp-audit [dir] Audit configured MCP servers (injection, rug-pull, secrets). --pin to re-baseline.
|
|
81
|
+
vibeguard agent-scan [dir] AI Agent Security Posture: one grade across MCP, data leakage, LLM-output sinks, prompt injection, agent capability.
|
|
82
|
+
vibeguard guard-action <action> Action firewall: block secret/PII exfiltration before it runs. Pass a shell command or JSON action. --trust host1,host2.
|
|
80
83
|
vibeguard compliance [dir] Map findings to SOC2/PCI/HIPAA/GDPR.
|
|
81
84
|
vibeguard cve [dir] Query OSV.dev for dependency CVEs.
|
|
82
85
|
vibeguard slopsquat [dir] Check for hallucinated npm packages.
|
|
@@ -680,6 +683,70 @@ function cmdInitCi(dir) {
|
|
|
680
683
|
return 0;
|
|
681
684
|
}
|
|
682
685
|
|
|
686
|
+
function cmdGuardAction(input, flags) {
|
|
687
|
+
const { inspectAction } = require('../src/action-guard');
|
|
688
|
+
// Accept a JSON action ('{"type":"network",...}') or, for convenience, a bare
|
|
689
|
+
// shell command string.
|
|
690
|
+
let action;
|
|
691
|
+
const raw = (input || '').trim();
|
|
692
|
+
if (raw.startsWith('{')) {
|
|
693
|
+
try { action = JSON.parse(raw); } catch { process.stderr.write('Invalid JSON action.\n'); return 2; }
|
|
694
|
+
} else if (raw) {
|
|
695
|
+
action = { type: 'shell', command: raw };
|
|
696
|
+
} else {
|
|
697
|
+
process.stderr.write('Usage: vibeguard guard-action \'<json-action>\' | "<shell command>"\n');
|
|
698
|
+
return 2;
|
|
699
|
+
}
|
|
700
|
+
const trustedHosts = flags.trust ? String(flags.trust).split(',') : [];
|
|
701
|
+
const verdict = inspectAction(action, { trustedHosts });
|
|
702
|
+
if (flags.json) {
|
|
703
|
+
process.stdout.write(JSON.stringify(verdict, null, 2) + '\n');
|
|
704
|
+
} else {
|
|
705
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', reset: '\x1b[0m' };
|
|
706
|
+
const tag = verdict.blocked ? `${C2.red}BLOCKED${C2.reset}` : verdict.action === 'warn' ? `${C2.yellow}WARN${C2.reset}` : `${C2.green}ALLOW${C2.reset}`;
|
|
707
|
+
process.stdout.write(`${tag} ${verdict.reason || 'no leak or dangerous action detected'}\n`);
|
|
708
|
+
for (const v of verdict.violations) process.stdout.write(` ${C2.dim}${v.level}: ${v.kind} — ${v.detail}${C2.reset}\n`);
|
|
709
|
+
}
|
|
710
|
+
return verdict.blocked ? 1 : 0;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function cmdAgentScan(dir, flags) {
|
|
714
|
+
const { agentScan, renderAgentScan } = require('../src/agent-scan');
|
|
715
|
+
const result = agentScan(dir, { pin: !!flags.pin });
|
|
716
|
+
if (flags.json) {
|
|
717
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
718
|
+
} else {
|
|
719
|
+
process.stdout.write(renderAgentScan(result) + '\n');
|
|
720
|
+
}
|
|
721
|
+
// Fail on critical by default; --fail-on <level> to tune.
|
|
722
|
+
if (flags['fail-on']) {
|
|
723
|
+
const order = ['critical', 'high', 'medium', 'low'];
|
|
724
|
+
const t = order.indexOf(String(flags['fail-on']).toLowerCase());
|
|
725
|
+
const worst = result.items.reduce((a, it) => Math.min(a, order.indexOf(it.severity)), 4);
|
|
726
|
+
return t !== -1 && worst <= t ? 1 : 0;
|
|
727
|
+
}
|
|
728
|
+
return result.counts.critical > 0 ? 1 : 0;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function cmdMcpAudit(dir, flags) {
|
|
732
|
+
const { auditMcp, renderMcpAudit } = require('../src/mcp-audit');
|
|
733
|
+
const result = auditMcp(dir, { pin: !!flags.pin });
|
|
734
|
+
if (flags.json) {
|
|
735
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
736
|
+
} else {
|
|
737
|
+
process.stdout.write(renderMcpAudit(result) + '\n');
|
|
738
|
+
}
|
|
739
|
+
if (!result.configFound) return 0;
|
|
740
|
+
// Fail on critical (blockable in CI), like the scan gate.
|
|
741
|
+
if (flags['fail-on']) {
|
|
742
|
+
const order = ['critical', 'high', 'medium', 'low'];
|
|
743
|
+
const t = order.indexOf(String(flags['fail-on']).toLowerCase());
|
|
744
|
+
const worst = result.findings.reduce((a, f) => Math.min(a, order.indexOf(f.severity)), 4);
|
|
745
|
+
return t !== -1 && worst <= t ? 1 : 0;
|
|
746
|
+
}
|
|
747
|
+
return result.counts.critical > 0 ? 1 : 0;
|
|
748
|
+
}
|
|
749
|
+
|
|
683
750
|
function cmdInstallHook(dir) {
|
|
684
751
|
const root = path.resolve(dir);
|
|
685
752
|
const gitDir = path.join(root, '.git');
|
|
@@ -755,7 +822,7 @@ async function main() {
|
|
|
755
822
|
const cmd = args._[0] || 'scan';
|
|
756
823
|
const dir = args._[1] || '.';
|
|
757
824
|
|
|
758
|
-
const noDirCmds = new Set(['url', 'rules', 'explain', 'secure-prompt', 'redact', 'detect-pii', 'firewall', 'exfil-check', 'dep-firewall', 'sandbox', 'output-guard', 'vault', 'audit-trail', 'why', 'guard', 'install-shell-hook', 'uninstall-shell-hook', 'auto-start', 'auto-stop', 'auto-status', 'auto']);
|
|
825
|
+
const noDirCmds = new Set(['url', 'rules', 'explain', 'secure-prompt', 'redact', 'detect-pii', 'firewall', 'exfil-check', 'dep-firewall', 'sandbox', 'output-guard', 'vault', 'audit-trail', 'why', 'guard', 'guard-action', 'install-shell-hook', 'uninstall-shell-hook', 'auto-start', 'auto-stop', 'auto-status', 'auto']);
|
|
759
826
|
if (!noDirCmds.has(cmd) && !fs.existsSync(dir)) {
|
|
760
827
|
process.stderr.write(`error: directory not found: ${dir}\n`);
|
|
761
828
|
process.exit(2);
|
|
@@ -824,6 +891,9 @@ async function main() {
|
|
|
824
891
|
else if (cmd === 'history') code = cmdHistory(dir, flags);
|
|
825
892
|
else if (cmd === 'badge') code = cmdBadge(dir, flags);
|
|
826
893
|
else if (cmd === 'init-ci') code = cmdInitCi(dir);
|
|
894
|
+
else if (cmd === 'mcp-audit') code = cmdMcpAudit(dir, flags);
|
|
895
|
+
else if (cmd === 'agent-scan') code = cmdAgentScan(dir, flags);
|
|
896
|
+
else if (cmd === 'guard-action') code = cmdGuardAction(args._[1], flags);
|
|
827
897
|
else if (cmd === 'install') code = cmdInstall(flags);
|
|
828
898
|
else if (cmd === 'rules') code = cmdRules(flags);
|
|
829
899
|
else if (cmd === 'explain') code = cmdExplain(args._[1], flags);
|
|
@@ -1410,8 +1480,26 @@ function cmdSelfCheck(dir, flags) {
|
|
|
1410
1480
|
if (fs.existsSync(gi) && /\.env/.test(fs.readFileSync(gi, 'utf8'))) checks.push(` ${C2.green}PASS${C.reset} .env in .gitignore`);
|
|
1411
1481
|
else { checks.push(` ${C2.red}FAIL${C.reset} .env NOT in .gitignore`); ok = false; }
|
|
1412
1482
|
|
|
1483
|
+
// Cryptographic content integrity — detects a patched/neutered guard that a
|
|
1484
|
+
// load-only check would miss.
|
|
1485
|
+
try {
|
|
1486
|
+
const { verifyIntegrity } = require('../src/integrity');
|
|
1487
|
+
const iv = verifyIntegrity(path.join(__dirname, '..', 'src'));
|
|
1488
|
+
if (!iv.available) {
|
|
1489
|
+
checks.push(` ${C2.dim}INFO Integrity manifest not present (run: node scripts/gen-integrity.js)${C.reset}`);
|
|
1490
|
+
} else if (iv.intact) {
|
|
1491
|
+
checks.push(` ${C2.green}PASS${C.reset} Content integrity verified (${iv.checked} security modules, sha256)`);
|
|
1492
|
+
} else {
|
|
1493
|
+
ok = false;
|
|
1494
|
+
if (iv.modified.length) checks.push(` ${C2.red}FAIL${C.reset} TAMPERED — modified: ${iv.modified.join(', ')}`);
|
|
1495
|
+
if (iv.missing.length) checks.push(` ${C2.red}FAIL${C.reset} MISSING — ${iv.missing.join(', ')}`);
|
|
1496
|
+
}
|
|
1497
|
+
} catch (e) {
|
|
1498
|
+
checks.push(` ${C2.yellow}WARN${C.reset} Integrity check failed to run: ${e.message}`);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1413
1501
|
for (const c of checks) process.stdout.write(c + '\n');
|
|
1414
|
-
process.stdout.write(`\n${ok ? C2.green + C2.bold + 'VibeGuard is intact.' : C2.
|
|
1502
|
+
process.stdout.write(`\n${ok ? C2.green + C2.bold + 'VibeGuard is intact.' : C2.red + C2.bold + 'INTEGRITY / SECURITY CHECK FAILED — do not trust this install.'}${C.reset}\n`);
|
|
1415
1503
|
return ok ? 0 : 1;
|
|
1416
1504
|
}
|
|
1417
1505
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yagyeshvyas/vibeguard",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Security scanner + AI agent firewall. Blocks secret/PII exfiltration in real time. 699 rules, 78 MCP tools (agent-scan, mcp-audit, guard-action), AST taint analysis. Offline, zero telemetry, zero dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"author": "Yagyesh Vyas <https://www.linkedin.com/in/yagyeshvyas/>",
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
"coverage": "c8 node test/run.js",
|
|
34
34
|
"counts": "node scripts/counts.js",
|
|
35
35
|
"benchmark": "node test/benchmark/run.js",
|
|
36
|
+
"integrity": "node scripts/gen-integrity.js",
|
|
36
37
|
"postinstall": "node scripts/postinstall.js",
|
|
37
|
-
"prepublishOnly": "node test/run.js && npm run lint"
|
|
38
|
+
"prepublishOnly": "node scripts/gen-integrity.js && node test/run.js && npm run lint"
|
|
38
39
|
},
|
|
39
40
|
"keywords": [
|
|
40
41
|
"security",
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* src/action-guard.js — Agent Action Firewall.
|
|
5
|
+
*
|
|
6
|
+
* The real-time "nothing leaks" guard. Inspects an agent action BEFORE it runs
|
|
7
|
+
* and blocks it if it would exfiltrate secrets or personal data, run a
|
|
8
|
+
* dangerous command, or send sensitive data to an untrusted destination.
|
|
9
|
+
*
|
|
10
|
+
* One inspection API over every action an agent can take:
|
|
11
|
+
* { type: 'shell', command }
|
|
12
|
+
* { type: 'network', url, body?, method? }
|
|
13
|
+
* { type: 'file-write', path, content }
|
|
14
|
+
* { type: 'prompt', content, provider? } // text going to an LLM
|
|
15
|
+
* { type: 'mcp', tool, args } // an MCP tool call
|
|
16
|
+
*
|
|
17
|
+
* Core guarantee (best-effort, not a sandbox): a hardcoded API key or a piece
|
|
18
|
+
* of personal data (email, SSN, credit card, phone) MUST NOT leave the machine
|
|
19
|
+
* to an external host without an explicit allow. Secrets to any external
|
|
20
|
+
* destination are BLOCKED, unconditionally.
|
|
21
|
+
*
|
|
22
|
+
* 100% local. Zero network. Zero dependencies. Fail-closed on the block path.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const { checkCommand, SECRET_PATTERNS } = require('./shell-guard');
|
|
26
|
+
const { detectPII, redactText } = require('./pii');
|
|
27
|
+
|
|
28
|
+
// Hosts that are the local machine or a private network — sending data there is
|
|
29
|
+
// not exfiltration off the box.
|
|
30
|
+
const LOCAL_HOST_RE = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|::1|\[::1\])$/i;
|
|
31
|
+
const PRIVATE_IP_RE = /^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.)/;
|
|
32
|
+
// Cloud metadata endpoints — credential theft targets, ALWAYS untrusted.
|
|
33
|
+
const METADATA_HOST_RE = /^(?:169\.254\.169\.254|metadata\.google\.internal|metadata\.goog)$/i;
|
|
34
|
+
|
|
35
|
+
function hostOf(url) {
|
|
36
|
+
if (typeof url !== 'string') return null;
|
|
37
|
+
const m = url.match(/^[a-z][a-z0-9+.-]*:\/\/([^/?#]+)/i);
|
|
38
|
+
if (!m) return null;
|
|
39
|
+
return m[1].replace(/:\d+$/, '').toLowerCase(); // strip port
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isExternalHost(host) {
|
|
43
|
+
if (!host) return false;
|
|
44
|
+
if (METADATA_HOST_RE.test(host)) return true; // metadata = worst-case external
|
|
45
|
+
if (LOCAL_HOST_RE.test(host)) return false;
|
|
46
|
+
if (PRIVATE_IP_RE.test(host)) return false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Shannon entropy in bits/char — high for random secrets, low for words/ids.
|
|
51
|
+
function shannonEntropy(s) {
|
|
52
|
+
const freq = Object.create(null);
|
|
53
|
+
for (const c of s) freq[c] = (freq[c] || 0) + 1;
|
|
54
|
+
let e = 0;
|
|
55
|
+
for (const k in freq) { const p = freq[k] / s.length; e -= p * Math.log2(p); }
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// A value that is structured, not a secret — don't treat these as unknown keys.
|
|
60
|
+
function looksStructured(v) {
|
|
61
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v)) return true; // UUID
|
|
62
|
+
if (/^[0-9a-f]+$/i.test(v) && [32, 40, 64].includes(v.length)) return true; // md5/sha1/sha256 hash
|
|
63
|
+
if (/^\d+$/.test(v)) return true; // pure number / id
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// A field NAMED like a credential carrying a high-entropy value = a secret, even
|
|
68
|
+
// if it matches no known vendor pattern. Precise: the secret-ish NAME plus real
|
|
69
|
+
// entropy avoids flagging random hashes/ids that aren't labelled secrets.
|
|
70
|
+
// High-confidence credential field names only. Deliberately excludes ambiguous
|
|
71
|
+
// names (token, bearer, session, auth) that are commonly legitimate auth values
|
|
72
|
+
// sent to APIs — those would false-positive and break real traffic. Known vendor
|
|
73
|
+
// key formats (sk_live_, ghp_, …) are still caught by SECRET_PATTERNS regardless
|
|
74
|
+
// of field name.
|
|
75
|
+
const NAMED_SECRET_RE =
|
|
76
|
+
/["']?([\w-]*(?:api[_-]?key|secret|private[_-]?key|access[_-]?key|password|passwd|credential)[\w-]*)["']?\s*[:=]\s*["']?([A-Za-z0-9+/=_.\-]{12,})["']?/gi;
|
|
77
|
+
|
|
78
|
+
function findNamedSecrets(text) {
|
|
79
|
+
const out = [];
|
|
80
|
+
let m;
|
|
81
|
+
NAMED_SECRET_RE.lastIndex = 0;
|
|
82
|
+
while ((m = NAMED_SECRET_RE.exec(text)) !== null) {
|
|
83
|
+
const name = m[1];
|
|
84
|
+
const val = m[2];
|
|
85
|
+
if (looksStructured(val)) continue;
|
|
86
|
+
// Env-var references / placeholders are not real values.
|
|
87
|
+
if (/^(?:process\.env|import\.meta|os\.environ|\$\{|xxx|changeme|your[_-]?)/i.test(val)) continue;
|
|
88
|
+
if (shannonEntropy(val) < 3.2) continue; // low entropy → likely not a secret
|
|
89
|
+
out.push(name);
|
|
90
|
+
}
|
|
91
|
+
return [...new Set(out)];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Find secrets + PII in any outbound string.
|
|
95
|
+
function scanForLeaks(text) {
|
|
96
|
+
const out = { secrets: [], pii: [], namedSecrets: [] };
|
|
97
|
+
if (!text || typeof text !== 'string') return out;
|
|
98
|
+
for (const { re, type } of SECRET_PATTERNS) {
|
|
99
|
+
if (re.test(text)) out.secrets.push(type);
|
|
100
|
+
}
|
|
101
|
+
out.secrets = [...new Set(out.secrets)];
|
|
102
|
+
const pii = detectPII(text, {});
|
|
103
|
+
out.pii = pii.types || [];
|
|
104
|
+
out.namedSecrets = findNamedSecrets(text);
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const RANK = { block: 2, warn: 1, allow: 0 };
|
|
109
|
+
|
|
110
|
+
// Inspect a single action. `policy.trustedHosts` (array) explicitly allows
|
|
111
|
+
// sending sensitive data to those hosts (e.g. your own API). `policy.piiMode`
|
|
112
|
+
// = 'block' (default for external) or 'warn'.
|
|
113
|
+
function inspectAction(action = {}, policy = {}) {
|
|
114
|
+
const trusted = new Set((policy.trustedHosts || []).map((h) => String(h).toLowerCase()));
|
|
115
|
+
const piiMode = policy.piiMode === 'warn' ? 'warn' : 'block';
|
|
116
|
+
const type = action.type || 'generic';
|
|
117
|
+
const violations = [];
|
|
118
|
+
const add = (level, kind, detail) => violations.push({ level, kind, detail });
|
|
119
|
+
|
|
120
|
+
const leakToDest = (text, host, destLabel) => {
|
|
121
|
+
// External = off this machine AND not on the caller's explicit allowlist.
|
|
122
|
+
const external = isExternalHost(host) && !trusted.has(host);
|
|
123
|
+
if (!external) return;
|
|
124
|
+
const { secrets, pii, namedSecrets } = scanForLeaks(text);
|
|
125
|
+
if (secrets.length) {
|
|
126
|
+
add('block', 'secret-exfiltration', `${secrets.join(', ')} would be sent to ${destLabel}`);
|
|
127
|
+
}
|
|
128
|
+
if (namedSecrets.length) {
|
|
129
|
+
add('block', 'named-secret-exfiltration', `credential field(s) ${namedSecrets.join(', ')} (high-entropy value) would be sent to ${destLabel}`);
|
|
130
|
+
}
|
|
131
|
+
if (pii.length) {
|
|
132
|
+
add(piiMode, 'pii-exfiltration', `personal data (${pii.join(', ')}) would be sent to ${destLabel}`);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
switch (type) {
|
|
137
|
+
case 'shell': {
|
|
138
|
+
const r = checkCommand(action.command || '');
|
|
139
|
+
if (r.blocked) {
|
|
140
|
+
// checkCommand already covers rm -rf, secret exfil, sensitive paths, etc.
|
|
141
|
+
const sev = r.severity === 'critical' ? 'block' : 'block';
|
|
142
|
+
add(sev, r.violations && r.violations[0] ? r.violations[0].type : 'dangerous-command', r.reason);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'network': {
|
|
147
|
+
const host = hostOf(action.url);
|
|
148
|
+
const dest = host || action.url || 'an external host';
|
|
149
|
+
// The URL itself can carry a secret (?token=...) or PII.
|
|
150
|
+
leakToDest(String(action.url || ''), host, dest);
|
|
151
|
+
leakToDest(typeof action.body === 'string' ? action.body : JSON.stringify(action.body || ''), host, dest);
|
|
152
|
+
if (host && METADATA_HOST_RE.test(host)) {
|
|
153
|
+
add('block', 'metadata-access', `request to cloud metadata endpoint ${host} — credential theft`);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case 'file-write': {
|
|
158
|
+
const { secrets, pii } = scanForLeaks(String(action.content || ''));
|
|
159
|
+
const p = String(action.path || '');
|
|
160
|
+
const publicPath = /(?:^|\/)(?:public|static|dist|www|build)\//i.test(p);
|
|
161
|
+
if (secrets.length && publicPath) {
|
|
162
|
+
add('block', 'secret-to-public-file', `${secrets.join(', ')} written to a web-served path (${p})`);
|
|
163
|
+
} else if (secrets.length) {
|
|
164
|
+
add('warn', 'secret-in-file', `${secrets.join(', ')} written to ${p} — ensure it is gitignored and not shipped`);
|
|
165
|
+
}
|
|
166
|
+
if (pii.length && publicPath) {
|
|
167
|
+
add('block', 'pii-to-public-file', `personal data (${pii.join(', ')}) written to a web-served path (${p})`);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case 'prompt':
|
|
172
|
+
case 'llm': {
|
|
173
|
+
const { secrets, pii, namedSecrets } = scanForLeaks(String(action.content || ''));
|
|
174
|
+
const provider = action.provider || 'an LLM provider';
|
|
175
|
+
if (secrets.length) add('block', 'secret-to-llm', `${secrets.join(', ')} in text sent to ${provider}`);
|
|
176
|
+
if (namedSecrets.length) add('block', 'named-secret-to-llm', `credential field(s) ${namedSecrets.join(', ')} in text sent to ${provider}`);
|
|
177
|
+
if (pii.length) add(piiMode, 'pii-to-llm', `personal data (${pii.join(', ')}) sent to ${provider} — redact first`);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'mcp': {
|
|
181
|
+
const blob = JSON.stringify(action.args || {}) + ' ' + String(action.tool || '');
|
|
182
|
+
const { secrets, pii } = scanForLeaks(blob);
|
|
183
|
+
if (secrets.length) add('block', 'secret-in-mcp-call', `${secrets.join(', ')} passed to MCP tool ${action.tool || ''}`);
|
|
184
|
+
if (pii.length) add('warn', 'pii-in-mcp-call', `personal data (${pii.join(', ')}) passed to MCP tool ${action.tool || ''}`);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
default: {
|
|
188
|
+
// Generic: scan any provided text; treat as external unless a host says otherwise.
|
|
189
|
+
const { secrets, pii } = scanForLeaks(String(action.content || action.text || ''));
|
|
190
|
+
if (secrets.length) add('block', 'secret-exposure', secrets.join(', '));
|
|
191
|
+
if (pii.length) add('warn', 'pii-exposure', pii.join(', '));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Verdict = the most severe violation. Fail-closed: default allow only when
|
|
196
|
+
// nothing matched.
|
|
197
|
+
let verdict = 'allow';
|
|
198
|
+
for (const v of violations) if (RANK[v.level] > RANK[verdict]) verdict = v.level;
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
action: verdict, // 'allow' | 'warn' | 'block'
|
|
202
|
+
blocked: verdict === 'block',
|
|
203
|
+
type,
|
|
204
|
+
violations,
|
|
205
|
+
reason: violations.length ? violations[0].detail : null,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Redact secrets + PII from a string so it CAN be sent safely (defense-in-depth
|
|
210
|
+
// companion to blocking — sanitize instead of drop when the caller opts in).
|
|
211
|
+
function sanitizeOutbound(text) {
|
|
212
|
+
if (!text || typeof text !== 'string') return text;
|
|
213
|
+
let out = redactText(text).redacted; // redactText returns { redacted, ... }
|
|
214
|
+
for (const { re } of SECRET_PATTERNS) {
|
|
215
|
+
out = out.replace(new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g'), '[REDACTED-SECRET]');
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
module.exports = { inspectAction, scanForLeaks, sanitizeOutbound, isExternalHost, hostOf, findNamedSecrets, shannonEntropy };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* src/agent-scan.js — AI Agent Security Posture.
|
|
5
|
+
*
|
|
6
|
+
* One command that answers the question generic SAST can't: "is my AI-agent
|
|
7
|
+
* setup safe?" It aggregates VibeGuard's agent-era checks into a single graded
|
|
8
|
+
* posture, grouped by the threat categories that actually matter for people
|
|
9
|
+
* building with LLMs, agents, and MCP:
|
|
10
|
+
*
|
|
11
|
+
* - MCP trust — the MCP servers the agent trusts (src/mcp-audit.js)
|
|
12
|
+
* - AI data leakage — PII / secrets sent to LLM providers (src/ai-guard.js + ai.*key* rules)
|
|
13
|
+
* - LLM output → sink— model output reaching exec/eval/SQL/DOM/file (ai.llm-output-*)
|
|
14
|
+
* - Prompt injection — user input in system prompt / missing guards (ai.prompt-*)
|
|
15
|
+
* - Agent capability — uncapped loops, unrestricted tool access (ai.agent-*)
|
|
16
|
+
* - Supply chain — hallucinated packages (ai.hallucinated-import)
|
|
17
|
+
*
|
|
18
|
+
* Pure orchestration of already-tested modules — no new detection engine, no
|
|
19
|
+
* network (slopsquat's registry check stays opt-in elsewhere). Offline.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const path = require('path');
|
|
23
|
+
|
|
24
|
+
// Category assignment for agent-relevant rule IDs. Anything ai.* not matched
|
|
25
|
+
// falls into 'other-ai'. mcp-audit + ai-guard feed their own categories.
|
|
26
|
+
const CATEGORY_RULES = {
|
|
27
|
+
'llm-output-to-sink': [
|
|
28
|
+
'ai.llm-output-exec', 'ai.llm-output-shell', 'ai.llm-output-sql',
|
|
29
|
+
'ai.llm-output-sql-v2', 'ai.llm-output-dom', 'ai.llm-output-file',
|
|
30
|
+
'ai.eval-llm-output',
|
|
31
|
+
],
|
|
32
|
+
'prompt-injection': [
|
|
33
|
+
'ai.no-prompt-injection-guard', 'ai.prompt-injection-marker',
|
|
34
|
+
'ai.prompt-extraction', 'ai.prompt-leak-via-error', 'ai.cursorrule-injection',
|
|
35
|
+
'ai.model-id-injection', 'ai.model-id-user-input',
|
|
36
|
+
],
|
|
37
|
+
'agent-capability': [
|
|
38
|
+
'ai.agent-loop-no-cap', 'ai.agent-no-max-steps', 'ai.agent-can-access-secrets',
|
|
39
|
+
'ai.agent-can-deploy', 'ai.agent-can-install-packages', 'ai.agent-can-modify-auth',
|
|
40
|
+
'ai.disabled-sandbox', 'ai.data-exfil-agent', 'ai.agent-memory-poisoning',
|
|
41
|
+
'ai.memory-poisoning', 'ai.adversarial-no-filter', 'ai.no-content-filter',
|
|
42
|
+
'ai.no-content-filter-bypass',
|
|
43
|
+
],
|
|
44
|
+
'ai-data-leakage': [
|
|
45
|
+
'ai.openai-key-public', 'ai.anthropic-key-public', 'ai.browser-api-key',
|
|
46
|
+
'ai.key-in-url', 'ai.agent-env-key-direct', 'ai.missing-max-tokens',
|
|
47
|
+
],
|
|
48
|
+
'supply-chain': ['ai.hallucinated-import'],
|
|
49
|
+
'mcp-trust': [
|
|
50
|
+
'ai.mcp-command-injection', 'ai.mcp-description-injection-deep',
|
|
51
|
+
'ai.mcp-path-traversal', 'ai.mcp-ssrf', 'ai.mcp-tool-no-auth',
|
|
52
|
+
'ai.obfuscated-description',
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const RULE_TO_CATEGORY = (() => {
|
|
57
|
+
const m = {};
|
|
58
|
+
for (const [cat, ids] of Object.entries(CATEGORY_RULES)) for (const id of ids) m[id] = cat;
|
|
59
|
+
return m;
|
|
60
|
+
})();
|
|
61
|
+
|
|
62
|
+
const SEV_ORDER = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
63
|
+
|
|
64
|
+
function categoryOf(ruleId) {
|
|
65
|
+
if (RULE_TO_CATEGORY[ruleId]) return RULE_TO_CATEGORY[ruleId];
|
|
66
|
+
if (ruleId.startsWith('ai.')) return 'other-ai';
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function gradeFor(counts) {
|
|
71
|
+
if (counts.critical > 0) return 'F';
|
|
72
|
+
if (counts.high >= 3) return 'D';
|
|
73
|
+
if (counts.high > 0) return 'C';
|
|
74
|
+
if (counts.medium >= 3) return 'C';
|
|
75
|
+
if (counts.medium > 0) return 'B';
|
|
76
|
+
return 'A';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function agentScan(root, opts = {}) {
|
|
80
|
+
const { scan, walk } = require('./scanner');
|
|
81
|
+
const { auditMcp } = require('./mcp-audit');
|
|
82
|
+
const { auditAIData } = require('./ai-guard');
|
|
83
|
+
|
|
84
|
+
const items = []; // normalized: { category, severity, ruleId, file, line, message, fix }
|
|
85
|
+
|
|
86
|
+
// 1. Code scan — keep only agent-relevant (ai.*) findings.
|
|
87
|
+
const scanRes = scan(root, { deps: false });
|
|
88
|
+
for (const f of scanRes.findings) {
|
|
89
|
+
const cat = categoryOf(f.ruleId);
|
|
90
|
+
if (!cat) continue;
|
|
91
|
+
items.push({
|
|
92
|
+
category: cat, severity: f.severity, ruleId: f.ruleId,
|
|
93
|
+
file: f.file, line: f.line, message: f.message, fix: f.fix,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 2. MCP trust.
|
|
98
|
+
const mcp = auditMcp(root, { pin: !!opts.pin });
|
|
99
|
+
for (const f of mcp.findings) {
|
|
100
|
+
items.push({
|
|
101
|
+
category: 'mcp-trust', severity: f.severity, ruleId: f.id,
|
|
102
|
+
file: f.config, line: 1, message: f.message, fix: f.fix, server: f.server,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 3. AI data leakage — PII / user data flowing to LLM providers.
|
|
107
|
+
let aiData = { findings: [] };
|
|
108
|
+
try {
|
|
109
|
+
const files = walk(root, []);
|
|
110
|
+
aiData = auditAIData(root, files);
|
|
111
|
+
} catch { /* best-effort */ }
|
|
112
|
+
for (const f of aiData.findings) {
|
|
113
|
+
items.push({
|
|
114
|
+
category: 'ai-data-leakage', severity: f.severity, ruleId: 'ai-guard.pii-to-llm',
|
|
115
|
+
file: f.file, line: f.line, message: f.message, fix: f.fix,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Aggregate.
|
|
120
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
121
|
+
const categories = {};
|
|
122
|
+
for (const it of items) {
|
|
123
|
+
counts[it.severity] = (counts[it.severity] || 0) + 1;
|
|
124
|
+
(categories[it.category] = categories[it.category] || []).push(it);
|
|
125
|
+
}
|
|
126
|
+
const grade = gradeFor(counts);
|
|
127
|
+
items.sort((a, b) => SEV_ORDER[a.severity] - SEV_ORDER[b.severity]);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
root: path.resolve(root),
|
|
131
|
+
grade,
|
|
132
|
+
counts,
|
|
133
|
+
total: items.length,
|
|
134
|
+
categories,
|
|
135
|
+
items,
|
|
136
|
+
mcpServers: mcp.servers.length,
|
|
137
|
+
mcpDrifted: mcp.drifted,
|
|
138
|
+
scannedFiles: scanRes.scannedFiles,
|
|
139
|
+
engine: scanRes.engine,
|
|
140
|
+
generatedAt: new Date().toISOString(),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const CATEGORY_LABEL = {
|
|
145
|
+
'mcp-trust': 'MCP trust',
|
|
146
|
+
'ai-data-leakage': 'AI data leakage',
|
|
147
|
+
'llm-output-to-sink': 'LLM output → dangerous sink',
|
|
148
|
+
'prompt-injection': 'Prompt injection',
|
|
149
|
+
'agent-capability': 'Agent capability / loops',
|
|
150
|
+
'supply-chain': 'Supply chain (hallucinated deps)',
|
|
151
|
+
'other-ai': 'Other AI risks',
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function renderAgentScan(result) {
|
|
155
|
+
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
156
|
+
const c = (x) => (useColor ? x : '');
|
|
157
|
+
const R = c('\x1b[0m'), B = c('\x1b[1m'), DIM = c('\x1b[2m');
|
|
158
|
+
const RED = c('\x1b[31m'), YEL = c('\x1b[33m'), GRN = c('\x1b[32m'), CYAN = c('\x1b[36m');
|
|
159
|
+
const gradeColor = result.grade === 'A' ? GRN : (result.grade === 'F' || result.grade === 'D') ? RED : YEL;
|
|
160
|
+
const sevColor = { critical: RED, high: YEL, medium: YEL, low: DIM };
|
|
161
|
+
|
|
162
|
+
const out = [];
|
|
163
|
+
out.push(`${B}${CYAN}VibeGuard — AI Agent Security Posture${R} ${DIM}(offline)${R}`);
|
|
164
|
+
out.push(` ${DIM}${result.scannedFiles} files · ${result.mcpServers} MCP server(s) · engine: ${result.engine ? result.engine.mode : '?'}${R}`);
|
|
165
|
+
out.push(` ${B}Agent Risk Grade: ${gradeColor}${result.grade}${R} ${DIM}(${result.counts.critical} critical, ${result.counts.high} high, ${result.counts.medium} medium)${R}`);
|
|
166
|
+
if (result.mcpDrifted && result.mcpDrifted.length) {
|
|
167
|
+
out.push(` ${RED}⚠ MCP definition drift: ${result.mcpDrifted.join(', ')} — re-review (rug-pull risk)${R}`);
|
|
168
|
+
}
|
|
169
|
+
out.push('');
|
|
170
|
+
|
|
171
|
+
if (result.total === 0) {
|
|
172
|
+
out.push(` ${GRN}No agent-specific security risks found.${R}`);
|
|
173
|
+
return out.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (const cat of Object.keys(CATEGORY_LABEL)) {
|
|
177
|
+
const list = result.categories[cat];
|
|
178
|
+
if (!list || !list.length) continue;
|
|
179
|
+
out.push(`${B}${CATEGORY_LABEL[cat]}${R} ${DIM}(${list.length})${R}`);
|
|
180
|
+
for (const it of list.slice(0, 10)) {
|
|
181
|
+
const col = sevColor[it.severity] || '';
|
|
182
|
+
const loc = it.file ? `${it.file}:${it.line}` : '';
|
|
183
|
+
out.push(` ${col}${it.severity.toUpperCase().padEnd(8)}${R} [${it.ruleId}] ${DIM}${loc}${R}`);
|
|
184
|
+
out.push(` ${it.message}`);
|
|
185
|
+
}
|
|
186
|
+
if (list.length > 10) out.push(` ${DIM}… ${list.length - 10} more${R}`);
|
|
187
|
+
out.push('');
|
|
188
|
+
}
|
|
189
|
+
return out.join('\n');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = { agentScan, renderAgentScan, categoryOf, gradeFor, CATEGORY_RULES };
|
package/src/integrity.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* src/integrity.js — self-integrity verification.
|
|
5
|
+
*
|
|
6
|
+
* A security tool that has been silently patched is worse than none: an
|
|
7
|
+
* attacker (or a compromised dependency's postinstall) could neuter a rule file
|
|
8
|
+
* or make the action firewall always return "allow". `self-check` used to only
|
|
9
|
+
* verify that modules *load* — this verifies their *content* against a manifest
|
|
10
|
+
* of SHA-256 hashes generated at publish time (scripts/gen-integrity.js).
|
|
11
|
+
*
|
|
12
|
+
* Limits (stated honestly): this detects tampering with the guard's source. It
|
|
13
|
+
* is not a full chain of trust — an attacker who rewrites both a module AND the
|
|
14
|
+
* manifest defeats it. It raises the bar and catches the common case (patched
|
|
15
|
+
* rules / neutered guard) that a load-only check misses. For a real trust
|
|
16
|
+
* anchor, verify the package's npm provenance / signature on install.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const crypto = require('crypto');
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
// The modules whose integrity actually matters for security decisions.
|
|
24
|
+
const CRITICAL_MODULES = [
|
|
25
|
+
'action-guard.js', 'shell-guard.js', 'interceptor.js', 'firewall.js',
|
|
26
|
+
'pii.js', 'rules.js', 'scanner.js', 'engine.js',
|
|
27
|
+
'mcp-audit.js', 'agent-scan.js', 'secure-prompt.js', 'ai-guard.js',
|
|
28
|
+
'taint.js', 'taint-ast.js', 'ast.js',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function hashFile(p) {
|
|
32
|
+
return crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function computeManifest(srcDir) {
|
|
36
|
+
const hashes = {};
|
|
37
|
+
for (const f of CRITICAL_MODULES) {
|
|
38
|
+
const p = path.join(srcDir, f);
|
|
39
|
+
if (fs.existsSync(p)) hashes[f] = hashFile(p);
|
|
40
|
+
}
|
|
41
|
+
return { tool: 'vibeguard', generatedAt: new Date().toISOString(), algo: 'sha256', hashes };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Verify the modules in `srcDir` against the shipped integrity.json.
|
|
45
|
+
function verifyIntegrity(srcDir) {
|
|
46
|
+
srcDir = srcDir || __dirname;
|
|
47
|
+
const manifestPath = path.join(srcDir, 'integrity.json');
|
|
48
|
+
let manifest;
|
|
49
|
+
try {
|
|
50
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
51
|
+
} catch {
|
|
52
|
+
return { available: false, intact: null, reason: 'no integrity manifest (integrity.json) found' };
|
|
53
|
+
}
|
|
54
|
+
const expected = (manifest && manifest.hashes) || {};
|
|
55
|
+
const modified = [];
|
|
56
|
+
const missing = [];
|
|
57
|
+
for (const [f, h] of Object.entries(expected)) {
|
|
58
|
+
const p = path.join(srcDir, f);
|
|
59
|
+
if (!fs.existsSync(p)) { missing.push(f); continue; }
|
|
60
|
+
let actual;
|
|
61
|
+
try { actual = hashFile(p); } catch { missing.push(f); continue; }
|
|
62
|
+
if (actual !== h) modified.push(f);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
available: true,
|
|
66
|
+
intact: modified.length === 0 && missing.length === 0,
|
|
67
|
+
modified,
|
|
68
|
+
missing,
|
|
69
|
+
checked: Object.keys(expected).length,
|
|
70
|
+
generatedAt: manifest.generatedAt,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { verifyIntegrity, computeManifest, hashFile, CRITICAL_MODULES };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tool": "vibeguard",
|
|
3
|
+
"generatedAt": "2026-07-13T18:38:30.609Z",
|
|
4
|
+
"algo": "sha256",
|
|
5
|
+
"hashes": {
|
|
6
|
+
"action-guard.js": "8b4142038b2614bd3da59c31cc9cecd7ccd1f002bec2e0a8f10bc423463cc625",
|
|
7
|
+
"shell-guard.js": "f16a0bd72d7e99feaae69bb20886ed2569d137bdc65240a6eacdfcf214831d9d",
|
|
8
|
+
"interceptor.js": "fd99360331111e7fbdee904206fd53989a7cbedbc784cd28c0a1523a41a3da7a",
|
|
9
|
+
"firewall.js": "06fb03919b17c62c5e42ca461e27f26a2aaf3a260a361fa1f721d0975e75b47e",
|
|
10
|
+
"pii.js": "51ea76de52b2c15d2cb34ab8125a5f67f725d1e7de43a4cef39136e25b276025",
|
|
11
|
+
"rules.js": "b14a78216654c399baa8d79b2c4052af5817dab524fa87056b74a8e25bb841f6",
|
|
12
|
+
"scanner.js": "3521b22024b60470b6969d61272e698c07bcdb7d7ccfbbf1e8885feeddb1961d",
|
|
13
|
+
"engine.js": "23666926e0e961633039b3fa7341e55e4607e027ea4e1a57773363df71dc19d3",
|
|
14
|
+
"mcp-audit.js": "8f38b2738ffedc23f61601a1c03d3cbaac8a38fb19390a898ffe32b30bf8ffc4",
|
|
15
|
+
"agent-scan.js": "018813166eb1e370bf452efaa92020cd4baea0a20f3826fed3f95ded312aa5c7",
|
|
16
|
+
"secure-prompt.js": "a4d8203ad2292e57b29f75a700f2837f12ba6c9067fd4d5f6731e55203e184b2",
|
|
17
|
+
"ai-guard.js": "9dd2c524dd704bbba69aacf7076e76ac966c6e0c773ee4b04ed7c8fb889db006",
|
|
18
|
+
"taint.js": "958decf89c32993e2c9a057ef7be9bbe592e7525fd0daa5fc5a278dcafe957af",
|
|
19
|
+
"taint-ast.js": "4c8dd6f365b7fd6c610fb4643619753531f2b5ecdc16feee135e2fccc66a2ad3",
|
|
20
|
+
"ast.js": "cba4db68368831845ed6c4481ea1e44a45c41cddef68993dc4c5908276636225"
|
|
21
|
+
}
|
|
22
|
+
}
|