@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.
Files changed (167) hide show
  1. package/.vibeguard-mcp.example.json +51 -0
  2. package/CHANGELOG.md +604 -216
  3. package/MCP-FIREWALL.md +296 -0
  4. package/README.md +355 -31
  5. package/bin/cli.js +355 -27
  6. package/bin/cmd-agent-monitor.js +45 -0
  7. package/bin/cmd-agent-risk.js +64 -0
  8. package/bin/cmd-gif.js +62 -0
  9. package/bin/cmd-git-scan.js +74 -0
  10. package/bin/cmd-llm-proxy.js +164 -0
  11. package/bin/cmd-mcp-firewall.js +191 -0
  12. package/bin/cmd-pentest.js +103 -0
  13. package/bin/cmd-platform.js +137 -0
  14. package/bin/cmd-pr-scan.js +135 -0
  15. package/bin/cmd-sbom-diff.js +38 -0
  16. package/bin/cmd-skill-scan.js +35 -0
  17. package/docs/AISVS.md +25 -0
  18. package/docs/ARCHITECTURE.md +81 -0
  19. package/docs/INSTALLATION.md +139 -0
  20. package/docs/WINDOWS.md +74 -0
  21. package/docs/security-policy.strict.example.json +134 -0
  22. package/docs/security-policy.strict.example.pub.pem +3 -0
  23. package/package.json +45 -7
  24. package/src/.vibeguard/cache/file-hashes.json +60 -0
  25. package/src/.vibeguard/latest-snapshot.json +36 -0
  26. package/src/.vibeguard/mcp-pins.json +1 -0
  27. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
  28. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
  29. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
  30. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
  31. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
  32. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
  33. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
  34. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
  35. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
  36. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
  37. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
  38. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
  43. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
  44. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
  45. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
  46. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
  47. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
  48. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
  49. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
  50. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
  51. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
  52. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
  53. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
  54. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
  55. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
  56. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
  57. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
  58. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
  59. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
  60. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
  61. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
  62. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
  63. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
  68. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
  69. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
  70. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
  71. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
  72. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
  73. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
  74. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
  75. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
  76. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
  77. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
  78. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
  79. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
  84. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
  85. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
  86. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
  87. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
  88. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
  89. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
  90. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
  91. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
  92. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
  93. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
  94. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
  95. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
  96. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
  97. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
  98. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
  99. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
  100. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
  101. package/src/.vibeguard-baseline.json +5226 -0
  102. package/src/action-guard.js +84 -6
  103. package/src/agent-monitor.js +262 -0
  104. package/src/agent-policy.js +642 -0
  105. package/src/agent-risk.js +271 -0
  106. package/src/agentic.js +1513 -0
  107. package/src/ast.js +165 -7
  108. package/src/audit-trail.js +212 -67
  109. package/src/auto.js +427 -427
  110. package/src/autofix.js +11 -4
  111. package/src/bundles.js +198 -0
  112. package/src/daemon.js +343 -343
  113. package/src/dashboard.js +278 -278
  114. package/src/engine.js +3 -0
  115. package/src/entropy.js +187 -0
  116. package/src/firewall.js +19 -3
  117. package/src/gif.js +134 -0
  118. package/src/gitscan.js +282 -0
  119. package/src/hook.js +151 -151
  120. package/src/injection-decode.js +136 -0
  121. package/src/install.js +298 -280
  122. package/src/integrity.js +16 -1
  123. package/src/integrity.json +43 -13
  124. package/src/interceptor.js +12 -9
  125. package/src/llm-proxy.js +986 -0
  126. package/src/mcp-audit.js +61 -5
  127. package/src/mcp-firewall.js +971 -0
  128. package/src/mcp-server.js +2500 -2047
  129. package/src/obfuscation.js +315 -0
  130. package/src/owasp-agentic.js +314 -0
  131. package/src/pentest.js +589 -0
  132. package/src/pii.js +4 -0
  133. package/src/platform/aisvs.js +38 -0
  134. package/src/platform/approval.js +187 -0
  135. package/src/platform/canonical.js +73 -0
  136. package/src/platform/contracts.js +158 -0
  137. package/src/platform/delegation.js +73 -0
  138. package/src/platform/http-gateway.js +177 -0
  139. package/src/platform/identity.js +253 -0
  140. package/src/platform/jwt.js +86 -0
  141. package/src/platform/mcp-http-bridge.js +199 -0
  142. package/src/platform/memory-guard.js +64 -0
  143. package/src/platform/os-sandbox.js +144 -0
  144. package/src/platform/policy.js +332 -0
  145. package/src/platform/sandbox-manager.js +92 -0
  146. package/src/platform/signed-audit.js +357 -0
  147. package/src/platform/ssrf.js +129 -0
  148. package/src/plugin.js +182 -168
  149. package/src/pre-deploy.js +170 -55
  150. package/src/privacy-audit.js +272 -272
  151. package/src/repl.js +150 -150
  152. package/src/report.js +7 -1
  153. package/src/routes.js +1210 -0
  154. package/src/rules-2026.js +1407 -0
  155. package/src/rules-pack.js +3068 -3019
  156. package/src/rules.js +376 -60
  157. package/src/sandbox.js +200 -10
  158. package/src/sbom.js +193 -164
  159. package/src/scanner.js +189 -33
  160. package/src/shell-guard.js +11 -0
  161. package/src/skill-scan.js +477 -0
  162. package/src/slopsquat.js +144 -144
  163. package/src/surface.js +408 -0
  164. package/src/taint-ast.js +204 -37
  165. package/src/taint.js +15 -3
  166. package/src/tokenlean.js +579 -0
  167. package/src/trace.js +220 -220
@@ -0,0 +1,137 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * bin/cmd-platform.js — CLI for the additive v2 security primitives:
5
+ * vibeguard policy validate <file> [--pub <pem>]
6
+ * vibeguard policy sign <file> --key <pem> [--out <file>]
7
+ * vibeguard audit verify <log> [--pub <pem>]
8
+ * vibeguard sandbox backends [--json]
9
+ *
10
+ * Legacy commands remain in bin/cli.js. Nothing here silently weakens them.
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const { verifyPolicy, loadPolicyFile, signPolicy } = require('../src/platform/policy');
16
+ const { SignedAuditLog } = require('../src/platform/signed-audit');
17
+ const { publicKeyToJwk, loadPublicKey } = require('../src/platform/identity');
18
+
19
+ function out(text) { process.stdout.write(text + '\n'); }
20
+
21
+ function cmdPolicy(args, flags) {
22
+ const action = args._[1];
23
+ const fileArg = args._[2] || flags.file;
24
+ if (!action || !fileArg) {
25
+ process.stderr.write('Usage: vibeguard policy <validate|sign> <file> [--pub key.pem] [--key private.pem] [--out file]\n');
26
+ return 2;
27
+ }
28
+ const file = path.resolve(fileArg);
29
+ let policy;
30
+ try { policy = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (err) {
31
+ process.stderr.write(`error: cannot read policy: ${err.message}\n`);
32
+ return 2;
33
+ }
34
+
35
+ if (action === 'validate') {
36
+ if (policy.schemaVersion !== '2.0') {
37
+ process.stderr.write('INVALID: policy schemaVersion must be 2.0 (legacy .vibeguard-mcp.json is not a v2 policy)\n');
38
+ return 1;
39
+ }
40
+ let verification = null;
41
+ if (flags.pub) {
42
+ verification = verifyPolicy(policy, { publicKey: loadPublicKey(fs.readFileSync(path.resolve(flags.pub))) });
43
+ }
44
+ if (policy.mode === 'strict' && !verification) {
45
+ process.stderr.write('error: strict policy requires --pub for signature verification\n');
46
+ return 1;
47
+ }
48
+ if (verification && !verification.valid) {
49
+ process.stderr.write(`INVALID: ${verification.reason}\n`);
50
+ return 1;
51
+ }
52
+ try {
53
+ if (policy.mode === 'strict') loadPolicyFile(file, { publicKey: flags.pub ? loadPublicKey(fs.readFileSync(path.resolve(flags.pub))) : undefined });
54
+ out(`valid policy: ${policy.policyId || '(no id)'} @ ${policy.policyVersion || '?'} mode=${policy.mode} signature=${verification ? 'verified' : policy.signature ? 'present-unverified' : 'none'}`);
55
+ return 0;
56
+ } catch (err) {
57
+ process.stderr.write(`INVALID: ${err.message}\n`);
58
+ return 1;
59
+ }
60
+ }
61
+
62
+ if (action === 'sign') {
63
+ if (!flags.key) {
64
+ process.stderr.write('error: policy sign requires --key <private-key.pem>\n');
65
+ return 2;
66
+ }
67
+ const privateKey = fs.readFileSync(path.resolve(flags.key));
68
+ const signed = signPolicy(policy, { privateKey, keyId: flags['key-id'] || 'policy-key' });
69
+ const outFile = fs.existsSync(file) && flags.out ? path.resolve(flags.out) : (flags.out ? path.resolve(flags.out) : file.replace(/\.json$/i, '') + '.signed.json');
70
+ fs.writeFileSync(outFile, JSON.stringify(signed, null, 2) + '\n', { mode: 0o600 });
71
+ out(`signed policy written to ${outFile}`);
72
+ return 0;
73
+ }
74
+ process.stderr.write(`unknown policy action: ${action}\n`);
75
+ return 2;
76
+ }
77
+
78
+ function cmdAuditVerify(args, flags) {
79
+ const log = args._[1] || flags.file;
80
+ if (!log) { process.stderr.write('Usage: vibeguard audit verify <log.jsonl> --pub <key.pem> [--json]\n'); return 2; }
81
+ const publicKey = flags.pub ? loadPublicKey(fs.readFileSync(path.resolve(flags.pub))) : undefined;
82
+ const result = SignedAuditLog.verifyFile(path.resolve(log), { publicKey });
83
+ if (flags.json) out(JSON.stringify({ ...result, signatureChecked: !!publicKey }, null, 2));
84
+ else {
85
+ out(`signed audit: ${publicKey ? (result.valid ? 'VALID' : 'INVALID') : 'UNVERIFIED'} — ${result.entries} entries`);
86
+ if (!publicKey) out(' No --pub supplied: the hash chain was checked, but Ed25519 signatures were NOT verified.');
87
+ for (const reason of result.reasons || []) out(` ${reason}`);
88
+ }
89
+ return publicKey && result.valid ? 0 : 1;
90
+ }
91
+
92
+ async function cmdSandbox(args, flags) {
93
+ const action = args._[1] || 'backends';
94
+ if (action === 'verify') {
95
+ const { getLinuxBackend } = require('../src/platform/os-sandbox');
96
+ const backend = getLinuxBackend();
97
+ if (!backend.available()) { process.stderr.write('Linux OS namespace backend unavailable on this host\n'); return 2; }
98
+ const ok = await backend.verify();
99
+ out(JSON.stringify({ backend: backend.id, verified: ok, verification: backend.verification, limitations: backend.limitations }, null, 2));
100
+ return ok ? 0 : 1;
101
+ }
102
+ if (action === 'backends') {
103
+ const { defaultManager } = require('../src/platform/sandbox-manager');
104
+ const data = defaultManager().list();
105
+ if (flags.json) out(JSON.stringify(data, null, 2));
106
+ else {
107
+ out('Sandbox backends:');
108
+ for (const b of data) out(` ${b.id.padEnd(12)} class=${b.isolationClass.padEnd(9)} verified=${b.verified ? 'yes' : 'NO'} ${b.limitations.join('; ')}`);
109
+ out('No OS-level backend is verified in this build. Do not claim isolation.');
110
+ }
111
+ return 0;
112
+ }
113
+ process.stderr.write('Usage: vibeguard sandbox <backends|verify> [--json]\n');
114
+ return 2;
115
+ }
116
+
117
+ function cmdAisvs(flags) {
118
+ const { getAisvsReport } = require('../src/platform/aisvs');
119
+ const r = getAisvsReport();
120
+ if (flags.json) { out(JSON.stringify(r, null, 2)); return 0; }
121
+ out(`${r.framework}`);
122
+ out(`controls: ${r.controls.length} — ${JSON.stringify(r.counts)}`);
123
+ for (const c of r.controls) out(` ${c.id.padEnd(16)} ${c.status.padEnd(16)} ${c.title}`);
124
+ return 0;
125
+ }
126
+
127
+ async function cmdPlatform(args, flags) {
128
+ const cmd = args._[0];
129
+ if (cmd === 'policy') return cmdPolicy(args, flags);
130
+ if (cmd === 'audit') return cmdAuditVerify(args, flags);
131
+ if (cmd === 'aisvs') return cmdAisvs(flags);
132
+ if (cmd === 'sandbox' && (args._[1] === 'backends' || args._[1] === 'verify')) return cmdSandbox(args, flags);
133
+ process.stderr.write('Usage: vibeguard <policy|audit|sandbox>\n');
134
+ return 2;
135
+ }
136
+
137
+ module.exports = { cmdPolicy, cmdAuditVerify, cmdSandbox, cmdAisvs, cmdPlatform, publicKeyToJwk };
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+
3
+ // cmdPrScan — `vibeguard pr-scan`: review ONLY the changed lines (PR gate).
4
+ //
5
+ // Strix-compatible semantics: exit 0 = clean, 2 = vulnerabilities found
6
+ // (CI gate fails), 1 = fatal error. Diff-scoped: findings outside the changed
7
+ // lines are suppressed, so CI stays fast and pre-existing debt doesn't block
8
+ // merges — new findings do.
9
+ //
10
+ // vibeguard pr-scan # working tree vs HEAD (uncommitted)
11
+ // vibeguard pr-scan --staged # staged changes only
12
+ // vibeguard pr-scan --base origin/main # commits in HEAD..origin/main...
13
+ // # (branch PR range, Strix --diff-base)
14
+ // vibeguard pr-scan --json
15
+ //
16
+ // Taint-correct: the FULL file is analyzed (so dataflow rules stay accurate),
17
+ // but only findings whose line is an ADDED line are reported.
18
+
19
+ const { execFileSync } = require('child_process');
20
+
21
+ const C = {
22
+ bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m',
23
+ yellow: '\x1b[33m', cyan: '\x1b[36m', reset: '\x1b[0m',
24
+ };
25
+
26
+ function git(dir, args) {
27
+ return execFileSync('git', args, { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
28
+ }
29
+
30
+ /**
31
+ * Compute the set of added lines per file for the requested diff scope.
32
+ * @returns {{added: Map<string, Set<number>>, files: string[]}}
33
+ */
34
+ function addedLines(dir, scope) {
35
+ const args = ['diff'];
36
+ if (scope.staged) args.push('--staged');
37
+ else if (scope.base) args.push(scope.base + '...HEAD');
38
+ else args.push('HEAD');
39
+ args.push('--unified=0');
40
+ const out = git(dir, args);
41
+ const added = new Map();
42
+ let curFile = null;
43
+ let curLine = 0;
44
+ for (const raw of out.split('\n')) {
45
+ const line = raw;
46
+ if (line.startsWith('+++ b/')) {
47
+ curFile = line.slice(6);
48
+ if (!added.has(curFile)) added.set(curFile, new Set());
49
+ continue;
50
+ }
51
+ if (line.startsWith('@@')) {
52
+ // @@ -oldStart,oldLen +newStart,newLen @@
53
+ const m = /\+(\d+)(?:,(\d+))?/.exec(line);
54
+ curLine = m ? Number(m[1]) : 0;
55
+ continue;
56
+ }
57
+ if (curFile && line.startsWith('+') && !line.startsWith('+++')) {
58
+ added.get(curFile).add(curLine);
59
+ curLine++;
60
+ } else if (curFile && !line.startsWith('-')) {
61
+ curLine++;
62
+ }
63
+ }
64
+ return { added, files: [...added.keys()] };
65
+ }
66
+
67
+ async function runPrScan(dir, opts = {}) {
68
+ const scope = { staged: !!opts.staged, base: opts.base || null };
69
+ const { added, files } = addedLines(dir, scope);
70
+ if (files.length === 0) {
71
+ return { findings: [], files: [], stats: { addedLines: 0, scannedFiles: 0 } };
72
+ }
73
+
74
+ const { scanFileContent } = require('../src/scanner');
75
+ const fs = require('fs');
76
+ const path = require('path');
77
+
78
+ const findings = [];
79
+ let addedTotal = 0;
80
+ for (const rel of files) {
81
+ const lines = added.get(rel);
82
+ addedTotal += lines.size;
83
+ const abs = path.join(dir, rel);
84
+ let content;
85
+ try {
86
+ content = fs.readFileSync(abs, 'utf8');
87
+ } catch {
88
+ continue; // deleted in the diff or unreadable — skip
89
+ }
90
+ const res = scanFileContent(abs, rel, content, null, null);
91
+ const arr = Array.isArray(res) ? res : (res.findings || []);
92
+ for (const f of arr) {
93
+ if (lines.has(f.line)) findings.push(f);
94
+ }
95
+ }
96
+ return { findings, files, stats: { addedLines: addedTotal, scannedFiles: files.length } };
97
+ }
98
+
99
+ async function cmdPrScan(args, flags) {
100
+ const f = flags || {};
101
+ const dir = args._[1] || '.';
102
+ const json = !!f.json;
103
+
104
+ let result;
105
+ try {
106
+ result = await runPrScan(dir, { staged: !!f.staged, base: f.base !== undefined && f.base !== true ? String(f.base) : null });
107
+ } catch (err) {
108
+ process.stderr.write(`pr-scan: fatal: ${err.message} (is ${dir} a git repo?)\n`);
109
+ return 1; // Strix-compatible: 1 = fatal error
110
+ }
111
+
112
+ if (json) {
113
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
114
+ return result.findings.length > 0 ? 2 : 0;
115
+ }
116
+
117
+ process.stdout.write(`\n${C.bold}VibeGuard PR scan${C.reset} — ${dir}\n`);
118
+ process.stdout.write(`${C.dim}${result.stats.scannedFiles} changed file(s), ${result.stats.addedLines} added line(s)${C.reset}\n\n`);
119
+ if (result.findings.length === 0) {
120
+ process.stdout.write(`${C.green}✓ No issues in the diff.${C.reset} Pre-existing findings outside the change are not reported.\n`);
121
+ return 0;
122
+ }
123
+ for (const fnd of result.findings) {
124
+ const sev = String(fnd.severity || 'medium');
125
+ const color = sev === 'critical' || sev === 'high' ? C.red : sev === 'medium' ? C.yellow : C.dim;
126
+ process.stdout.write(
127
+ `${color}${sev.toUpperCase().padEnd(9)}${C.reset}${fnd.file}:${fnd.line} [${fnd.ruleId}] ${fnd.message || fnd.title || ''}\n`
128
+ );
129
+ if (fnd.fix) process.stdout.write(` ${C.dim}fix: ${fnd.fix}${C.reset}\n`);
130
+ }
131
+ process.stdout.write(`\n${C.red}${result.findings.length} finding(s) in the diff — gate FAILS (exit 2).${C.reset}\n`);
132
+ return 2; // Strix-compatible: 2 = vulnerabilities found
133
+ }
134
+
135
+ module.exports = { cmdPrScan, runPrScan };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ // cmdSbomDiff — `vibeguard sbom-diff <base> <head>`: compare two project
4
+ // snapshots (e.g. main vs. PR) and report dependency drift at supply-chain
5
+ // level (CycloneDX). 100% offline; the diff is computed from the SBOMs.
6
+
7
+ const C = {
8
+ bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m',
9
+ yellow: '\x1b[33m', cyan: '\x1b[36m', reset: '\x1b[0m',
10
+ };
11
+
12
+ function cmdSbomDiff(args, flags) {
13
+ const baseDir = args._[1] || '.';
14
+ const headDir = args._[2] || '.';
15
+ const { diffSBOM } = require('../src/sbom');
16
+ let d;
17
+ try {
18
+ d = diffSBOM(baseDir, headDir);
19
+ } catch (e) {
20
+ process.stderr.write(`sbom-diff: ${e.message}\n`);
21
+ return 2;
22
+ }
23
+ if (flags.json || flags.output === 'json') {
24
+ process.stdout.write(JSON.stringify(d, null, 2) + '\n');
25
+ return 0;
26
+ }
27
+ process.stdout.write(`${C.bold}VibeGuard SBOM Diff${C.reset}\n`);
28
+ process.stdout.write(`${C.dim}${'─'.repeat(60)}${C.reset}\n\n`);
29
+ process.stdout.write(` Base: ${d.base}\n`);
30
+ process.stdout.write(` Head: ${d.head}\n\n`);
31
+ process.stdout.write(` ${C.green}+${d.counts.added}${C.reset} added ${C.red}-${d.counts.removed}${C.reset} removed ${C.yellow}~${d.counts.changed}${C.reset} changed\n\n`);
32
+ for (const c of d.added) process.stdout.write(` ${C.green}+${C.reset} ${c.name}@${c.version}\n`);
33
+ for (const c of d.removed) process.stdout.write(` ${C.red}-${C.reset} ${c.name}@${c.version}\n`);
34
+ for (const c of d.changed) process.stdout.write(` ${C.yellow}~${C.reset} ${c.name}: ${c.from} -> ${c.to}\n`);
35
+ return 0;
36
+ }
37
+
38
+ module.exports = { cmdSbomDiff };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * bin/cmd-skill-scan.js — scan agent skills / plugins / instruction files.
5
+ *
6
+ * Exit codes: 0 clean, 1 medium/high, 2 critical.
7
+ */
8
+
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+ const { scanSkills, renderSkillReport, collectSkillFiles } = require('../src/skill-scan');
12
+
13
+ function cmdSkillScan(args, flags) {
14
+ const root = path.resolve(flags.dir || args._[1] || '.');
15
+ const extraPaths = args._.slice(2);
16
+ if (flags.path) extraPaths.push(String(flags.path));
17
+ if (extraPaths.length && !fs.existsSync(root)) {
18
+ process.stderr.write(`error: directory not found: ${root}\n`);
19
+ return 2;
20
+ }
21
+ const result = scanSkills(root, { paths: extraPaths.length ? extraPaths : undefined, all: !!flags.all });
22
+ if (flags.json) {
23
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
24
+ } else if (flags.list) {
25
+ const files = collectSkillFiles(root, { paths: extraPaths.length ? extraPaths : undefined, all: !!flags.all });
26
+ process.stdout.write(files.map((f) => path.relative(root, f)).join('\n') + '\n');
27
+ } else {
28
+ process.stdout.write(renderSkillReport(result) + '\n');
29
+ }
30
+ if (result.counts.critical > 0) return 2;
31
+ if (result.counts.high > 0 || result.counts.medium > 0) return 1;
32
+ return 0;
33
+ }
34
+
35
+ module.exports = { cmdSkillScan };
package/docs/AISVS.md ADDED
@@ -0,0 +1,25 @@
1
+ # AISVS-Style Control Mapping
2
+
3
+ This is an **internal readiness matrix**, not an AISVS 1.01 certification. It
4
+ maps the controls the repository actually implements to an AISVS-style set of
5
+ categories and cites verification evidence IDs.
6
+
7
+ Run:
8
+
9
+ ```bash
10
+ vibeguard aisvs # human summary
11
+ vibeguard aisvs --json # machine-readable mapping
12
+ ```
13
+
14
+ Status meanings:
15
+
16
+ - `implemented` — implemented and tested in the tested path.
17
+ - `partial` — only a mode/primitive; residual limitations exist.
18
+ - `not_verified` — no executable OS/platform evidence.
19
+ - `not_implemented` — no control.
20
+
21
+ Current summary from `src/platform/aisvs.js`: 12 partial, 1 not_verified, 2
22
+ not_implemented. No control is claimed as fully certified.
23
+
24
+ Evidence is in `research/SECURITY_TEST_MATRIX.md`; limitations are in
25
+ `research/KNOWN_LIMITATIONS.md`.
@@ -0,0 +1,81 @@
1
+ # VibeGuard Architecture (v2 security baseline)
2
+
3
+ This document describes what is **implemented** in the repository today, and
4
+ separates it from the target design in `research/08`–`15`. If a control is not
5
+ listed as implemented, do not treat it as available.
6
+
7
+ ## Implemented baseline
8
+
9
+ ```
10
+ Legacy v1.10 scanner + MCP server (preserved)
11
+ │
12
+ ├─ platform/canonical + contracts
13
+ ├─ platform/identity (Ed25519 VGAT capability tokens, replay cache)
14
+ ├─ platform/approval (signed, single-use human approvals, in-memory)
15
+ ├─ platform/signed-audit (Ed25519 event chain + Merkle checkpoints)
16
+ ├─ platform/policy (strict v2 engine, signed policies, default deny)
17
+ ├─ platform/jwt (offline EdDSA JWT/JWKS validation)
18
+ ├─ platform/mcp-http-bridge (authenticated JSON-RPC + SSE ↔ stdio)
19
+ ├─ platform/os-sandbox (Linux unshare network/PID namespace)
20
+ ├─ platform/memory-guard + delegation (library controls)
21
+ ├─ platform/ssrf (private/metadata/loopback destination blocking)
22
+ ├─ platform/http-gateway (authenticated JSON-RPC HTTP slice)
23
+ ├─ platform/sandbox-manager (fail-closed backend registry)
24
+ └─ hardened legacy modules:
25
+ mcp-firewall: all-method response inspection, limits, strict mode
26
+ agent-policy: strict option, realpath, shell egress, deep secrets
27
+ scanner/plugin: no target-controlled plugin execution by default
28
+ sandbox: process harness without host-realm objects
29
+ shell-guard: Windows destructive command coverage
30
+ ```
31
+
32
+ ### Enforcement path
33
+
34
+ ```
35
+ agent/client ──► mcp-firewall (stdio) ──► MCP server
36
+ │
37
+ ├─ policy (strict legacy engine or v2 library)
38
+ ├─ all-method content scan (tools/resources/prompts/unknown)
39
+ ├─ secret/PII/entropy/DLP
40
+ └─ legacy hash-chained audit log
41
+
42
+ vibeguard policy sign/validate ──► Ed25519 signed policy v2
43
+ vibeguard audit verify ──► signed event chain + checkpoints
44
+ vibeguard sandbox backends ──► explicitly unverified/verified status
45
+ ```
46
+
47
+ ## What is not implemented / not verified
48
+
49
+ - **Windows AppContainer/Job Objects/WFP and macOS VM backends** are not
50
+ implemented. Linux has an `unshare` network/PID namespace backend verified by
51
+ a live probe; its filesystem is still host-readable. Do not claim
52
+ cross-platform OS isolation.
53
+ - The HTTP bridge supports authenticated JSON-RPC POST and SSE notifications
54
+ over a spawned stdio upstream, but not TLS/mTLS, remote OAuth server flow or
55
+ multi-session persistence.
56
+ - Strict mode writes signed gateway audit events; non-strict mode still uses the
57
+ legacy hash chain. External checkpoint/anchor remains absent.
58
+ - Persistent identity/approval stores and an authenticated approval UI; the broker is in-memory.
59
+ - Independent runtime monitors and quarantine service; an optional kill-on-block switch exists.
60
+ - REST API/SDK/dashboard/IDE integrations beyond the primitive HTTP gateway.
61
+ - AISVS 1.01 mapping, evidence-backed OWASP statuses, complete supply-chain
62
+ registry, and production release signing.
63
+
64
+ See `reports/known-limitations.md` for the authoritative list.
65
+
66
+ ## Trust boundaries
67
+
68
+ | Boundary | Control in this build |
69
+ |---|---|
70
+ | Client → gateway | VGAT Ed25519 token (stdio legacy path has no identity yet), audience/expiry/replay validation in the HTTP slice |
71
+ | Tool arguments/results | Policy v2, secret/PII/entropy checks, all-method response scan |
72
+ | Target repo → scanner | Plugins disabled unless explicit `--trust-plugins`; sandbox not used for plugins |
73
+ | Untrusted code → host | Fresh V8 context + Node permission model; **unverified**, same-user |
74
+ | Audit writer → attacker | Hash chain; signed events when using `SignedAuditLog`; no OS append-only anchor |
75
+ | Policy → agent | Signed strict policy v2; legacy project policy is monitor-only |
76
+
77
+ ## Compatibility
78
+
79
+ Legacy CLI commands and the 93 MCP tools remain. New strict behavior is opt-in
80
+ for existing commands; new platform commands are additive. Partial unsafe
81
+ behavior is explicitly labeled in output (`verified=NO`).
@@ -0,0 +1,139 @@
1
+ # Installation and Deployment
2
+
3
+ ## Requirements
4
+
5
+ - Node.js **20 or 22** for the v2 platform primitives (Node 18 can scan and use
6
+ the legacy sandbox, but process isolation is unavailable).
7
+ - No account, API key or network connection is required for scanning, policy
8
+ evaluation, signed audit, HTTP loopback gateway or the platform tests.
9
+ - Windows 11, Linux and macOS are supported by the code paths in this repo;
10
+ Windows CI runs `node test/run-platform.js`. macOS CI is configured but has
11
+ not been observed as a verified release gate in this environment.
12
+
13
+ ## From a checkout
14
+
15
+ ```bash
16
+ npm ci
17
+ node test/run.js # legacy + platform suites
18
+ node test/run-platform.js # focused security suite
19
+ node bin/cli.js scan .
20
+ ```
21
+
22
+ Do not use `npm install` in an untrusted project with lifecycle scripts unless
23
+ you have reviewed it; the project itself does not modify shell profiles.
24
+
25
+ ## Strict MCP gateway (stdio)
26
+
27
+ 1. Create and sign a strict policy:
28
+
29
+ ```bash
30
+ node bin/cli.js policy validate docs/security-policy.strict.example.json \
31
+ --pub docs/security-policy.strict.example.pub.pem
32
+ ```
33
+
34
+ 2. Use a signed policy with the legacy strict gateway:
35
+
36
+ ```bash
37
+ node bin/cli.js mcp-firewall --server <name> --strict
38
+ ```
39
+
40
+ This mode uses the legacy policy engine with strict default-deny after an
41
+ explicit allow list. The signed policy-v2 engine is available as a library and
42
+ via `policy validate/sign`; wiring it to a production upstream bridge is not
43
+ complete.
44
+
45
+ 3. Audit:
46
+
47
+ ```bash
48
+ node bin/cli.js audit verify .vibeguard/audit/events.jsonl --pub audit-public.pem
49
+ ```
50
+
51
+ ## HTTP gateway slice
52
+
53
+ `src/platform/http-gateway.js` is a loopback-first, authenticated JSON-RPC POST
54
+ endpoint with an injected message handler. It is **not** a complete Streamable
55
+ HTTP MCP bridge. Example usage is in `test/platform-security-tests.js`.
56
+
57
+ Bind to loopback by default. Do not expose it without TLS, authentication and
58
+ network policy; the current CLI does not start it automatically.
59
+
60
+ ## Sandbox
61
+
62
+ ```bash
63
+ node bin/cli.js sandbox backends
64
+ node bin/cli.js sandbox "const x = 1 + 2; x" --isolation process
65
+ ```
66
+
67
+ The process backend is explicitly unverified: fresh V8 context + Node
68
+ permission model, same OS user, network not blocked by the kernel. On Linux
69
+ (including WSL), `vibeguard sandbox verify` creates a `unshare` user/network/PID
70
+ namespace and verifies network isolation. Filesystem isolation is not provided.
71
+ Windows AppContainer/Job/WFP and macOS VM backends are not implemented.
72
+
73
+ ## Offline operation
74
+
75
+ Scanning, policy, identity, approval, signed audit, SSRF checks, JWT/JWKS and
76
+ the platform tests are offline. Existing `cve`, `url`, `pentest`, `proxy`,
77
+ `llm-proxy` and GIF commands are network features and must be explicitly
78
+ invoked; see `reports/known-limitations.md`.
79
+
80
+ ## Useful commands
81
+
82
+ ```bash
83
+ node bin/cli.js mcp-firewall --selftest
84
+ node bin/cli.js mcp-audit
85
+ node bin/cli.js skill-scan .
86
+ node bin/cli.js agent-risk
87
+ node bin/cli.js owasp-coverage
88
+ node bin/cli.js policy sign policy.json --key policy-private.pem
89
+ node bin/cli.js audit verify audit.jsonl --pub audit-public.pem
90
+ npm run security-bench
91
+ ```
92
+
93
+ ## Signed gateway audit
94
+
95
+ Strict mode writes Ed25519-signed events to `.vibeguard/audit/mcp-firewall.signed.jsonl` and a checkpoint sidecar; the key is generated at `.vibeguard/audit/ed25519.pem` (permissions 0600). Verify with:
96
+
97
+ ```bash
98
+ vibeguard audit verify .vibeguard/audit/mcp-firewall.signed.jsonl \
99
+ --pub .vibeguard/audit/ed25519.pub.pem
100
+ ```
101
+
102
+ Non-strict mode keeps the legacy hash-chained log.
103
+
104
+ ## Stdio identity/approval
105
+
106
+ ```bash
107
+ vibeguard mcp-firewall --exec "<server>" --dir . \
108
+ --token <VGAT> --token-pub token.pub.pem --token-issuer human:acme/security \
109
+ --token-tenant acme --token-key-id k1
110
+ ```
111
+
112
+ A signed single-use approval can be supplied with `--approval-token`, `--approval-pub`, `--approval-issuer`, `--approval-tenant`, `--approval-key-id`. There is no authenticated approval UI yet.
113
+
114
+ ## HTTP/SSE bridge
115
+
116
+ Use `src/platform/mcp-http-bridge.js` with a policy and authority; it supports authenticated JSON-RPC POST and an SSE `GET /mcp` notification stream. It is loopback-tested, not a TLS/OAuth remote deployment.
117
+
118
+ ## Kill switch
119
+
120
+ ```bash
121
+ vibeguard mcp-firewall --exec "<server>" --strict --kill-on-block
122
+ ```
123
+
124
+ Exit code 3 means the proxy quarantined/killed the upstream after a blocked call.
125
+
126
+ ## Linux OS namespace verification
127
+
128
+ ```bash
129
+ vibeguard sandbox verify # only meaningful on Linux with unshare/user namespaces
130
+ ```
131
+
132
+ Windows/macOS OS backends are not implemented.
133
+
134
+ ## Detection corpus
135
+
136
+ ```bash
137
+ node test/corpus/run.js --gate
138
+ vibeguard aisvs --json
139
+ ```
@@ -0,0 +1,74 @@
1
+ # Windows Setup and Testing
2
+
3
+ ## Verified environment
4
+
5
+ - Windows 11
6
+ - Node.js 24.14.0 for this audit/implementation run
7
+ - PowerShell 7
8
+ - Git for Windows
9
+
10
+ The platform security suite is run on Windows in CI (`.github/workflows/ci.yml`,
11
+ `platform-security` matrix) and locally with:
12
+
13
+ ```powershell
14
+ npm ci
15
+ node test/run-platform.js
16
+ node bin/cli.js sandbox backends
17
+ ```
18
+
19
+ ## What works on Windows
20
+
21
+ - `vibeguard scan`, `mcp`, `mcp-firewall`, `mcp-audit`, `skill-scan`,
22
+ `agent-risk`, `owasp-coverage`, `agent-monitor`
23
+ - policy validation/signing, signed audit verification
24
+ - process sandbox with a fresh V8 context and Node permission model
25
+ - Windows destructive-command blocking in `shell-guard` (`Remove-Item`,
26
+ `del /f /s /q`, `format X:`, `diskpart`, `vssadmin`, `bcdedit`,
27
+ `powershell -enc`, security-setting changes)
28
+ - junction/symlink-aware path policy (uses `fs.realpathSync.native`)
29
+
30
+ ## What is not available or verified
31
+
32
+ - **No Windows AppContainer/Job Object/WFP backend is implemented in this
33
+ build.** `sandbox backends` prints `verified=NO` on Windows. The Linux-only
34
+ `unshare` backend can be verified from WSL (`node bin/cli.js sandbox verify`)
35
+ but that is Linux network/PID isolation, not Windows isolation. Do not claim
36
+ Windows OS isolation.
37
+ - The process backend is same-user and does not block network at the Windows
38
+ kernel/firewall layer. It is a code-execution convenience boundary, not a
39
+ security boundary.
40
+ - macOS-specific isolation is not available; Windows/Linux only for the
41
+ primitives that exist.
42
+ - The HTTP gateway has not been integrated with a Windows service/TLS deployment.
43
+ - Windows CI is configured; results depend on the GitHub runner and are not
44
+ asserted by this local report beyond the Windows run recorded in
45
+ `reports/security-test-results.md`.
46
+
47
+ ## Windows commands
48
+
49
+ ```powershell
50
+ # scan and policy work
51
+ node bin/cli.js scan .
52
+ node bin/cli.js policy validate docs/security-policy.strict.example.json `
53
+ --pub docs/security-policy.strict.example.pub.pem
54
+
55
+ # explicit non-OS sandbox (reports unverified)
56
+ node bin/cli.js sandbox "const x = 1 + 2; x" --isolation process
57
+
58
+ # show truthful isolation status
59
+ node bin/cli.js sandbox backends --json
60
+ ```
61
+
62
+ ## Paths and junctions
63
+
64
+ Policy path checks canonicalize with `fs.realpathSync.native`. A junction inside
65
+ a project that points outside is denied as outside-project; credential paths
66
+ are matched on the canonical target. Legitimate external paths must be added
67
+ explicitly to policy `allowedPaths`/allow resources.
68
+
69
+ ## Shell behavior
70
+
71
+ `shell-guard` now blocks the Windows commands above. It is still a denylist and
72
+ cannot guarantee that every destructive PowerShell/cmd construct is covered.
73
+ For untrusted code, use a real OS/VM backend when one is available; do not rely
74
+ on the denylist.