@yagyeshvyas/vibeguard 1.3.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vibeguard-mcp.example.json +51 -0
- package/CHANGELOG.md +604 -216
- package/MCP-FIREWALL.md +296 -0
- package/README.md +355 -31
- package/bin/cli.js +355 -27
- package/bin/cmd-agent-monitor.js +45 -0
- package/bin/cmd-agent-risk.js +64 -0
- package/bin/cmd-gif.js +62 -0
- package/bin/cmd-git-scan.js +74 -0
- package/bin/cmd-llm-proxy.js +164 -0
- package/bin/cmd-mcp-firewall.js +191 -0
- package/bin/cmd-pentest.js +103 -0
- package/bin/cmd-platform.js +137 -0
- package/bin/cmd-pr-scan.js +135 -0
- package/bin/cmd-sbom-diff.js +38 -0
- package/bin/cmd-skill-scan.js +35 -0
- package/docs/AISVS.md +25 -0
- package/docs/ARCHITECTURE.md +81 -0
- package/docs/INSTALLATION.md +139 -0
- package/docs/WINDOWS.md +74 -0
- package/docs/security-policy.strict.example.json +134 -0
- package/docs/security-policy.strict.example.pub.pem +3 -0
- package/package.json +45 -7
- package/src/.vibeguard/cache/file-hashes.json +60 -0
- package/src/.vibeguard/latest-snapshot.json +36 -0
- package/src/.vibeguard/mcp-pins.json +1 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
- package/src/.vibeguard-baseline.json +5226 -0
- package/src/action-guard.js +84 -6
- package/src/agent-monitor.js +262 -0
- package/src/agent-policy.js +642 -0
- package/src/agent-risk.js +271 -0
- package/src/agentic.js +1513 -0
- package/src/ast.js +165 -7
- package/src/audit-trail.js +212 -67
- package/src/auto.js +427 -427
- package/src/autofix.js +11 -4
- package/src/bundles.js +198 -0
- package/src/daemon.js +343 -343
- package/src/dashboard.js +278 -278
- package/src/engine.js +3 -0
- package/src/entropy.js +187 -0
- package/src/firewall.js +19 -3
- package/src/gif.js +134 -0
- package/src/gitscan.js +282 -0
- package/src/hook.js +151 -151
- package/src/injection-decode.js +136 -0
- package/src/install.js +298 -280
- package/src/integrity.js +16 -1
- package/src/integrity.json +43 -13
- package/src/interceptor.js +12 -9
- package/src/llm-proxy.js +986 -0
- package/src/mcp-audit.js +61 -5
- package/src/mcp-firewall.js +971 -0
- package/src/mcp-server.js +2500 -2047
- package/src/obfuscation.js +315 -0
- package/src/owasp-agentic.js +314 -0
- package/src/pentest.js +589 -0
- package/src/pii.js +4 -0
- package/src/platform/aisvs.js +38 -0
- package/src/platform/approval.js +187 -0
- package/src/platform/canonical.js +73 -0
- package/src/platform/contracts.js +158 -0
- package/src/platform/delegation.js +73 -0
- package/src/platform/http-gateway.js +177 -0
- package/src/platform/identity.js +253 -0
- package/src/platform/jwt.js +86 -0
- package/src/platform/mcp-http-bridge.js +199 -0
- package/src/platform/memory-guard.js +64 -0
- package/src/platform/os-sandbox.js +144 -0
- package/src/platform/policy.js +332 -0
- package/src/platform/sandbox-manager.js +92 -0
- package/src/platform/signed-audit.js +357 -0
- package/src/platform/ssrf.js +129 -0
- package/src/plugin.js +182 -168
- package/src/pre-deploy.js +170 -55
- package/src/privacy-audit.js +272 -272
- package/src/repl.js +150 -150
- package/src/report.js +7 -1
- package/src/routes.js +1210 -0
- package/src/rules-2026.js +1407 -0
- package/src/rules-pack.js +3068 -3019
- package/src/rules.js +376 -60
- package/src/sandbox.js +200 -10
- package/src/sbom.js +193 -164
- package/src/scanner.js +189 -33
- package/src/shell-guard.js +11 -0
- package/src/skill-scan.js +477 -0
- package/src/slopsquat.js +144 -144
- package/src/surface.js +408 -0
- package/src/taint-ast.js +204 -37
- package/src/taint.js +15 -3
- package/src/tokenlean.js +579 -0
- package/src/trace.js +220 -220
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* bin/cmd-agent-risk.js — agent risk score + OWASP coverage CLI.
|
|
5
|
+
*
|
|
6
|
+
* vibeguard agent-risk [dir] [--json] [--frameworks agentic,mcp,llm]
|
|
7
|
+
* vibeguard owasp-coverage [dir] [--json] [--all]
|
|
8
|
+
*
|
|
9
|
+
* exit: 0 clean (A / full coverage), 1 risky, 2 critical-or-worse.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { computeAgentRisk, renderAgentRisk } = require('../src/agent-risk');
|
|
14
|
+
const { coverageReport, renderCoverage } = require('../src/owasp-agentic');
|
|
15
|
+
|
|
16
|
+
function parseFrameworks(flags) {
|
|
17
|
+
const raw = flags.frameworks || flags.framework;
|
|
18
|
+
if (!raw || raw === true) return undefined;
|
|
19
|
+
return String(raw).split(',').map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function cmdAgentRisk(args, flags) {
|
|
23
|
+
const root = path.resolve(flags.dir || args._[1] || '.');
|
|
24
|
+
const report = computeAgentRisk(root, {
|
|
25
|
+
auditFile: flags.audit,
|
|
26
|
+
policyPath: flags.policy,
|
|
27
|
+
skillPaths: flags.path ? [String(flags.path)] : undefined,
|
|
28
|
+
frameworks: parseFrameworks(flags),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (flags.json) {
|
|
32
|
+
const { owasp, ...rest } = report;
|
|
33
|
+
process.stdout.write(JSON.stringify({ ...rest, owasp: { percent: owasp.percent, covered: owasp.covered, total: owasp.total, summary: owasp.summary } }, null, 2) + '\n');
|
|
34
|
+
} else {
|
|
35
|
+
process.stdout.write(renderAgentRisk(report) + '\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const critical = (report.mcp.counts.critical || 0) + (report.skills.counts.critical || 0);
|
|
39
|
+
if (critical > 0 || report.grade === 'F') return 2;
|
|
40
|
+
if (report.score > 0) return 1;
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function cmdOwaspCoverage(args, flags) {
|
|
45
|
+
const root = path.resolve(flags.dir || args._[1] || '.');
|
|
46
|
+
const frameworks = flags.all ? ['agentic', 'mcp', 'llm'] : parseFrameworks(flags);
|
|
47
|
+
let findings = [];
|
|
48
|
+
try {
|
|
49
|
+
const { computeAgentRisk: compute } = require('../src/agent-risk');
|
|
50
|
+
const risk = compute(root, { noWrite: true, frameworks });
|
|
51
|
+
findings = [...(risk.mcp.findings || []), ...(risk.skills.findings || [])];
|
|
52
|
+
} catch {
|
|
53
|
+
// Coverage can be reported without the live scan.
|
|
54
|
+
}
|
|
55
|
+
const report = coverageReport({ frameworks, findings });
|
|
56
|
+
if (flags.json) {
|
|
57
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
58
|
+
} else {
|
|
59
|
+
process.stdout.write(renderCoverage(report) + '\n');
|
|
60
|
+
}
|
|
61
|
+
return report.percent === 100 ? 0 : 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { cmdAgentRisk, cmdOwaspCoverage };
|
package/bin/cmd-gif.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// cmdGif — `vibeguard gif <query>`: print (or download) a keyless open GIF.
|
|
4
|
+
//
|
|
5
|
+
// vibeguard gif cat # print a validated GIF URL
|
|
6
|
+
// vibeguard gif "all tests passed" # cat GIF with text overlay
|
|
7
|
+
// vibeguard gif yes # yes/no reaction GIF
|
|
8
|
+
// vibeguard gif cat --save out.gif # download to a file
|
|
9
|
+
// vibeguard gif yes --json # machine-readable result
|
|
10
|
+
//
|
|
11
|
+
// 100% keyless. No account, no tracking, no paid tier. Byte-verified before
|
|
12
|
+
// being printed as valid. See src/gif.js for the backend list + known dead
|
|
13
|
+
// backends (Tenor/GIPHY/Klipy all need keys — tested).
|
|
14
|
+
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
const C = {
|
|
18
|
+
bold: '\x1b[1m', dim: '\x1b[2m', green: '\x1b[32m', cyan: '\x1b[36m',
|
|
19
|
+
yellow: '\x1b[33m', magenta: '\x1b[35m', reset: '\x1b[0m',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
async function cmdGif(args, flags) {
|
|
23
|
+
const { searchGifs, downloadGif } = require('../src/gif');
|
|
24
|
+
const query = args._.slice(1).join(' ').trim();
|
|
25
|
+
if (!query) {
|
|
26
|
+
process.stderr.write('usage: vibeguard gif <query> [--save out.gif] [--json]\n');
|
|
27
|
+
process.stderr.write('examples: vibeguard gif cat | vibeguard gif "all tests passed" | vibeguard gif yes\n');
|
|
28
|
+
return 2;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let result;
|
|
32
|
+
try {
|
|
33
|
+
result = await searchGifs(query);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
process.stderr.write(`gif: ${e.message}\n`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const saveTarget = flags.save || flags.output;
|
|
40
|
+
if (saveTarget) {
|
|
41
|
+
const outPath = path.resolve(String(saveTarget));
|
|
42
|
+
const d = await downloadGif(query, outPath);
|
|
43
|
+
if (flags.json) {
|
|
44
|
+
process.stdout.write(JSON.stringify({ title: result.title, url: result.url, source: result.source, license: result.license, path: d.path, bytes: d.bytes, valid: d.valid }, null, 2) + '\n');
|
|
45
|
+
} else {
|
|
46
|
+
process.stdout.write(`${C.green}✓${C.reset} saved ${C.bold}${d.bytes}${C.reset} bytes to ${C.cyan}${d.path}${C.reset} ${C.dim}(${result.source}, ${result.license})${C.reset}\n`);
|
|
47
|
+
}
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (flags.json) {
|
|
52
|
+
process.stdout.write(JSON.stringify({ title: result.title, url: result.url, source: result.source, license: result.license, bytes: result.bytes, valid: result.valid }, null, 2) + '\n');
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
process.stdout.write(`${C.magenta}${C.bold}🎞 ${result.title}${C.reset}\n`);
|
|
57
|
+
process.stdout.write(` ${C.cyan}${result.url}${C.reset}\n`);
|
|
58
|
+
process.stdout.write(` ${C.dim}${result.source} · ${result.license} · ${result.bytes} bytes${result.valid ? ' · byte-verified GIF' : ''}${C.reset}\n`);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { cmdGif };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// cmdGitScan — `vibeguard git-scan [dir]`: scan the ENTIRE git history for
|
|
4
|
+
// leaked secrets (Gitleaks / TruffleHog parity). A secret committed months ago
|
|
5
|
+
// and since deleted is still found — it lives in history.
|
|
6
|
+
//
|
|
7
|
+
// vibeguard git-scan # scan the current repo's history
|
|
8
|
+
// vibeguard git-scan ../other-repo # scan another repo
|
|
9
|
+
// vibeguard git-scan --since 2024-01-01 # only commits after a date
|
|
10
|
+
// vibeguard git-scan --max-blobs 5000 # cap blobs examined (default 20000)
|
|
11
|
+
// vibeguard git-scan --json # machine-readable findings array
|
|
12
|
+
// vibeguard git-scan --output out.json # also write findings to a file
|
|
13
|
+
//
|
|
14
|
+
// Exit codes: 0 = clean, 1 = findings, 2 = usage / not-a-repo / git errors.
|
|
15
|
+
// Matches are always masked (first4****last2) — never printed raw.
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const C = {
|
|
21
|
+
bold: '\x1b[1m', dim: '\x1b[2m', green: '\x1b[32m', cyan: '\x1b[36m',
|
|
22
|
+
yellow: '\x1b[33m', red: '\x1b[31m', reset: '\x1b[0m',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async function cmdGitScan(args, flags) {
|
|
26
|
+
const dir = path.resolve(args._[1] || '.');
|
|
27
|
+
const { scanGitHistory } = require('../src/gitscan');
|
|
28
|
+
|
|
29
|
+
if (flags.help || flags.h) {
|
|
30
|
+
process.stderr.write('usage: vibeguard git-scan [dir] [--since <date>] [--max-blobs N] [--max-commits N] [--json] [--output file.json]\n');
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let result;
|
|
35
|
+
try {
|
|
36
|
+
result = await scanGitHistory(dir, {
|
|
37
|
+
since: flags.since,
|
|
38
|
+
maxBlobs: flags['max-blobs'],
|
|
39
|
+
maxCommits: flags['max-commits'],
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
process.stderr.write(`git-scan: ${err.message}\n`);
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const findings = result.findings;
|
|
47
|
+
|
|
48
|
+
if (flags.json) {
|
|
49
|
+
process.stdout.write(JSON.stringify(findings, null, 2) + '\n');
|
|
50
|
+
} else if (findings.length > 0) {
|
|
51
|
+
process.stdout.write(`${C.bold}${C.red}${findings.length} secret(s) found in git history${C.reset}\n`);
|
|
52
|
+
process.stdout.write(`${C.dim}commit | path | rule | match (redacted)${C.reset}\n`);
|
|
53
|
+
for (const f of findings) {
|
|
54
|
+
const sha = (f.commit || '').slice(0, 8);
|
|
55
|
+
process.stdout.write(` ${C.yellow}${sha}${C.reset} | ${f.path} | ${f.ruleId} | ${C.red}${f.match}${C.reset}\n`);
|
|
56
|
+
}
|
|
57
|
+
process.stdout.write(`${C.dim}${findings.length} finding(s) across ${result.stats.blobs} blob(s) (${result.stats.durationMs} ms)${C.reset}\n`);
|
|
58
|
+
} else {
|
|
59
|
+
process.stdout.write(`${C.green}✓${C.reset} no secrets in git history (${result.stats.blobs} blobs, ${result.stats.commits} commits, ${result.stats.durationMs} ms)\n`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (flags.output) {
|
|
63
|
+
try {
|
|
64
|
+
fs.writeFileSync(path.resolve(String(flags.output)), JSON.stringify(findings, null, 2) + '\n');
|
|
65
|
+
} catch (err) {
|
|
66
|
+
process.stderr.write(`git-scan: cannot write output file: ${err.message}\n`);
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return findings.length > 0 ? 1 : 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { cmdGitScan };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
// cmdLlmProxy — `vibeguard llm-proxy`: OpenAI-compatible runtime LLM guard proxy.
|
|
5
|
+
//
|
|
6
|
+
// vibeguard llm-proxy
|
|
7
|
+
// vibeguard llm-proxy --port 9000 --mode redact
|
|
8
|
+
// vibeguard llm-proxy --upstream http://localhost:11434/v1 --api-key sk-...
|
|
9
|
+
//
|
|
10
|
+
// Any LLM client points base_url at http://127.0.0.1:<port>/v1 — VibeGuard
|
|
11
|
+
// scans every prompt AND response for prompt-injection / secrets / PII and
|
|
12
|
+
// blocks, redacts, or reports, then forwards to the real upstream.
|
|
13
|
+
// 100% local, free, zero deps. See src/llm-proxy.js for the server core.
|
|
14
|
+
//
|
|
15
|
+
// Returns 0 after starting (the server keeps the event loop alive), 2 on bad
|
|
16
|
+
// args. SIGINT/SIGTERM trigger a clean shutdown.
|
|
17
|
+
|
|
18
|
+
const { createGuardProxy, DEFAULT_PORT, DEFAULT_UPSTREAM, MODES } = require('../src/llm-proxy');
|
|
19
|
+
|
|
20
|
+
const USAGE = [
|
|
21
|
+
'usage: vibeguard llm-proxy [--port <port>] [--upstream <base-url>] [--mode block|redact|report] [--api-key <key>]',
|
|
22
|
+
'',
|
|
23
|
+
'OpenAI-compatible local LLM guard proxy (Lakera Guard parity, 100% local).',
|
|
24
|
+
'Point any OpenAI SDK client at http://127.0.0.1:<port>/v1 — VibeGuard scans',
|
|
25
|
+
'every prompt and response for prompt-injection, secrets, and PII.',
|
|
26
|
+
'',
|
|
27
|
+
' --port <n> listen port (default 8443)',
|
|
28
|
+
' --upstream <url> upstream OpenAI-compatible base URL (default https://api.openai.com/v1)',
|
|
29
|
+
' --mode <mode> block — reject violating requests with 403 (default)',
|
|
30
|
+
' redact — mask secrets/PII with [REDACTED:<ruleId>]',
|
|
31
|
+
' report — never mutate, log violations, pass through',
|
|
32
|
+
' --api-key <key> authorization header sent to upstream',
|
|
33
|
+
' --system-prompt-file <path> detect the model echoing YOUR system prompt in outputs',
|
|
34
|
+
' (default: forward the client\'s own Authorization header)',
|
|
35
|
+
'',
|
|
36
|
+
'examples:',
|
|
37
|
+
' vibeguard llm-proxy',
|
|
38
|
+
' vibeguard llm-proxy --port 9000 --upstream http://localhost:11434/v1 --mode redact',
|
|
39
|
+
'',
|
|
40
|
+
].join('\n');
|
|
41
|
+
|
|
42
|
+
async function cmdLlmProxy(args, flags) {
|
|
43
|
+
const f = flags || {};
|
|
44
|
+
|
|
45
|
+
// --port
|
|
46
|
+
let port = DEFAULT_PORT;
|
|
47
|
+
if (f.port !== undefined) {
|
|
48
|
+
port = Number(f.port);
|
|
49
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
50
|
+
process.stderr.write(USAGE);
|
|
51
|
+
process.stderr.write('llm-proxy: invalid --port (expected 1-65535)\n');
|
|
52
|
+
return 2;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --upstream
|
|
57
|
+
let upstream = DEFAULT_UPSTREAM;
|
|
58
|
+
if (f.upstream !== undefined) {
|
|
59
|
+
try {
|
|
60
|
+
const u = new URL(String(f.upstream));
|
|
61
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') throw new Error('scheme');
|
|
62
|
+
upstream = u.toString().replace(/\/+$/, '');
|
|
63
|
+
} catch {
|
|
64
|
+
process.stderr.write(USAGE);
|
|
65
|
+
process.stderr.write('llm-proxy: invalid --upstream URL (expected http(s)://host[:port][/v1])\n');
|
|
66
|
+
return 2;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// --mode
|
|
71
|
+
const mode = f.mode !== undefined ? String(f.mode) : 'block';
|
|
72
|
+
if (!MODES.has(mode)) {
|
|
73
|
+
process.stderr.write(USAGE);
|
|
74
|
+
process.stderr.write(`llm-proxy: invalid --mode '${mode}' (expected block|redact|report)\n`);
|
|
75
|
+
return 2;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// --api-key (accept both hyphenated and camelCase flag spellings)
|
|
79
|
+
const apiKey =
|
|
80
|
+
f['api-key'] !== undefined && f['api-key'] !== true ? String(f['api-key']) :
|
|
81
|
+
f.apiKey !== undefined && f.apiKey !== true ? String(f.apiKey) :
|
|
82
|
+
null;
|
|
83
|
+
|
|
84
|
+
// --system-prompt-file: lines of YOUR system prompt; the proxy flags any
|
|
85
|
+
// response that echoes one (prompt-leakage exfiltration).
|
|
86
|
+
let systemPromptLines = [];
|
|
87
|
+
if (f['system-prompt-file'] !== undefined && f['system-prompt-file'] !== true) {
|
|
88
|
+
const spPath = String(f['system-prompt-file']);
|
|
89
|
+
try {
|
|
90
|
+
const raw = fs.readFileSync(spPath, 'utf8');
|
|
91
|
+
systemPromptLines = raw.split(/\r?\n/)
|
|
92
|
+
.map((l) => l.trim())
|
|
93
|
+
.filter((l) => l.length >= 16);
|
|
94
|
+
if (systemPromptLines.length === 0) {
|
|
95
|
+
process.stderr.write('llm-proxy: --system-prompt-file has no usable lines (min 16 chars each)\n');
|
|
96
|
+
return 2;
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
process.stderr.write('llm-proxy: cannot read --system-prompt-file: ' + spPath + '\n');
|
|
100
|
+
return 2;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let gp;
|
|
105
|
+
try {
|
|
106
|
+
gp = createGuardProxy({ port, upstream, mode, apiKey, systemPromptLines });
|
|
107
|
+
} catch (err) {
|
|
108
|
+
process.stderr.write(`llm-proxy: ${err && err.message ? err.message : err}\n`);
|
|
109
|
+
return 2;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
gp.server.once('listening', () => {
|
|
113
|
+
process.stdout.write(`[llm-proxy] listening on http://127.0.0.1:${gp.port}/v1 (mode: ${mode})\n`);
|
|
114
|
+
process.stdout.write(`[llm-proxy] upstream: ${upstream}\n`);
|
|
115
|
+
process.stdout.write(`[llm-proxy] point clients at base_url http://127.0.0.1:${gp.port}/v1 — Ctrl+C to stop\n`);
|
|
116
|
+
});
|
|
117
|
+
gp.server.on('error', (err) => {
|
|
118
|
+
process.stderr.write(`llm-proxy: ${err && err.message ? err.message : err}\n`);
|
|
119
|
+
process.exit(2);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
let shuttingDown = false;
|
|
123
|
+
const shutdown = () => {
|
|
124
|
+
if (shuttingDown) return;
|
|
125
|
+
shuttingDown = true;
|
|
126
|
+
gp.close()
|
|
127
|
+
.then(() => process.exit(0))
|
|
128
|
+
.catch(() => process.exit(0));
|
|
129
|
+
};
|
|
130
|
+
process.on('SIGINT', shutdown);
|
|
131
|
+
process.on('SIGTERM', shutdown);
|
|
132
|
+
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Direct invocation: `node bin/cmd-llm-proxy.js [--port ...] ...`
|
|
137
|
+
if (require.main === module) {
|
|
138
|
+
const argv = process.argv.slice(2);
|
|
139
|
+
const flags = {};
|
|
140
|
+
const positional = [];
|
|
141
|
+
for (let i = 0; i < argv.length; i++) {
|
|
142
|
+
const a = argv[i];
|
|
143
|
+
if (a.startsWith('--')) {
|
|
144
|
+
const eq = a.indexOf('=');
|
|
145
|
+
if (eq !== -1) {
|
|
146
|
+
flags[a.slice(2, eq)] = a.slice(eq + 1);
|
|
147
|
+
} else {
|
|
148
|
+
const name = a.slice(2);
|
|
149
|
+
if (i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
|
|
150
|
+
flags[name] = argv[++i];
|
|
151
|
+
} else {
|
|
152
|
+
flags[name] = true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
positional.push(a);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
cmdLlmProxy({ _: positional }, flags).then((code) => {
|
|
160
|
+
if (code !== 0) process.exit(code);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports = { cmdLlmProxy };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* bin/cmd-mcp-firewall.js — CLI for the real-time MCP firewall.
|
|
5
|
+
*
|
|
6
|
+
* Modes:
|
|
7
|
+
* vibeguard mcp-firewall --server <name> proxy a configured server
|
|
8
|
+
* vibeguard mcp-firewall --exec "<command>" proxy an ad-hoc server
|
|
9
|
+
* vibeguard mcp-firewall --selftest run the offline checks
|
|
10
|
+
* vibeguard mcp-firewall --check '<json>' evaluate one tool call
|
|
11
|
+
* vibeguard mcp-firewall --status summarize the audit log
|
|
12
|
+
* vibeguard mcp-firewall --list-servers show configured servers
|
|
13
|
+
*
|
|
14
|
+
* IMPORTANT: in proxy mode stdout is reserved for JSON-RPC. Every human
|
|
15
|
+
* message goes to stderr. A banner on stdout would corrupt the agent session.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const {
|
|
21
|
+
startProxy,
|
|
22
|
+
runSelfTest,
|
|
23
|
+
renderSelfTest,
|
|
24
|
+
resolveServer,
|
|
25
|
+
} = require('../src/mcp-firewall');
|
|
26
|
+
const { loadPolicy, describePolicy, evaluateToolCall, DEFAULT_POLICY } = require('../src/agent-policy');
|
|
27
|
+
const { analyzeMonitorLog, renderMonitor } = require('../src/agent-monitor');
|
|
28
|
+
|
|
29
|
+
function out(text) {
|
|
30
|
+
process.stdout.write(text + '\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function listServers(root) {
|
|
34
|
+
const rows = [];
|
|
35
|
+
for (const rel of ['.mcp.json', '.cursor/mcp.json', '.vscode/mcp.json']) {
|
|
36
|
+
const file = path.join(root, rel);
|
|
37
|
+
let json;
|
|
38
|
+
try { json = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { continue; }
|
|
39
|
+
const servers = json.mcpServers || json.servers || {};
|
|
40
|
+
for (const [name, cfg] of Object.entries(servers)) {
|
|
41
|
+
rows.push({ name, file: rel, command: [cfg.command, ...(cfg.args || [])].filter(Boolean).join(' ') });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return rows;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function cmdMcpFirewall(args, flags) {
|
|
48
|
+
const root = path.resolve(flags.dir || args._[1] || '.');
|
|
49
|
+
const json = !!flags.json;
|
|
50
|
+
|
|
51
|
+
if (flags.init) {
|
|
52
|
+
const target = path.resolve(root, flags.policy || '.vibeguard-mcp.json');
|
|
53
|
+
if (fs.existsSync(target)) {
|
|
54
|
+
process.stderr.write(`refusing to overwrite existing policy: ${target}\n`);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
const { projectRoot: _projectRoot, ...defaults } = DEFAULT_POLICY;
|
|
58
|
+
fs.writeFileSync(target, JSON.stringify(defaults, null, 2) + '\n', 'utf8');
|
|
59
|
+
out(`Wrote default MCP firewall policy to ${target}`);
|
|
60
|
+
out('Review deniedPaths / allowedHosts / tool rules, then start the proxy with --server <name>.');
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (flags.selftest || flags.test) {
|
|
65
|
+
const result = runSelfTest();
|
|
66
|
+
if (json) out(JSON.stringify(result, null, 2));
|
|
67
|
+
else out(renderSelfTest(result));
|
|
68
|
+
return result.passed === result.total ? 0 : 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (flags['list-servers'] || flags.list) {
|
|
72
|
+
const rows = listServers(root);
|
|
73
|
+
if (json) {
|
|
74
|
+
out(JSON.stringify(rows, null, 2));
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
if (!rows.length) {
|
|
78
|
+
out('No MCP servers configured (.mcp.json / .cursor/mcp.json / .vscode/mcp.json).');
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
out('Configured MCP servers:');
|
|
82
|
+
for (const row of rows) out(` ${row.name.padEnd(24)} ${row.file}\n ${row.command}`);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (flags.status) {
|
|
87
|
+
const report = analyzeMonitorLog(path.resolve(root, flags.audit || '.vibeguard/audit/mcp-firewall.jsonl'));
|
|
88
|
+
if (json) out(JSON.stringify(report, null, 2));
|
|
89
|
+
else out(renderMonitor(report));
|
|
90
|
+
return report.exists ? 0 : 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (flags.check) {
|
|
94
|
+
let call;
|
|
95
|
+
try {
|
|
96
|
+
call = typeof flags.check === 'string' ? JSON.parse(flags.check) : null;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
process.stderr.write(`error: --check must be JSON: ${err.message}\n`);
|
|
99
|
+
return 2;
|
|
100
|
+
}
|
|
101
|
+
const server = call.server || flags.server || 'cli';
|
|
102
|
+
const tool = call.tool || call.name || flags.tool;
|
|
103
|
+
const callArgs = call.args || call.arguments || {};
|
|
104
|
+
if (!tool) {
|
|
105
|
+
process.stderr.write('error: --check needs a "tool" field\n');
|
|
106
|
+
return 2;
|
|
107
|
+
}
|
|
108
|
+
const loaded = loadPolicy(root, flags.policy);
|
|
109
|
+
const verdict = evaluateToolCall({ root, policy: loaded.policy, server, tool, args: callArgs });
|
|
110
|
+
if (json) out(JSON.stringify({ ...verdict, policySource: loaded.source, policyError: loaded.error }, null, 2));
|
|
111
|
+
else {
|
|
112
|
+
out(`VibeGuard MCP firewall: ${verdict.action.toUpperCase()} — ${tool} (${verdict.capability})`);
|
|
113
|
+
for (const v of verdict.violations) out(` [${v.level}] ${v.id}: ${v.message}`);
|
|
114
|
+
if (loaded.source) out(` policy: ${loaded.source}`);
|
|
115
|
+
}
|
|
116
|
+
return verdict.blocked ? 2 : verdict.action === 'warn' ? 1 : 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (flags.policy && !flags.server && !flags.exec && !flags.command) {
|
|
120
|
+
// Policy inspection only.
|
|
121
|
+
const loaded = loadPolicy(root, flags.policy);
|
|
122
|
+
const summary = describePolicy(loaded.policy, loaded.source);
|
|
123
|
+
if (json) out(JSON.stringify({ ...summary, error: loaded.error }, null, 2));
|
|
124
|
+
else out(JSON.stringify(summary, null, 2));
|
|
125
|
+
return loaded.error ? 1 : 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const serverName = flags.server || args._[1];
|
|
129
|
+
const exec = flags.exec || flags.command;
|
|
130
|
+
if (!serverName && !exec) {
|
|
131
|
+
process.stderr.write(
|
|
132
|
+
'Usage:\n' +
|
|
133
|
+
' vibeguard mcp-firewall --server <name> [--dir .] [--policy file]\n' +
|
|
134
|
+
' vibeguard mcp-firewall --exec "<command>" [--strict] [--signed-audit] [--kill-on-block]\n' +
|
|
135
|
+
' vibeguard mcp-firewall --exec "<command>" --token <VGAT> --token-pub key.pem --token-key-id k\n' +
|
|
136
|
+
' vibeguard mcp-firewall --exec "<command>" --approval-token <VGAPPROVAL> --approval-pub key.pem --approval-key-id a\n' +
|
|
137
|
+
' vibeguard mcp-firewall --exec "<command>" --token <VGAT> --token-pub key.pem\n' +
|
|
138
|
+
' vibeguard mcp-firewall --selftest [--json]\n' +
|
|
139
|
+
' vibeguard mcp-firewall --check \'{"tool":"read_file","args":{"path":".env"}}\'\n' +
|
|
140
|
+
' vibeguard mcp-firewall --status\n' +
|
|
141
|
+
' vibeguard mcp-firewall --list-servers\n'
|
|
142
|
+
);
|
|
143
|
+
return 2;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let serverDef;
|
|
147
|
+
try {
|
|
148
|
+
serverDef = resolveServer(root, { serverName, command: exec });
|
|
149
|
+
} catch (err) {
|
|
150
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
151
|
+
return 2;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
process.stderr.write(
|
|
155
|
+
`VibeGuard MCP firewall — proxying "${serverDef.name}"\n` +
|
|
156
|
+
` command: ${serverDef.command} ${serverDef.args.join(' ')}\n` +
|
|
157
|
+
` audit: ${path.resolve(root, flags.audit || ((flags.strict || flags['signed-audit']) ? '.vibeguard/audit/mcp-firewall.signed.jsonl' : '.vibeguard/audit/mcp-firewall.jsonl'))}\n`
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const proxy = startProxy({
|
|
161
|
+
root,
|
|
162
|
+
serverName: serverName || undefined,
|
|
163
|
+
command: exec || undefined,
|
|
164
|
+
policyPath: flags.policy,
|
|
165
|
+
auditFile: flags.audit || undefined,
|
|
166
|
+
strict: flags.strict === true,
|
|
167
|
+
signedAudit: flags['signed-audit'] === true,
|
|
168
|
+
signedAuditFile: flags.audit || undefined,
|
|
169
|
+
killOnBlock: flags['kill-on-block'] === true,
|
|
170
|
+
token: flags.token,
|
|
171
|
+
tokenPublicKey: flags['token-pub'],
|
|
172
|
+
tokenIssuer: flags['token-issuer'],
|
|
173
|
+
tokenTenant: flags['token-tenant'],
|
|
174
|
+
tokenKeyId: flags['token-key-id'],
|
|
175
|
+
approvalToken: flags['approval-token'],
|
|
176
|
+
approvalPublicKey: flags['approval-pub'],
|
|
177
|
+
approvalIssuer: flags['approval-issuer'],
|
|
178
|
+
approvalTenant: flags['approval-tenant'],
|
|
179
|
+
approvalKeyId: flags['approval-key-id'],
|
|
180
|
+
maxBlocks: flags['max-blocks'] ? Number(flags['max-blocks']) : 0,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
proxy.child.once('spawn', () => {
|
|
184
|
+
process.stderr.write(` firewall active (policy: ${proxy.engine.policySource || 'built-in defaults'})\n`);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Keep the process alive; the proxy owns stdout/stdin from here.
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = { cmdMcpFirewall, listServers };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// cmdPentest — `vibeguard pentest <url>`: active web/API security probe suite.
|
|
4
|
+
//
|
|
5
|
+
// vibeguard pentest https://staging.example.com
|
|
6
|
+
// vibeguard pentest http://localhost:3000 --verify-ssrf
|
|
7
|
+
// vibeguard pentest https://api.example.com --token <jwt> --ci --json
|
|
8
|
+
//
|
|
9
|
+
// 100% local, zero dependencies. Every finding ships with severity, CWE,
|
|
10
|
+
// evidence and a curl reproduction command. Exit: 0 clean / 1 findings / 2 usage.
|
|
11
|
+
// Test only systems you own or are authorized to test.
|
|
12
|
+
|
|
13
|
+
const C = {
|
|
14
|
+
bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m',
|
|
15
|
+
yellow: '\x1b[33m', cyan: '\x1b[36m', reset: '\x1b[0m',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const USAGE = `usage: vibeguard pentest <url> [options]
|
|
19
|
+
|
|
20
|
+
Active web/API security probe suite (zero dependencies, 100% local).
|
|
21
|
+
Test only systems you own or are authorized to test.
|
|
22
|
+
|
|
23
|
+
options:
|
|
24
|
+
--verify-ssrf out-of-band SSRF proof: local callback listener + URL-param
|
|
25
|
+
fuzzing; a callback from the target IS proof-of-exploit
|
|
26
|
+
--token <jwt> test whether the server accepts alg:none tokens
|
|
27
|
+
--token-header <h> header the token goes in (default Authorization)
|
|
28
|
+
--timeout <ms> per-request timeout (default 10000)
|
|
29
|
+
--ci gate mode: exit 1 on any finding (default behavior anyway)
|
|
30
|
+
--json machine-readable output
|
|
31
|
+
--allow-private allow private/loopback targets (default: allowed for
|
|
32
|
+
loopback, blocked for other private ranges)
|
|
33
|
+
--help this help
|
|
34
|
+
|
|
35
|
+
examples:
|
|
36
|
+
vibeguard pentest http://localhost:3000 --verify-ssrf
|
|
37
|
+
vibeguard pentest https://api.example.com --token eyJhbGciOiJIUzI1NiIs...
|
|
38
|
+
vibeguard pentest https://staging.example.com --json
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
const SEV_ORDER = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
|
|
42
|
+
|
|
43
|
+
async function cmdPentest(args, flags) {
|
|
44
|
+
const f = flags || {};
|
|
45
|
+
if (f.help || f.h || args._[1] === 'help') {
|
|
46
|
+
process.stderr.write(USAGE);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
const target = args._[1];
|
|
50
|
+
if (!target) {
|
|
51
|
+
process.stderr.write(USAGE);
|
|
52
|
+
process.stderr.write('pentest: missing target URL\n');
|
|
53
|
+
return 2;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const opts = {
|
|
57
|
+
timeout: f.timeout !== undefined && f.timeout !== true ? Number(f.timeout) : undefined,
|
|
58
|
+
verifySsrf: f['verify-ssrf'] === true || f.verifySsrf === true,
|
|
59
|
+
token: f.token !== undefined && f.token !== true ? String(f.token) : undefined,
|
|
60
|
+
tokenHeader: f['token-header'] !== undefined && f['token-header'] !== true ? String(f['token-header']) : undefined,
|
|
61
|
+
};
|
|
62
|
+
if (opts.timeout !== undefined && (!Number.isInteger(opts.timeout) || opts.timeout < 500)) {
|
|
63
|
+
process.stderr.write('pentest: invalid --timeout (min 500ms)\n');
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let result;
|
|
68
|
+
try {
|
|
69
|
+
const { runPentest } = require('../src/pentest');
|
|
70
|
+
result = await runPentest(target, opts);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
process.stderr.write(`pentest: internal error: ${err.message}\n`);
|
|
73
|
+
return 2;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (f.json) {
|
|
77
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
78
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const findings = result.findings.slice().sort((a, b) => SEV_ORDER[a.severity] - SEV_ORDER[b.severity]);
|
|
82
|
+
const sevColor = (s) => (s === 'critical' || s === 'high' ? C.red : s === 'medium' ? C.yellow : C.dim);
|
|
83
|
+
|
|
84
|
+
process.stdout.write(`\n${C.bold}VibeGuard active pentest${C.reset}\n`);
|
|
85
|
+
process.stdout.write(`${C.dim}${target} · ${findings.length} finding(s) · ${result.stats.requests} requests · ${result.stats.durationMs} ms${C.reset}\n\n`);
|
|
86
|
+
|
|
87
|
+
for (const fnd of findings) {
|
|
88
|
+
process.stdout.write(
|
|
89
|
+
`${sevColor(fnd.severity)}${fnd.severity.toUpperCase().padEnd(9)}${C.reset}${C.bold}[${fnd.id}]${C.reset} ${C.bold}${fnd.title}${C.reset} (${fnd.cwe})\n`
|
|
90
|
+
);
|
|
91
|
+
if (fnd.detail) process.stdout.write(` ${fnd.detail}\n`);
|
|
92
|
+
if (fnd.evidence) process.stdout.write(` ${C.dim}evidence: ${fnd.evidence}${C.reset}\n`);
|
|
93
|
+
if (fnd.reproduction) process.stdout.write(` ${C.cyan}repro: ${fnd.reproduction}${C.reset}\n`);
|
|
94
|
+
process.stdout.write('\n');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (findings.length === 0) {
|
|
98
|
+
process.stdout.write(`${C.green}✓ No issues detected.${C.reset} (negative result — not a guarantee of safety)\n`);
|
|
99
|
+
}
|
|
100
|
+
return findings.length > 0 ? 1 : 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = { cmdPentest };
|